Skip to content

Commit

Permalink
Added health check.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed May 13, 2017
1 parent 4fdb70a commit d951c43
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 70 deletions.
44 changes: 0 additions & 44 deletions conf/application.conf

This file was deleted.

17 changes: 0 additions & 17 deletions conf/swagger.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.Set;
import java.util.TreeSet;

import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -26,23 +28,26 @@
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.undertow.server.DefaultResponseListener;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.RoutingHandler;
import io.undertow.util.Headers;
import io.undertow.util.Methods;

/**
* @author jbauer
*/
@Singleton
public class ServerModule extends AbstractModule
public class ApplicationModule extends AbstractModule
{
private static Logger log = LoggerFactory.getLogger(ServerModule.class.getCanonicalName());
private static Logger log = LoggerFactory.getLogger(ApplicationModule.class.getCanonicalName());

protected Set<EndpointInfo> registeredEndpoints = new TreeSet<>();
protected Set<Class<?>> registeredControllers = new HashSet<>();
protected Set<Class<? extends Service>> registeredServices = new HashSet<>();

protected Config config;

public ServerModule(Config config)
public ApplicationModule(Config config)
{
this.config = config;
}
Expand All @@ -55,6 +60,25 @@ protected void configure()
this.binder().requestInjection(this);

RoutingHandler router = new RoutingHandler();

if(config.hasPath("health.statusPath"))
{
final String statusPath = config.getString("health.statusPath");

router.add(Methods.GET, statusPath, new HttpHandler()
{

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception
{
exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, MediaType.TEXT_PLAIN);
exchange.getResponseSender().send("OK");
}

});

this.registeredEndpoints.add(EndpointInfo.builder().withConsumes("*/*").withProduces("text/plain").withPathTemplate(statusPath).withControllerName("Internal").withMethod(Methods.GET).build());
}

try
{
Expand All @@ -69,7 +93,7 @@ protected void configure()

this.bind(RoutingHandler.class).toInstance(router);

this.bind(ServerModule.class).toInstance(this);
this.bind(ApplicationModule.class).toInstance(this);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ else if(configFile != null)
this.bindConfig(fileConfig(configFile));
}

install(new ServerModule(this.config));
install(new ApplicationModule(this.config));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EndpointInfo implements Comparable<EndpointInfo>
private String consumes = "*/*";
private String produces = "*/*";
private String controllerMethod = "*";
private String controllerName = "anonymous";
private String controllerName = "_";


private EndpointInfo(Builder builder)
Expand Down Expand Up @@ -166,7 +166,7 @@ public int compareTo(EndpointInfo other) {
@Override
public String toString()
{
return String.format("%-8s %-30s %-26s %-26s %s", this.method, this.pathTemplate, "[" + this.consumes + "]", "[" + this.produces+ "]", "("+this.controllerName+"."+this.controllerMethod+ ")");
return String.format("%-8s %-40s %-26s %-26s %s", this.method, this.pathTemplate, "[" + this.consumes + "]", "[" + this.produces+ "]", "("+this.controllerName+"."+this.controllerMethod+ ")");
}

/**
Expand All @@ -190,8 +190,8 @@ public static final class Builder
private String pathTemplate;
private String consumes = "*/*";
private String produces = "*/*";
private String controllerMethod = "anonymous";
private String controllerName = "anonymous";
private String controllerMethod = "_";
private String controllerName = "_";

private Builder()
{
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ globalHeaders
Server = ${application.name}
}

health {
statusPath = "/internal/status"
}

assets {
# the base path assets will be server from
Expand Down

0 comments on commit d951c43

Please sign in to comment.