diff --git a/conf/application.conf b/conf/application.conf deleted file mode 100644 index bfffa02..0000000 --- a/conf/application.conf +++ /dev/null @@ -1,44 +0,0 @@ - -application { - - env = dev - - version = "1.0" - - name="Wurrly API" - - - path = "/v1" - - # localhost - host = "localhost" - - # HTTP ports - port = 8090 - - - -} - -api.version="v1" - -globalHeaders -{ -# Access-Control-Allow-Origin: "*" -# Access-Control-Allow-Methods: "*" -# Access-Control-Allow-Headers: "*" - Server: ${application.name} -} - - -assets { - path = "/public" - dir = "./assets" - cache { - time = 500 - } -} - - -include "swagger.conf" - \ No newline at end of file diff --git a/conf/swagger.conf b/conf/swagger.conf deleted file mode 100644 index 50c580c..0000000 --- a/conf/swagger.conf +++ /dev/null @@ -1,17 +0,0 @@ - -swagger { - swagger: "2.0" - info { - title = ${application.name} - version = ${application.version} - } - theme="default" - basePath= ${application.path}"/swagger" - specFilename="swagger.json" - consumes: ["application/json"] - produces: ["application/json"] - schemes: ["http"] - logoUrl: "https://www.wurrly.com/images/wurrly-logo.svg" - stylesheet: "wurrly.css" -} - \ No newline at end of file diff --git a/src/main/java/io/sinistral/proteus/modules/ServerModule.java b/src/main/java/io/sinistral/proteus/modules/ApplicationModule.java similarity index 72% rename from src/main/java/io/sinistral/proteus/modules/ServerModule.java rename to src/main/java/io/sinistral/proteus/modules/ApplicationModule.java index 6ed6f70..d3c19e3 100644 --- a/src/main/java/io/sinistral/proteus/modules/ServerModule.java +++ b/src/main/java/io/sinistral/proteus/modules/ApplicationModule.java @@ -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; @@ -26,15 +28,18 @@ 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 registeredEndpoints = new TreeSet<>(); protected Set> registeredControllers = new HashSet<>(); @@ -42,7 +47,7 @@ public class ServerModule extends AbstractModule protected Config config; - public ServerModule(Config config) + public ApplicationModule(Config config) { this.config = config; } @@ -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 { @@ -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 { diff --git a/src/main/java/io/sinistral/proteus/modules/ConfigModule.java b/src/main/java/io/sinistral/proteus/modules/ConfigModule.java index 21eedf6..62580a6 100644 --- a/src/main/java/io/sinistral/proteus/modules/ConfigModule.java +++ b/src/main/java/io/sinistral/proteus/modules/ConfigModule.java @@ -76,7 +76,7 @@ else if(configFile != null) this.bindConfig(fileConfig(configFile)); } - install(new ServerModule(this.config)); + install(new ApplicationModule(this.config)); } diff --git a/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java b/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java index acbe516..55aef6c 100644 --- a/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java +++ b/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java @@ -19,7 +19,7 @@ public class EndpointInfo implements Comparable private String consumes = "*/*"; private String produces = "*/*"; private String controllerMethod = "*"; - private String controllerName = "anonymous"; + private String controllerName = "_"; private EndpointInfo(Builder builder) @@ -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+ ")"); } /** @@ -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() { diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 416fd0d..67809bf 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -36,6 +36,9 @@ globalHeaders Server = ${application.name} } +health { + statusPath = "/internal/status" +} assets { # the base path assets will be server from