From c9a93dd4788346d0d9509914d4705ef8fbe41a5c Mon Sep 17 00:00:00 2001 From: joshua bauer Date: Tue, 25 Apr 2017 08:06:59 -0700 Subject: [PATCH] Migrate to new NS. --- conf/application.conf | 210 ++---------------- conf/logback.xml | 4 +- pom.xml | 2 +- wurrly-undertow.iml => proteus.iml | 0 .../wurrly => io/proteus}/Application.java | 118 ++++------ .../io/proteus/controllers/Benchmarks.java | 100 +++++++++ .../proteus}/controllers/Users.java | 60 ++--- .../wurrly => io/proteus}/models/User.java | 2 +- src/main/java/io/proteus/models/World.java | 40 ++++ .../proteus}/modules/ConfigModule.java | 2 +- .../proteus}/modules/RoutingModule.java | 33 +-- .../proteus}/server/Extractors.java | 38 ++-- .../proteus}/server/MediaType.java | 2 +- .../proteus}/server/MimeTypes.java | 2 +- .../proteus}/server/ServerRequest.java | 11 +- .../proteus}/server/ServerResponse.java | 110 +++++---- .../server/endpoints/EndpointInfo.java | 2 +- .../server/handlers/BaseHttpHandler.java | 57 +++++ .../handlers/GlobalHeaderHttpHandler.java | 71 ++++++ .../server/handlers/HandlerGenerator.java | 113 +++++----- .../ServerDefaultResponseListener.java | 7 +- .../handlers/ServerFallbackHandler.java | 25 +++ .../handlers/benchmark/BenchmarkHandlers.java | 6 +- .../MaxRequestContentLengthPredicate.java | 2 +- .../server/predicates/ServerPredicates.java | 5 +- .../server/swagger/AnnotationHelper.java | 2 +- .../proteus}/server/swagger/Reader.java | 4 +- .../swagger/ServerParameterExtension.java | 2 +- .../proteus}/services/AssetsService.java | 4 +- .../proteus}/services/BaseService.java | 5 +- .../proteus}/services/SwaggerService.java | 14 +- .../proteus}/tests/JsonViewTest.java | 5 +- .../proteus}/tests/TestInvoker.java | 7 +- .../proteus}/tests/TestJsoniterViews.java | 5 +- .../proteus}/tests/TestTypes.java | 4 +- .../proteus}/utilities/ChunkedStream.java | 2 +- .../proteus}/utilities/JsonMapper.java | 2 +- .../proteus}/utilities/ReapableQueue.java | 2 +- .../proteus}/utilities/SecurityOps.java | 2 +- .../com.wurrly.server.swagger.ServerExtension | 1 - ....wurrly.server.swagger.ServerModelResolver | 1 - 41 files changed, 584 insertions(+), 500 deletions(-) rename wurrly-undertow.iml => proteus.iml (100%) rename src/main/java/{com/wurrly => io/proteus}/Application.java (66%) create mode 100644 src/main/java/io/proteus/controllers/Benchmarks.java rename src/main/java/{com/wurrly => io/proteus}/controllers/Users.java (84%) rename src/main/java/{com/wurrly => io/proteus}/models/User.java (97%) create mode 100644 src/main/java/io/proteus/models/World.java rename src/main/java/{com/wurrly => io/proteus}/modules/ConfigModule.java (99%) rename src/main/java/{com/wurrly => io/proteus}/modules/RoutingModule.java (66%) rename src/main/java/{com/wurrly => io/proteus}/server/Extractors.java (95%) rename src/main/java/{com/wurrly => io/proteus}/server/MediaType.java (99%) rename src/main/java/{com/wurrly => io/proteus}/server/MimeTypes.java (95%) rename src/main/java/{com/wurrly => io/proteus}/server/ServerRequest.java (97%) rename src/main/java/{com/wurrly => io/proteus}/server/ServerResponse.java (84%) rename src/main/java/{com/wurrly => io/proteus}/server/endpoints/EndpointInfo.java (99%) create mode 100644 src/main/java/io/proteus/server/handlers/BaseHttpHandler.java create mode 100644 src/main/java/io/proteus/server/handlers/GlobalHeaderHttpHandler.java rename src/main/java/{com/wurrly => io/proteus}/server/handlers/HandlerGenerator.java (90%) rename src/main/java/{com/wurrly => io/proteus}/server/handlers/ServerDefaultResponseListener.java (95%) create mode 100644 src/main/java/io/proteus/server/handlers/ServerFallbackHandler.java rename src/main/java/{com/wurrly => io/proteus}/server/handlers/benchmark/BenchmarkHandlers.java (98%) rename src/main/java/{com/wurrly => io/proteus}/server/predicates/MaxRequestContentLengthPredicate.java (97%) rename src/main/java/{com/wurrly => io/proteus}/server/predicates/ServerPredicates.java (96%) rename src/main/java/{com/wurrly => io/proteus}/server/swagger/AnnotationHelper.java (98%) rename src/main/java/{com/wurrly => io/proteus}/server/swagger/Reader.java (99%) rename src/main/java/{com/wurrly => io/proteus}/server/swagger/ServerParameterExtension.java (97%) rename src/main/java/{com/wurrly => io/proteus}/services/AssetsService.java (95%) rename src/main/java/{com/wurrly => io/proteus}/services/BaseService.java (93%) rename src/main/java/{com/wurrly => io/proteus}/services/SwaggerService.java (96%) rename src/main/java/{com/wurrly => io/proteus}/tests/JsonViewTest.java (98%) rename src/main/java/{com/wurrly => io/proteus}/tests/TestInvoker.java (98%) rename src/main/java/{com/wurrly => io/proteus}/tests/TestJsoniterViews.java (98%) rename src/main/java/{com/wurrly => io/proteus}/tests/TestTypes.java (97%) rename src/main/java/{com/wurrly => io/proteus}/utilities/ChunkedStream.java (99%) rename src/main/java/{com/wurrly => io/proteus}/utilities/JsonMapper.java (99%) rename src/main/java/{com/wurrly => io/proteus}/utilities/ReapableQueue.java (99%) rename src/main/java/{com/wurrly => io/proteus}/utilities/SecurityOps.java (98%) delete mode 100644 src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerExtension delete mode 100644 src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerModelResolver diff --git a/conf/application.conf b/conf/application.conf index 2a01862..d97d14d 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -1,15 +1,11 @@ application { - env = dev version = "1.0" - name="Wurrly API" - - - + name="Wurrly API" # tmpdir tmpdir = ${java.io.tmpdir}/${application.name} @@ -31,7 +27,9 @@ application { # date format dateFormat = dd-MMM-yyyy - defaultResponseListener = "com.wurrly.server.handlers.ServerDefaultResponseListener" + fallbackHandler = "io.proteus.server.handlers.ServerFallbackHandler" + + defaultResponseListener = "io.proteus.server.handlers.ServerDefaultResponseListener" # number format, system default. set it at runtime # numberFormat = DecimalFormat.getInstance(${application.lang})).toPattern() @@ -44,13 +42,20 @@ application { # redirect to/force https # example: https://my.domain.com/{0} redirect_https = "" - - + } api.version="v1" +globalHeaders +{ +# Access-Control-Allow-Origin: "*" +# Access-Control-Allow-Methods: "*" +# Access-Control-Allow-Headers: "*" + Server: ${application.name} +} + assets { path = "/public" @@ -60,193 +65,6 @@ assets { } } -# images -image.size.min=120 -image.size.max=3200 -image.quality.max=80 - -# cassandra - - -cassandra.keyspace="wurrly" -cassandra.queryLimit=100 -cassandra.connections.max=100 -cassandra.connections.min=5 - -#redis - -redis.port=6379 -redis.password=null -redis.maxTotal=1024 -redis.maxIdle=10 -redis.minIdle=5 - -#elasticsearch - -es.index.name="wurrly" - - - -#graph - -graph.enabled = true - -# analytics - -events.batch.size=10 - -# okhttp - -okhttp.timeout=10 - -# azure - -azure.accountName="wurrly" -azure.accessKey.primary="lQyT2OeOYeNoYh/NX58LKCMFue6YYp7gjWLvH+2c5oq1s/jE0ur6kkN25oWn5vGDYdQgREmaZZHI6qpjs/FlnA==" -azure.accessKey.secondary="qYB2MkSrgsEAiXfFCVfG0xK7DDkmRCI8Y1KH0iWaQz+k+OdbLyOO8jax+ZqStWg0XIQL1SA099eUEcWGtCjRIA==" - -#ebean models - -ebean.default=[ "models.MediaContent", "models.VideoOverlay", "models.Mask", "models.ContentResource", "models.Content", "models.Hero", "models.Battle", "models.Tip", "models.PlaylistCategory", "models.Collaboration", "models.Review", "models.Collaborator", "models.CollaboratorComment", "models.MediaPurchase","models.AdminActivity","models.Playlist","models.SongTrack","models.Feature","models.Publisher","models.Label","models.Credentials","models.WurrlyModel","models.ArtistFact","models.ArtistQuestion","models.Property","models.Artist","models.Wurrly","models.Song","models.Report","models.Competition","models.Event","models.Comment", "models.User","models.adapter.UserEntityListener","models.adapter.SongEntityListener","models.adapter.WurrlyEntityListener"] - -# akka - -subsystem.worker.count=12 -subsystem.worker.timeout=60000 - -# netty - -play.http.parser.maxMemoryBuffer=256000K -play.http.parser.maxDiskBuffer=256000K - -# location - -location.country.db.path="support/geo/Country.mmdb" -location.city.db.path="support/geo/City.mmdb" -location.iso.codes.path="support/geo/territories.json" -location.default.region="GB" - -# hashids - -hashids.salt="3C0B0AEF-794F-4D89-9EEE-476CE9A89DFB" - -# newrelic - -newrelic.license.key="a9bfbe086c5964de4617fa0280077dd2273d3a6b" - -# users - -user.feed.item.limit=1500 -user.default.avatarPath="4c/50/b8/36/e7e2bf69ca.png" -user.default.bannerPath="57/60/9b/8f/61341a91f0.png" -user.password.backdoor="happyasaclamindecember" - - -# google cloud messaging - -gcm.senderId=1095155988888 -gcm.apiKey="AIzaSyDbHS8u7LEZQcr3_WooM5Ib-DUEU8HTCfU" - - -# twilio - -twilio.number="+16467987759" -twilio.sid="AC8a33a9fc51927ccd980ac919cdadcba5" -twilio.token="de44558f9a980b337512eb60b812f31a" - - - -#api - -api.authentication.header="X-Wurrly-Auth" -api.authentication.key="213fe69502445ed67ae8b99d22838802" - -# hfa -hfa.royaltyId.length=10 - -# shopify -shopify.api.key=769375b638f4a6132df62f3c10fdab21 -shopify.api.password=7f950bbb21cf43c0afe8c050907993b3 -shopify.api.secret=a9c0ebee8d529e05ded128c1738afbcb -shopify.login="josh@wurrly.com" -shopify.password="wuRR1y" -shopify.authorization="Basic NzY5Mzc1YjYzOGY0YTYxMzJkZjYyZjNjMTBmZGFiMjE6N2Y5NTBiYmIyMWNmNDNjMGFmZThjMDUwOTA3OTkzYjM=" -shopify.shop.url="https://wurrly.myshopify.com/admin" -shopify.expiration.days=6 -shopify.product.image.prefix="http://cdn1.wurrly.co/images/w550/" -shopify.domain="wurrly.myshopify.com" -shopify.channel.mobile="23087876" -shopify.product.price="1.99" - -#migration -migration.baseUrl="http://imaging.wurrly.co:4444/wurrlies?" - -#itms -itms.secret="a1f89c67d6e34599b1056b3f42f1c735" -itms.verification.production.url="https://buy.itunes.apple.com/verifyReceipt" -itms.verification.sandbox.url="https://sandbox.itunes.apple.com/verifyReceipt" - -#subscriptions - -user.max.wurrlies=20 - -#notifications - -notifications.enabled=1 - -#collaborations - -collaborations.maxUsers=4 - -#mailchimp - - -mailchimp.base.url="https://us9.api.mailchimp.com/3.0/" - -#password - -user.default.password="$2a$10$6T5QVxo16r7qoSdwm9Hx/.rJzWuMQEFoJ6X/VL0DKY0uxaO.XSjBa" - -#battles - -battle.voting.duration=48 - -#sift - -sift.api.key="GT4cFVEZegH4N5jxq5rj" -sift.api.url="https://wur28vu8.pottymouthfilter.com/v1/" include "swagger.conf" - -# The application languages -# ~~~~~ - - -# Router -# ~~~~~ -# Define the Router object to use for this application. -# This router will be looked up first when the application is starting up, -# so make sure this is the entry point. -# Furthermore, it's assumed your route file is named properly. -# So for an application router like `my.application.Router`, -# you may need to define a router file `conf/my.application.routes`. -# Default to Routes in the root package (and conf/routes) -# play.http.router = my.application.Routes - -# Database configuration -# ~~~~~ -# You can declare as many datasources as you want. -# By convention, the default datasource is named `default` -# -# db.default.driver=org.h2.Driver -# db.default.url="jdbc:h2:mem:play" -# db.default.username=sa -# db.default.password="" - -# Evolutions -# ~~~~~ -# You can disable evolutions if needed -# play.evolutions.enabled=false - -# You can disable evolutions for a specific datasource if necessary -# play.evolutions.db.default.enabled=false + \ No newline at end of file diff --git a/conf/logback.xml b/conf/logback.xml index 2c628ce..71c7db4 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -20,8 +20,8 @@ - - + + diff --git a/pom.xml b/pom.xml index 7a840ec..05caa4f 100644 --- a/pom.xml +++ b/pom.xml @@ -249,7 +249,7 @@ - com.wurrly + io.proteus jsoniter 0.9.8 diff --git a/wurrly-undertow.iml b/proteus.iml similarity index 100% rename from wurrly-undertow.iml rename to proteus.iml diff --git a/src/main/java/com/wurrly/Application.java b/src/main/java/io/proteus/Application.java similarity index 66% rename from src/main/java/com/wurrly/Application.java rename to src/main/java/io/proteus/Application.java index 3e4b309..03beb2f 100644 --- a/src/main/java/com/wurrly/Application.java +++ b/src/main/java/io/proteus/Application.java @@ -1,15 +1,9 @@ /** * */ -package com.wurrly; +package io.proteus; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -31,30 +25,24 @@ import com.jsoniter.DecodingMode; import com.jsoniter.JsonIterator; import com.jsoniter.annotation.JsoniterAnnotationSupport; -import com.jsoniter.output.Codegen; import com.jsoniter.output.EncodingMode; import com.jsoniter.output.JsonStream; -import com.jsoniter.spi.Encoder; -import com.jsoniter.spi.TypeLiteral; import com.typesafe.config.Config; -import com.wurrly.controllers.Users; -import com.wurrly.modules.ConfigModule; -import com.wurrly.modules.RoutingModule; -import com.wurrly.server.endpoints.EndpointInfo; -import com.wurrly.server.handlers.HandlerGenerator; -import com.wurrly.server.handlers.benchmark.BenchmarkHandlers; -import com.wurrly.services.AssetsService; -import com.wurrly.services.SwaggerService; - -import io.undertow.Handlers; + +import io.proteus.controllers.Benchmarks; +import io.proteus.controllers.Users; +import io.proteus.modules.ConfigModule; +import io.proteus.server.endpoints.EndpointInfo; +import io.proteus.server.handlers.BaseHttpHandler; +import io.proteus.server.handlers.GlobalHeaderHttpHandler; +import io.proteus.server.handlers.HandlerGenerator; +import io.proteus.services.AssetsService; +import io.proteus.services.SwaggerService; import io.undertow.Undertow; import io.undertow.UndertowOptions; 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.HttpString; /** * @author jbauer */ @@ -144,26 +132,39 @@ public Undertow buildServer() final RoutingHandler router = injector.getInstance(RoutingHandler.class); final DefaultResponseListener defaultResponseListener = injector.getInstance(DefaultResponseListener.class); - - HandlerGenerator generator = new HandlerGenerator("com.wurrly.controllers.handlers","RouteHandlers"); - injector.injectMembers(generator); - - Supplier generatedRouteSupplier = injector.getInstance(generator.compileClass()); - router.addAll(generatedRouteSupplier.get()); - - router.addAll(new BenchmarkHandlers().get()); + for(Class controllerClass : registeredControllers) + { + HandlerGenerator generator = new HandlerGenerator("io.proteus.controllers.handlers",controllerClass); + + injector.injectMembers(generator); - StringBuilder sb = new StringBuilder(); + Supplier generatedRouteSupplier = injector.getInstance(generator.compileClass()); + + router.addAll(generatedRouteSupplier.get()); + } + + Config globalHeaders = rootConfig.getConfig("globalHeaders"); + Map globalHeadersParameters = globalHeaders.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().render())); + + HttpHandler baseHandler = new BaseHttpHandler(router, defaultResponseListener); + + final GlobalHeaderHttpHandler globalHeaderHandler = injector.getInstance(GlobalHeaderHttpHandler.class); + + //baseHandler = globalHeaderHandler.wrap(baseHandler); + + StringBuilder sb = new StringBuilder(); + + sb.append("\n\nUsing the following global headers: \n\n"); + sb.append(globalHeadersParameters.entrySet().stream().map( e -> "\t" + e.getKey() + " = " + e.getValue() ).collect(Collectors.joining("\n"))); + sb.append("\n\nRegistered the following endpoints: \n\n"); + sb.append(this.registeredEndpoints.stream().sorted().map(EndpointInfo::toString).collect(Collectors.joining("\n"))); + sb.append("\n"); - this.registeredEndpoints.stream().forEachOrdered( r -> sb.append(r.toString()).append("\n")); - - log.info("\n\nRegistered the following endpoints: \n\n" + sb.toString()); - - - + log.info(sb.toString()); + webServer = Undertow.builder() .addHttpListener(rootConfig.getInt("application.port"),rootConfig.getString("application.host")) .setBufferSize(1024 * 16) @@ -176,34 +177,8 @@ public Undertow buildServer() .setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, false) .setServerOption(UndertowOptions.MAX_ENTITY_SIZE, 1000000L * 200 ) .setWorkerThreads(Runtime.getRuntime().availableProcessors()*8) - .setHandler( - new HttpHandler() - { - - @Override - public void handleRequest(final HttpServerExchange exchange) throws Exception - { - - exchange.addDefaultResponseListener(defaultResponseListener); - -// exchange.getResponseHeaders().put(HttpString.tryFromString("Access-Control-Allow-Origin"), "*"); -// exchange.getResponseHeaders().put(HttpString.tryFromString("Access-Control-Allow-Methods"), "*"); -// exchange.getResponseHeaders().put(HttpString.tryFromString("Access-Control-Allow-Headers"), "*"); - //exchange.getResponseHeaders().put(Headers.SERVER, "Bowser"); - - try { - router.handleRequest(exchange); - } catch (Exception e) - { - if(exchange.isResponseChannelAvailable()) { - log.error(e.getMessage()); - exchange.endExchange(); - } - } - - } - } - ).build(); + .setHandler( baseHandler ) + .build(); @@ -240,6 +215,8 @@ public static void main(String[] args) app.useController(Users.class); + app.useController(Benchmarks.class); + app.start(); } catch (Exception e) @@ -251,13 +228,6 @@ public static void main(String[] args) } - public static class BaseHandlers - { - public static void notFoundHandler(HttpServerExchange exchange) { - exchange.setStatusCode(404); - exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); - exchange.getResponseSender().send("Page Not Found!!"); - } - } + } diff --git a/src/main/java/io/proteus/controllers/Benchmarks.java b/src/main/java/io/proteus/controllers/Benchmarks.java new file mode 100644 index 0000000..c16d52c --- /dev/null +++ b/src/main/java/io/proteus/controllers/Benchmarks.java @@ -0,0 +1,100 @@ +/** + * + */ +package io.proteus.controllers; + +import static io.proteus.server.ServerResponse.response; + +import java.io.ByteArrayOutputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Singleton; +import com.jsoniter.output.JsonStream; + +import io.proteus.models.World; +import io.proteus.server.ServerResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.undertow.server.HttpServerExchange; + +/** + * @author jbauer + * + */ +@Api(tags="benchmark") +@Path("/benchmark") +@Produces((MediaType.APPLICATION_JSON)) +@Consumes((MediaType.MEDIA_TYPE_WILDCARD)) +@Singleton +public class Benchmarks +{ + + + @GET + @Path("/json") + @ApiOperation(value = "Json serialization endpoint", httpMethod = "GET" ) + public void json(HttpServerExchange exchange) + { + response( JsonStream.serialize(ImmutableMap.of("message", "Hello, World!")) ).send(exchange); + } + + @GET + @Path("/world") + @ApiOperation(value = "World serialization endpoint", httpMethod = "GET" ) + public void world(HttpServerExchange exchange) + { + JsonStream stream = JsonStream.localStream(); + World world = new World(123,123); + try + { + world.serialize(stream); + response( stream.toString() ).applicationJson().send(exchange); + + stream.close(); + + } catch (Exception e) + { + + } + + } + + @GET + @Path("/world2") + @ApiOperation(value = "World serialization endpoint", httpMethod = "GET" ) + public ServerResponse world2() + { + World world = new World(123,123); + + return response( world ).applicationJson(); + } + + @GET + @Path("/world3") + @ApiOperation(value = "World serialization endpoint", httpMethod = "GET" ) + public void world3(HttpServerExchange exchange) + { + World world = new World(123,123); + + response( JsonStream.serialize(world) ).applicationJson().send(exchange); + + + } + + + @GET + @Path("/plaintext") + @Produces((MediaType.TEXT_PLAIN)) + @ApiOperation(value = "Plaintext endpoint", httpMethod = "GET" ) + public void plaintext(HttpServerExchange exchange) + { + response("Hello, World!").textPlain().send(exchange); + + } +} diff --git a/src/main/java/com/wurrly/controllers/Users.java b/src/main/java/io/proteus/controllers/Users.java similarity index 84% rename from src/main/java/com/wurrly/controllers/Users.java rename to src/main/java/io/proteus/controllers/Users.java index 5bed6df..5000c93 100644 --- a/src/main/java/com/wurrly/controllers/Users.java +++ b/src/main/java/io/proteus/controllers/Users.java @@ -1,9 +1,9 @@ /** * */ -package com.wurrly.controllers; +package io.proteus.controllers; -import static com.wurrly.server.ServerResponse.response; +import static io.proteus.server.ServerResponse.response; import java.nio.ByteBuffer; import java.util.Date; @@ -33,10 +33,10 @@ import com.jsoniter.any.Any; import com.jsoniter.output.JsonStream; import com.typesafe.config.Config; -import com.wurrly.models.User; -import com.wurrly.server.ServerRequest; -import com.wurrly.server.ServerResponse; +import io.proteus.models.User; +import io.proteus.server.ServerRequest; +import io.proteus.server.ServerResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -52,13 +52,9 @@ @Singleton public class Users { - - @Inject - @Named("es.index.name") - protected String esIndexName; - + @Inject - protected Config configuration; + protected Config config; private static Logger log = LoggerFactory.getLogger(Users.class.getCanonicalName()); @@ -103,9 +99,8 @@ public ServerResponse userType( log.debug("optionalDate: " + optionalDate); - return response(User.class) - .ok() - .entity(new User(232343L)) + return response(new User(232343L)) + .ok() .header(HttpString.tryFromString("TestHeader"), "57475475"); } @@ -128,7 +123,7 @@ public ServerResponse userForm( final ServerRequest serverRequest, log.debug("testFile: " + testFile); // // - return response(Any.class).ok().entity(Any.wrap(new User(userId,type))); + return response(Any.wrap(new User(userId,type))).ok(); } @@ -136,7 +131,7 @@ public ServerResponse userForm( final ServerRequest serverRequest, @GET @Path("/{userId}") @ApiOperation(value = "Find users by id", httpMethod = "GET", response = User.class) - public ServerResponse user( final ServerRequest serverRequest, + public ServerResponse user( final ServerRequest serverRequest, @ApiParam(name="userId", required=true) @PathParam("userId") final Long userId, @ApiParam(name="context", required=false) @QueryParam("context") Optional context ) @@ -148,7 +143,7 @@ public ServerResponse user( final ServerRequest serverRequest, // log.debug("context: " + context); // // - return response(String.class) + return response(User.class) .ok() .applicationJson() .body(JsonStream.serialize(new User(userId))); @@ -157,12 +152,13 @@ public ServerResponse user( final ServerRequest serverRequest, } + @SuppressWarnings("rawtypes") @POST @Path("/") //@Consumes("multipart/form-data") // @ApiImplicitParams({ @ApiImplicitParam(dataType = "com.wurrly.models.User", name = "user", paramType = "body", required = false, allowMultiple = false) }) @ApiOperation(value = "Create a user", httpMethod = "POST", response = User.class) - public ServerResponse createUser( final ServerRequest serverRequest, + public ServerResponse createUser( final ServerRequest serverRequest, @QueryParam("context") Optional context, final User user, List stringArgs, @@ -170,20 +166,19 @@ public ServerResponse createUser( final ServerRequest serverRequest, ) { - ServerResponse response = null; + ServerResponse response = null; if( user != null ) { - response = response(User.class).ok().entity(user) ; + return response(User.class).ok().entity(user) ; } else { - response = response().exception(new Exception("No user found")) ; + return response().throwable(new Exception("No user found")) ; } - - return response; + } @PUT @@ -194,8 +189,7 @@ public ServerResponse createUser( final ServerRequest serverRequest, @ApiOperation(value = "Update a user's name", httpMethod = "PUT", response = User.class) public CompletableFuture>> updateUsername(@ApiParam(hidden=true)final ServerRequest serverRequest, @QueryParam("context") Optional context, final List users ) { -// - log.debug("esIndexName: " + esIndexName); +// log.debug("context: " + context); log.debug("request: " + serverRequest); log.debug("file: " + users); @@ -217,22 +211,6 @@ public CompletableFuture> empty() } - @GET - @Path("/raw") - @ApiOperation(value = "Test a raw control endpoint", httpMethod = "GET" ) - public void raw(HttpServerExchange exchange) - { - exchange.getResponseSender().send("end"); - - } - - @GET - @Path("/raw2") - @ApiOperation(value = "Test a raw control endpoint", httpMethod = "GET" ) - public void raw2(HttpServerExchange exchange) - { - response("end").textPlain().send(exchange); - } } diff --git a/src/main/java/com/wurrly/models/User.java b/src/main/java/io/proteus/models/User.java similarity index 97% rename from src/main/java/com/wurrly/models/User.java rename to src/main/java/io/proteus/models/User.java index 82e36cd..d38bfda 100644 --- a/src/main/java/com/wurrly/models/User.java +++ b/src/main/java/io/proteus/models/User.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.models; +package io.proteus.models; import com.jsoniter.annotation.JsonIgnore; import com.jsoniter.annotation.JsonWrapper; diff --git a/src/main/java/io/proteus/models/World.java b/src/main/java/io/proteus/models/World.java new file mode 100644 index 0000000..93d6358 --- /dev/null +++ b/src/main/java/io/proteus/models/World.java @@ -0,0 +1,40 @@ +/** + * + */ +package io.proteus.models; + +import com.jsoniter.output.JsonStream; +import com.jsoniter.output.StreamImplNumber; +import com.jsoniter.output.StreamImplString; + +/** + * @author jbauer + * + */ +public final class World { + public int id; + public int randomNumber; + + /** + * Constructs a new world object with the given parameters. + * + * @param id the ID of the world + * @param randomNumber the random number of the world + */ + public World(int id, int randomNumber) { + this.id = id; + this.randomNumber = randomNumber; + } + + + public void serialize(JsonStream stream) throws Exception { + stream.writeByte(JsonStream.OBJECT_START); + StreamImplString.writeStringWithoutQuote(stream,"\"id\":"); + StreamImplNumber.writeInt(stream,this.id); + stream.writeByte(JsonStream.COMMA); + + StreamImplString.writeStringWithoutQuote(stream,",\"randomNumber\":"); + StreamImplNumber.writeInt(stream,this.randomNumber); + stream.writeByte(JsonStream.OBJECT_END); + } +} diff --git a/src/main/java/com/wurrly/modules/ConfigModule.java b/src/main/java/io/proteus/modules/ConfigModule.java similarity index 99% rename from src/main/java/com/wurrly/modules/ConfigModule.java rename to src/main/java/io/proteus/modules/ConfigModule.java index 052201b..68bf27d 100644 --- a/src/main/java/com/wurrly/modules/ConfigModule.java +++ b/src/main/java/io/proteus/modules/ConfigModule.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.modules; +package io.proteus.modules; import java.io.File; import java.lang.reflect.Type; diff --git a/src/main/java/com/wurrly/modules/RoutingModule.java b/src/main/java/io/proteus/modules/RoutingModule.java similarity index 66% rename from src/main/java/com/wurrly/modules/RoutingModule.java rename to src/main/java/io/proteus/modules/RoutingModule.java index 7465028..596651d 100644 --- a/src/main/java/com/wurrly/modules/RoutingModule.java +++ b/src/main/java/io/proteus/modules/RoutingModule.java @@ -1,9 +1,8 @@ /** * */ -package com.wurrly.modules; +package io.proteus.modules; -import java.nio.file.Paths; import java.util.HashSet; import java.util.Set; import java.util.TreeSet; @@ -17,16 +16,11 @@ import com.google.inject.TypeLiteral; import com.google.inject.name.Names; import com.typesafe.config.Config; -import com.wurrly.Application.BaseHandlers; -import com.wurrly.server.endpoints.EndpointInfo; -import io.undertow.predicate.TruePredicate; +import io.proteus.server.endpoints.EndpointInfo; import io.undertow.server.DefaultResponseListener; import io.undertow.server.HttpHandler; import io.undertow.server.RoutingHandler; -import io.undertow.server.handlers.resource.FileResourceManager; -import io.undertow.server.handlers.resource.ResourceHandler; -import io.undertow.util.Methods; /** * @author jbauer @@ -56,9 +50,19 @@ protected void configure() this.binder().requestInjection(this); - RoutingHandler router = new RoutingHandler() - .setFallbackHandler(BaseHandlers::notFoundHandler); + + RoutingHandler router = new RoutingHandler(); + try + { + String className = config.getString("application.fallbackHandler"); + log.info("Installing FallbackListener " + className); + Class clazz = (Class) Class.forName(className); + router.setFallbackHandler(clazz.newInstance()); + } catch (Exception e) + { + log.error(e.getMessage(),e); + } this.bind(RoutingHandler.class).toInstance(router); @@ -67,15 +71,16 @@ protected void configure() try { - String defaultResponseListenerClassName = config.getString("application.defaultResponseListener"); - Class defaultResponseListenerClass = (Class) Class.forName(defaultResponseListenerClassName); - this.bind(DefaultResponseListener.class).to(defaultResponseListenerClass).in(Singleton.class); + String className = config.getString("application.defaultResponseListener"); + log.info("Installing DefaultResponseListener " + className); + Class clazz = (Class) Class.forName(className); + this.bind(DefaultResponseListener.class).to(clazz).in(Singleton.class); } catch (Exception e) { log.error(e.getMessage(),e); } - + this.bind(new TypeLiteral>>() {}).annotatedWith(Names.named("registeredControllers")).toInstance(registeredControllers); this.bind(new TypeLiteral>() {}).annotatedWith(Names.named("registeredEndpoints")).toInstance(registeredEndpoints); diff --git a/src/main/java/com/wurrly/server/Extractors.java b/src/main/java/io/proteus/server/Extractors.java similarity index 95% rename from src/main/java/com/wurrly/server/Extractors.java rename to src/main/java/io/proteus/server/Extractors.java index 4a4eac1..a305cc3 100644 --- a/src/main/java/com/wurrly/server/Extractors.java +++ b/src/main/java/io/proteus/server/Extractors.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server; +package io.proteus.server; import java.io.IOException; import java.lang.reflect.Method; @@ -23,8 +23,8 @@ import com.jsoniter.JsonIterator; import com.jsoniter.any.Any; import com.jsoniter.spi.TypeLiteral; -import com.wurrly.server.predicates.ServerPredicates; +import io.proteus.server.predicates.ServerPredicates; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.form.FormData.FormValue; import io.undertow.server.handlers.form.FormDataParser; @@ -43,7 +43,12 @@ public class Extractors public static class Optional { - + + public static java.util.Optional extractWithFunction(final HttpServerExchange exchange, final String name, Function function) + { + return string(exchange, name).map(function); + } + public static java.util.Optional jsonIterator(final HttpServerExchange exchange) { return java.util.Optional.ofNullable(exchange.getAttachment(ServerRequest.BYTE_BUFFER_KEY)).map(ByteBuffer::array).map(JsonIterator::parse); @@ -126,14 +131,12 @@ public static java.util.Optional xmlModel(final HttpServerExchange excha }); } - - + public static java.util.Optional date(final HttpServerExchange exchange,final String name) { - return string(exchange, name).map( ZonedDateTime::parse ).map(ZonedDateTime::toInstant).map(Date::from); - + } public static java.util.Optional any(final HttpServerExchange exchange ) @@ -166,7 +169,7 @@ public static java.util.Optional longValue(final HttpServerExchange excha { return string(exchange, name).map(Long::parseLong); } - + public static java.util.Optional booleanValue(final HttpServerExchange exchange, final String name) { return string(exchange, name).map(Boolean::parseBoolean); @@ -304,6 +307,17 @@ public static ByteBuffer fileBytes(final HttpServerExchange exchange, final Str } + + public static String string(final HttpServerExchange exchange, final String name) + { + return exchange.getQueryParameters().get(name).getFirst(); + } + + public static T extractWithFunction(final HttpServerExchange exchange, final String name, Function function) + { + return function.apply(exchange.getQueryParameters().get(name).getFirst()); + } + public static Float floatValue(final HttpServerExchange exchange, final String name) { return Float.parseFloat(string(exchange, name)); @@ -313,15 +327,11 @@ public static Double doubleValue(final HttpServerExchange exchange, final Strin { return Double.parseDouble(string(exchange, name)); } - - public static String string(final HttpServerExchange exchange, final String name) - { - return exchange.getQueryParameters().get(name).getFirst(); - } + public static Long longValue(final HttpServerExchange exchange, final String name) { - return Long.parseLong(string(exchange, name)); + return Long.parseLong( string(exchange, name) ); } public static Integer integerValue(final HttpServerExchange exchange, final String name) diff --git a/src/main/java/com/wurrly/server/MediaType.java b/src/main/java/io/proteus/server/MediaType.java similarity index 99% rename from src/main/java/com/wurrly/server/MediaType.java rename to src/main/java/io/proteus/server/MediaType.java index 3a395bd..5fef26c 100644 --- a/src/main/java/com/wurrly/server/MediaType.java +++ b/src/main/java/io/proteus/server/MediaType.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server; +package io.proteus.server; /** * @author jbauer diff --git a/src/main/java/com/wurrly/server/MimeTypes.java b/src/main/java/io/proteus/server/MimeTypes.java similarity index 95% rename from src/main/java/com/wurrly/server/MimeTypes.java rename to src/main/java/io/proteus/server/MimeTypes.java index c06becf..6d5d82b 100644 --- a/src/main/java/com/wurrly/server/MimeTypes.java +++ b/src/main/java/io/proteus/server/MimeTypes.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server; +package io.proteus.server; /** * @author jbauer diff --git a/src/main/java/com/wurrly/server/ServerRequest.java b/src/main/java/io/proteus/server/ServerRequest.java similarity index 97% rename from src/main/java/com/wurrly/server/ServerRequest.java rename to src/main/java/io/proteus/server/ServerRequest.java index 1e0f790..9fe4ed9 100644 --- a/src/main/java/com/wurrly/server/ServerRequest.java +++ b/src/main/java/io/proteus/server/ServerRequest.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server; +package io.proteus.server; import java.io.File; import java.io.IOException; @@ -16,8 +16,7 @@ import org.slf4j.LoggerFactory; import org.xnio.channels.StreamSourceChannel; -import com.wurrly.server.predicates.ServerPredicates; - +import io.proteus.server.predicates.ServerPredicates; import io.undertow.connector.PooledByteBuffer; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.form.FormData; @@ -60,7 +59,7 @@ public ServerRequest() public ServerRequest(HttpServerExchange exchange) throws IOException { this.method = exchange.getRequestMethod().toString(); - this.path = URLDecoder.decode(exchange.getRequestPath(), CHARSET); + this.path = exchange.getRequestPath(); this.exchange = exchange; this.contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); @@ -84,10 +83,6 @@ else if ( ServerPredicates.STRING_BODY_PREDICATE.resolve(exchange) ) } - public void respond(ServerResponse response) - { - - } public Deque files(final String name) { diff --git a/src/main/java/com/wurrly/server/ServerResponse.java b/src/main/java/io/proteus/server/ServerResponse.java similarity index 84% rename from src/main/java/com/wurrly/server/ServerResponse.java rename to src/main/java/io/proteus/server/ServerResponse.java index 8da1602..184adb0 100644 --- a/src/main/java/com/wurrly/server/ServerResponse.java +++ b/src/main/java/io/proteus/server/ServerResponse.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server; +package io.proteus.server; import java.nio.ByteBuffer; import java.util.HashMap; @@ -15,8 +15,8 @@ import com.jsoniter.output.JsonContext; import com.jsoniter.output.JsonStream; import com.jsoniter.spi.Encoder; -import com.wurrly.server.predicates.ServerPredicates; +import io.proteus.server.predicates.ServerPredicates; import io.undertow.attribute.ExchangeAttributes; import io.undertow.io.IoCallback; import io.undertow.predicate.Predicate; @@ -53,8 +53,9 @@ public class ServerResponse protected boolean hasCookies = false; protected boolean hasHeaders = false; protected boolean hasIoCallback = false; - protected boolean isXml = false; - protected boolean isJson = false; + protected boolean processXml = false; + protected boolean processJson = false; + protected boolean preprocessed = false; public ServerResponse() { @@ -134,37 +135,49 @@ public void setContentType(String contentType) if (this.contentType.equals(MimeTypes.APPLICATION_JSON_TYPE)) { - this.isJson = true; + if(!this.preprocessed) + { + this.processJson = true; + } } else if (this.contentType.equals(MimeTypes.APPLICATION_XML_TYPE)) { - this.isXml = true; + if(!this.preprocessed) + { + this.processXml = true; + } } } public ServerResponse body(ByteBuffer body) { this.body = body; + this.preprocessed = true; return this; } + + + public ServerResponse body(String body) + { + return this.body( ByteBuffer.wrap(body.getBytes()) ); + } public ServerResponse entity(T entity) { this.entity = entity; return this; - } + } public ServerResponse throwable(Throwable throwable) { this.throwable = throwable; + if (this.status == StatusCodes.ACCEPTED) + { + badRequest(); + } return this; } - - public ServerResponse body(String body) - { - this.body = ByteBuffer.wrap(body.getBytes()); - return this; - } + public ServerResponse status(int status) { @@ -182,8 +195,7 @@ public ServerResponse header(HttpString headerName, String value) public ServerResponse cookie(String cookieName, Cookie cookie) { this.cookies.put(cookieName, cookie); - this.hasCookies = true; - + this.hasCookies = true; return this; } @@ -195,9 +207,11 @@ public ServerResponse contentType(String contentType) public ServerResponse applicationJson() { + if(!this.preprocessed) + { + this.processJson = true; + } this.contentType = MimeTypes.APPLICATION_JSON_TYPE; - this.isJson = true; - return this; } @@ -209,8 +223,10 @@ public ServerResponse textHtml() public ServerResponse applicationXml() { - this.contentType = MimeTypes.APPLICATION_XML_TYPE; - this.isXml = true; + if(!this.preprocessed) + { + this.processXml = true; + } this.contentType = MimeTypes.APPLICATION_XML_TYPE; return this; } @@ -288,15 +304,7 @@ public ServerResponse withIoCallback(IoCallback ioCallback) return this; } - public ServerResponse exception(Throwable t) - { - if (this.status == StatusCodes.ACCEPTED) - { - badRequest(); - } - return this.throwable(t); - } - + public void send( final HttpServerExchange exchange) throws RuntimeException { send(null,exchange); @@ -332,7 +340,7 @@ public void send(final HttpHandler handler, final HttpServerExchange exchange) t { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, this.contentType); } - else if (!this.isJson && !this.isXml) + else if (!this.processJson && !this.processXml) { if (ServerPredicates.ACCEPT_JSON_PREDICATE.resolve(exchange)) { @@ -362,33 +370,41 @@ else if (hasEntity) try { - if (this.isXml) + if (this.processXml) { exchange.getResponseSender().send(ByteBuffer.wrap(XML_MAPPER.writeValueAsBytes(this.entity))); } else { - if (exchange.isInIoThread() && handler != null) - { - exchange.dispatch(handler); - return; - } - - exchange.startBlocking(); - - final int bufferSize = exchange.getConnection().getBufferSize(); +// if (exchange.isInIoThread() && handler != null) +// { +// exchange.dispatch(handler); +// return; +// } +// +// exchange.startBlocking(); +// +// final int bufferSize = exchange.getConnection().getBufferSize(); +// +// /** +// * @TODO Test that this is faster than a thread local JsonStream with the TypeLiteral relevant encoder +// **/ +// +// try (final JsonStream stream = new JsonStream(exchange.getOutputStream(), bufferSize)) +// { +// stream.writeViewVal(this.entity,this.jsonContext); +// } +// +// exchange.endExchange(); - /** - * @TODO Test that this is faster than a thread local JsonStream with the TypeLiteral relevant encoder - **/ - - try (final JsonStream stream = new JsonStream(exchange.getOutputStream(), bufferSize)) + try { - stream.writeViewVal(this.entity,this.jsonContext); + exchange.getResponseSender().send(JsonStream.serialize(this.entity, this.jsonContext)); + } catch (Exception e) + { + } - exchange.endExchange(); - } } catch (Exception e) diff --git a/src/main/java/com/wurrly/server/endpoints/EndpointInfo.java b/src/main/java/io/proteus/server/endpoints/EndpointInfo.java similarity index 99% rename from src/main/java/com/wurrly/server/endpoints/EndpointInfo.java rename to src/main/java/io/proteus/server/endpoints/EndpointInfo.java index 679812f..210fbff 100644 --- a/src/main/java/com/wurrly/server/endpoints/EndpointInfo.java +++ b/src/main/java/io/proteus/server/endpoints/EndpointInfo.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.endpoints; +package io.proteus.server.endpoints; import org.apache.commons.lang3.builder.CompareToBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; diff --git a/src/main/java/io/proteus/server/handlers/BaseHttpHandler.java b/src/main/java/io/proteus/server/handlers/BaseHttpHandler.java new file mode 100644 index 0000000..f8f9810 --- /dev/null +++ b/src/main/java/io/proteus/server/handlers/BaseHttpHandler.java @@ -0,0 +1,57 @@ +/** + * + */ +package io.proteus.server.handlers; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.undertow.server.DefaultResponseListener; +import io.undertow.server.HttpHandler; +import io.undertow.server.HttpServerExchange; + +/** + * @author jbauer + */ +public class BaseHttpHandler implements HttpHandler +{ + private static Logger log = LoggerFactory.getLogger(BaseHttpHandler.class.getCanonicalName()); + + protected DefaultResponseListener defaultResponseListener; + protected HttpHandler rootHandler; + + /** + * @param defaultResponseListener + * @param rootHandler + */ + public BaseHttpHandler(HttpHandler rootHandler,DefaultResponseListener defaultResponseListener) + { + this.defaultResponseListener = defaultResponseListener; + this.rootHandler = rootHandler; + } + + /* + * (non-Javadoc) + * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange) + */ + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception + { + + //exchange.addDefaultResponseListener(defaultResponseListener); + + try + { + rootHandler.handleRequest(exchange); + } catch (Exception e) + { + if (exchange.isResponseChannelAvailable()) + { + log.error(e.getMessage()); + exchange.endExchange(); + } + } + + } + +} diff --git a/src/main/java/io/proteus/server/handlers/GlobalHeaderHttpHandler.java b/src/main/java/io/proteus/server/handlers/GlobalHeaderHttpHandler.java new file mode 100644 index 0000000..c84e317 --- /dev/null +++ b/src/main/java/io/proteus/server/handlers/GlobalHeaderHttpHandler.java @@ -0,0 +1,71 @@ +/** + * + */ +package io.proteus.server.handlers; + +import java.util.Map; +import java.util.stream.Collectors; + +import com.google.inject.Inject; +import com.typesafe.config.Config; + +import io.undertow.server.HandlerWrapper; +import io.undertow.server.HttpHandler; +import io.undertow.server.HttpServerExchange; +import io.undertow.util.HeaderMap; +import io.undertow.util.HeaderValues; +import io.undertow.util.HttpString; + +/** + * @author jbauer + * + */ +public class GlobalHeaderHttpHandler implements HttpHandler, HandlerWrapper +{ + protected HttpHandler next; + protected final HeaderMap headers = new HeaderMap(); + + + @Inject + public GlobalHeaderHttpHandler(Config config ) + { + Config globalHeaders = config.getConfig("globalHeaders"); + + Map globalHeaderParameters = globalHeaders.entrySet().stream().collect(Collectors.toMap(e -> HttpString.tryFromString(e.getKey()), e ->e.getValue().render())); + + for( Map.Entry e : globalHeaderParameters.entrySet() ) + { + headers.add(e.getKey(), e.getValue()); + } + } + + /* (non-Javadoc) + * @see io.undertow.server.HandlerWrapper#wrap(io.undertow.server.HttpHandler) + */ + @Override + public HttpHandler wrap(final HttpHandler handler) + { + this.next = handler; + return this; + } + + /* (non-Javadoc) + * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange) + */ + @Override + public void handleRequest(final HttpServerExchange exchange) throws Exception + { + + long fiGlobal = this.headers.fastIterateNonEmpty(); + while (fiGlobal != -1) { + + final HeaderValues headerValues = headers.fiCurrent(fiGlobal); + exchange.getResponseHeaders().addAll(headerValues.getHeaderName(), headerValues); + fiGlobal = headers.fiNextNonEmpty(fiGlobal); + } + + next.handleRequest(exchange); + + } + +} diff --git a/src/main/java/com/wurrly/server/handlers/HandlerGenerator.java b/src/main/java/io/proteus/server/handlers/HandlerGenerator.java similarity index 90% rename from src/main/java/com/wurrly/server/handlers/HandlerGenerator.java rename to src/main/java/io/proteus/server/handlers/HandlerGenerator.java index 7523e68..4e7907c 100644 --- a/src/main/java/com/wurrly/server/handlers/HandlerGenerator.java +++ b/src/main/java/io/proteus/server/handlers/HandlerGenerator.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.handlers; +package io.proteus.server.handlers; import java.io.File; import java.lang.reflect.Method; @@ -50,11 +50,11 @@ import com.squareup.javapoet.ParameterSpec; import com.squareup.javapoet.ParameterizedTypeName; import com.squareup.javapoet.TypeSpec; -import com.wurrly.server.Extractors; -import com.wurrly.server.ServerRequest; -import com.wurrly.server.ServerResponse; -import com.wurrly.server.endpoints.EndpointInfo; +import io.proteus.server.Extractors; +import io.proteus.server.ServerRequest; +import io.proteus.server.ServerResponse; +import io.proteus.server.endpoints.EndpointInfo; import io.swagger.annotations.Api; import io.undertow.server.HttpServerExchange; import io.undertow.server.RoutingHandler; @@ -85,56 +85,56 @@ public enum StatementParameterType public enum TypeHandler { - LongType("Long $L = $T.longValue(exchange,$S)", false, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class, StatementParameterType.STRING), - IntegerType("Integer $L = $T.integerValue(exchange,$S)", false, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class, StatementParameterType.STRING), - StringType("String $L = $T.string(exchange,$S)", false, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class, StatementParameterType.STRING), - BooleanType("Boolean $L = $T.booleanValue(exchange,$S)", false, StatementParameterType.LITERAL, com.wurrly.server.Extractors.class, StatementParameterType.STRING), - FilePathType("$T $L = $T.filePath(exchange,$S)", true, java.nio.file.Path.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class, StatementParameterType.STRING), - AnyType("$T $L = $T.any(exchange)", true, com.jsoniter.any.Any.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class), - JsonIteratorType("$T $L = $T.jsonIterator(exchange)", true, com.jsoniter.JsonIterator.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class), - ModelType("$T $L = com.wurrly.server.Extractors.model(exchange,$L)", true, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.LITERAL), + LongType("Long $L = $T.longValue(exchange,$S)", false, StatementParameterType.LITERAL,io.proteus.server.Extractors.class, StatementParameterType.STRING), + IntegerType("Integer $L = $T.integerValue(exchange,$S)", false, StatementParameterType.LITERAL,io.proteus.server.Extractors.class, StatementParameterType.STRING), + StringType("String $L = $T.string(exchange,$S)", false, StatementParameterType.LITERAL,io.proteus.server.Extractors.class, StatementParameterType.STRING), + BooleanType("Boolean $L = $T.booleanValue(exchange,$S)", false, StatementParameterType.LITERAL, io.proteus.server.Extractors.class, StatementParameterType.STRING), + FilePathType("$T $L = $T.filePath(exchange,$S)", true, java.nio.file.Path.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.class, StatementParameterType.STRING), + AnyType("$T $L = $T.any(exchange)", true, com.jsoniter.any.Any.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.class), + JsonIteratorType("$T $L = $T.jsonIterator(exchange)", true, com.jsoniter.JsonIterator.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.class), + ModelType("$T $L = io.proteus.server.Extractors.model(exchange,$L)", true, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.LITERAL), - //EnumType("$T $L = $T.enumValue(exchange,$T.class,$S)", true, StatementParameterType.TYPE, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class, StatementParameterType.TYPE, StatementParameterType.STRING), - ByteBufferType("$T $L = $T.fileBytes(exchange,$S)", false, java.nio.ByteBuffer.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.class, StatementParameterType.STRING), - DateType("$T $L = $T.date(exchange,$S)", false, java.util.Date.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.class, StatementParameterType.STRING), - FloatType("Integer $L = $T.floatValue(exchange,$S)", false, StatementParameterType.LITERAL, com.wurrly.server.Extractors.class, StatementParameterType.STRING), - DoubleType("Integer $L = $T.doubleValue(exchange,$S)", false, StatementParameterType.LITERAL, com.wurrly.server.Extractors.class, StatementParameterType.STRING), + //EnumType("$T $L = $T.enumValue(exchange,$T.class,$S)", true, StatementParameterType.TYPE, StatementParameterType.LITERAL,io.proteus.server.Extractors.class, StatementParameterType.TYPE, StatementParameterType.STRING), + ByteBufferType("$T $L = $T.fileBytes(exchange,$S)", false, java.nio.ByteBuffer.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.class, StatementParameterType.STRING), + DateType("$T $L = $T.date(exchange,$S)", false, java.util.Date.class, StatementParameterType.LITERAL, io.proteus.server.Extractors.class, StatementParameterType.STRING), + FloatType("Integer $L = $T.floatValue(exchange,$S)", false, StatementParameterType.LITERAL, io.proteus.server.Extractors.class, StatementParameterType.STRING), + DoubleType("Integer $L = $T.doubleValue(exchange,$S)", false, StatementParameterType.LITERAL, io.proteus.server.Extractors.class, StatementParameterType.STRING), - ValueOfType("$T $L = $T.valueOf($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.TYPE, com.wurrly.server.Extractors.class, StatementParameterType.STRING), - FromStringType("$T $L = $T.fromString($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL,StatementParameterType.TYPE, com.wurrly.server.Extractors.class, StatementParameterType.STRING), + ValueOfType("$T $L = $T.valueOf($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.TYPE, io.proteus.server.Extractors.class, StatementParameterType.STRING), + FromStringType("$T $L = $T.fromString($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL,StatementParameterType.TYPE, io.proteus.server.Extractors.class, StatementParameterType.STRING), ListValueOfType("$T<$T> $L = exchange.getQueryParameters().get($S).stream().map($T::valueOf).collect(java.util.stream.Collectors.toList())",false, java.util.List.class,StatementParameterType.RAW, StatementParameterType.LITERAL, StatementParameterType.STRING, StatementParameterType.RAW ), ListFromStringType("$T<$T> $L = exchange.getQueryParameters().get($S).stream().map($T::fromString).collect(java.util.stream.Collectors.toList())",false, java.util.List.class,StatementParameterType.RAW, StatementParameterType.LITERAL, StatementParameterType.STRING, StatementParameterType.RAW ), - HeaderValueOfType("$T $L = $T.valueOf($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.TYPE, com.wurrly.server.Extractors.Header.class, StatementParameterType.STRING), - HeaderFromStringType("$T $L = $T.fromString($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.TYPE,com.wurrly.server.Extractors.Header.class, StatementParameterType.STRING), - HeaderStringType("$T $L = $T.string(exchange,$S)", false, java.lang.String.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Header.class, StatementParameterType.STRING), + HeaderValueOfType("$T $L = $T.valueOf($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.TYPE, io.proteus.server.Extractors.Header.class, StatementParameterType.STRING), + HeaderFromStringType("$T $L = $T.fromString($T.string(exchange,$S))", false, StatementParameterType.TYPE, StatementParameterType.LITERAL, StatementParameterType.TYPE,io.proteus.server.Extractors.Header.class, StatementParameterType.STRING), + HeaderStringType("$T $L = $T.string(exchange,$S)", false, java.lang.String.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.Header.class, StatementParameterType.STRING), - OptionalHeaderValueOfType("$T<$T> $L = $T.string(exchange,$S).map($T::valueOf)", false,Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Header.Optional.class, StatementParameterType.STRING,StatementParameterType.RAW), - OptionalHeaderFromStringType("$T<$T> $L = $T.string(exchange,$S).map($T::fromString)", false, Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Header.Optional.class, StatementParameterType.STRING,StatementParameterType.RAW), - OptionalHeaderStringType("$T<$T> $L = $T.string(exchange,$S)", false, Optional.class, java.lang.String.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Header.Optional.class, StatementParameterType.STRING), + OptionalHeaderValueOfType("$T<$T> $L = $T.string(exchange,$S).map($T::valueOf)", false,Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL, io.proteus.server.Extractors.Header.Optional.class, StatementParameterType.STRING,StatementParameterType.RAW), + OptionalHeaderFromStringType("$T<$T> $L = $T.string(exchange,$S).map($T::fromString)", false, Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL, io.proteus.server.Extractors.Header.Optional.class, StatementParameterType.STRING,StatementParameterType.RAW), + OptionalHeaderStringType("$T<$T> $L = $T.string(exchange,$S)", false, Optional.class, java.lang.String.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.Header.Optional.class, StatementParameterType.STRING), OptionalListValueOfType("$T $L = java.util.Optional.ofNullable(exchange.getQueryParameters().get($S)).map(java.util.Deque::stream).map( p -> p.map($T::valueOf).collect(java.util.stream.Collectors.toList()))",false, StatementParameterType.RAW, StatementParameterType.LITERAL, StatementParameterType.STRING, StatementParameterType.RAW ), OptionalListFromStringType("$T $L = java.util.Optional.ofNullable(exchange.getQueryParameters().get($S)).map(java.util.Deque::stream).map( p -> p.map($T::fromString).collect(java.util.stream.Collectors.toList()))",false, StatementParameterType.RAW, StatementParameterType.LITERAL, StatementParameterType.STRING, StatementParameterType.RAW ), - OptionalJsonIteratorType("$T<$T> $L = $T.jsonIterator(exchange)", true, Optional.class, com.jsoniter.JsonIterator.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Optional.class), - OptionalAnyType("$T<$T> $L = $T.any(exchange)", true, Optional.class, com.jsoniter.any.Any.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Optional.class), - OptionalStringType("$T $L = $T.string(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalLongType("$T $L = $T.longValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalIntegerType("$T $L = $T.integerValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalBooleanType("$T $L = $T.booleanValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalPathType("$T<$T> $L = $T.filePath(exchange,$S)", true, Optional.class, java.nio.file.Path.class, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalFloatType("$T $L = $T.floatValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalDoubleType("$T $L = $T.doubleValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalJsonIteratorType("$T<$T> $L = $T.jsonIterator(exchange)", true, Optional.class, com.jsoniter.JsonIterator.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.Optional.class), + OptionalAnyType("$T<$T> $L = $T.any(exchange)", true, Optional.class, com.jsoniter.any.Any.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.Optional.class), + OptionalStringType("$T $L = $T.string(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalLongType("$T $L = $T.longValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalIntegerType("$T $L = $T.integerValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalBooleanType("$T $L = $T.booleanValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalPathType("$T<$T> $L = $T.filePath(exchange,$S)", true, Optional.class, java.nio.file.Path.class, StatementParameterType.LITERAL,io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalFloatType("$T $L = $T.floatValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalDoubleType("$T $L = $T.doubleValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalDateType("$T<$T> $L = $T.date(exchange,$S)", false, Optional.class, java.util.Date.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalDateType("$T<$T> $L = $T.date(exchange,$S)", false, Optional.class, java.util.Date.class, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING), - OptionalModelType("java.util.Optional<$L> $L = $T.model(exchange,$L)", true, StatementParameterType.LITERAL, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.LITERAL), + OptionalModelType("java.util.Optional<$L> $L = $T.model(exchange,$L)", true, StatementParameterType.LITERAL, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.LITERAL), - OptionalValueOfType("$T<$T> $L = $T.string(exchange,$S).map($T::valueOf)", false, Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING, StatementParameterType.RAW), - OptionalFromStringType("$T<$T> $L = $T.string(exchange,$S).map($T::fromString)", false, Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING, StatementParameterType.RAW), + OptionalValueOfType("$T<$T> $L = $T.string(exchange,$S).map($T::valueOf)", false, Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL,io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING, StatementParameterType.RAW), + OptionalFromStringType("$T<$T> $L = $T.string(exchange,$S).map($T::fromString)", false, Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.STRING, StatementParameterType.RAW), - //OptionalEnumType("$T $L = $T.enumValue(exchange,$T.class,$S)", true, StatementParameterType.TYPE, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.RAW, StatementParameterType.STRING), + //OptionalEnumType("$T $L = $T.enumValue(exchange,$T.class,$S)", true, StatementParameterType.TYPE, StatementParameterType.LITERAL, io.proteus.server.Extractors.Optional.class, StatementParameterType.RAW, StatementParameterType.STRING), ; @@ -469,18 +469,17 @@ else if (hasFromString) @Inject @Named("registeredEndpoints") protected Set registeredEndpoints; - - @Inject - @Named("registeredControllers") - protected Set> registeredControllers; + + protected Class controllerClass; + // public static void main(String[] args) // { // try // { - // RouteGenerator generator = new RouteGenerator("com.wurrly.controllers.handlers","RouteHandlers"); + // RouteGenerator generator = new RouteGenerator("io.proteus.controllers.handlers","RouteHandlers"); // - // Set> classes = getApiClasses("com.wurrly.controllers",null); + // Set> classes = getApiClasses("io.proteus.controllers",null); // // generator.generateRoutes(classes); // @@ -499,11 +498,11 @@ else if (hasFromString) // // } - public HandlerGenerator(String packageName, String className) + public HandlerGenerator(String packageName, Class controllerClass) { this.packageName = packageName; - this.className = className; - + this.controllerClass = controllerClass; + this.className = controllerClass.getSimpleName() + "RouteSupplier"; } public Class> compileClass() @@ -529,24 +528,22 @@ protected void generateRoutes() TypeSpec.Builder typeBuilder = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC).addSuperinterface(ParameterizedTypeName.get(Supplier.class, RoutingHandler.class)); - ClassName extractorClass = ClassName.get("com.wurrly.server", "Extractors"); + ClassName extractorClass = ClassName.get("io.proteus.server", "Extractors"); ClassName injectClass = ClassName.get("com.google.inject", "Inject"); MethodSpec.Builder constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addAnnotation(injectClass); - for (Class clazz : this.registeredControllers) - { - String className = clazz.getSimpleName().toLowerCase() + "Controller"; + String className = this.controllerClass.getSimpleName().toLowerCase() + "Controller"; - typeBuilder.addField(clazz, className, Modifier.PROTECTED); + typeBuilder.addField(this.controllerClass, className, Modifier.PROTECTED); - constructor.addParameter(clazz, className); + constructor.addParameter(this.controllerClass, className); constructor.addStatement("this.$N = $N", className, className); - addClassMethodHandlers(typeBuilder, clazz); - } + addClassMethodHandlers(typeBuilder, this.controllerClass); + typeBuilder.addMethod(constructor.build()); @@ -930,7 +927,7 @@ else if (t.equals(TypeHandler.OptionalListFromStringType) || t.equals(TypeHandle } else { - functionBlockBuilder.add("$T $L = $L.$L($L);", m.getReturnType(), "response", controllerName, m.getName(), controllerMethodArgs); + functionBlockBuilder.add("$T $L = $L.$L($L);", m.getGenericReturnType(), "response", controllerName, m.getName(), controllerMethodArgs); } methodBuilder.addCode(functionBlockBuilder.build()); diff --git a/src/main/java/com/wurrly/server/handlers/ServerDefaultResponseListener.java b/src/main/java/io/proteus/server/handlers/ServerDefaultResponseListener.java similarity index 95% rename from src/main/java/com/wurrly/server/handlers/ServerDefaultResponseListener.java rename to src/main/java/io/proteus/server/handlers/ServerDefaultResponseListener.java index 538af97..a78f051 100644 --- a/src/main/java/com/wurrly/server/handlers/ServerDefaultResponseListener.java +++ b/src/main/java/io/proteus/server/handlers/ServerDefaultResponseListener.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.handlers; +package io.proteus.server.handlers; import java.nio.ByteBuffer; import java.util.HashMap; @@ -15,9 +15,9 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.jsoniter.output.JsonStream; -import com.wurrly.server.MimeTypes; -import com.wurrly.server.predicates.ServerPredicates; +import io.proteus.server.MimeTypes; +import io.proteus.server.predicates.ServerPredicates; import io.undertow.server.DefaultResponseListener; import io.undertow.server.HttpServerExchange; import io.undertow.util.Headers; @@ -33,6 +33,7 @@ public class ServerDefaultResponseListener implements DefaultResponseListener @Inject protected XmlMapper xmlMapper; + @Override public boolean handleDefaultResponse(HttpServerExchange exchange) diff --git a/src/main/java/io/proteus/server/handlers/ServerFallbackHandler.java b/src/main/java/io/proteus/server/handlers/ServerFallbackHandler.java new file mode 100644 index 0000000..1ef9a36 --- /dev/null +++ b/src/main/java/io/proteus/server/handlers/ServerFallbackHandler.java @@ -0,0 +1,25 @@ +/** + * + */ +package io.proteus.server.handlers; + +import io.undertow.server.HttpHandler; +import io.undertow.server.HttpServerExchange; +import io.undertow.util.Headers; + +/** + * @author jbauer + * + */ +public class ServerFallbackHandler implements HttpHandler +{ + + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception + { + exchange.setStatusCode(404); + exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); + exchange.getResponseSender().send("Page Not Found!!"); + + } +} diff --git a/src/main/java/com/wurrly/server/handlers/benchmark/BenchmarkHandlers.java b/src/main/java/io/proteus/server/handlers/benchmark/BenchmarkHandlers.java similarity index 98% rename from src/main/java/com/wurrly/server/handlers/benchmark/BenchmarkHandlers.java rename to src/main/java/io/proteus/server/handlers/benchmark/BenchmarkHandlers.java index ede4c7d..4022404 100644 --- a/src/main/java/com/wurrly/server/handlers/benchmark/BenchmarkHandlers.java +++ b/src/main/java/io/proteus/server/handlers/benchmark/BenchmarkHandlers.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.handlers.benchmark; +package io.proteus.server.handlers.benchmark; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; @@ -22,9 +22,9 @@ import com.google.common.io.Files; import com.j256.simplemagic.ContentType; import com.jsoniter.output.JsonStream; -import com.wurrly.server.ServerResponse; -import com.wurrly.server.handlers.HandlerGenerator.StatementParameterType; +import io.proteus.server.ServerResponse; +import io.proteus.server.handlers.HandlerGenerator.StatementParameterType; import io.undertow.attribute.ExchangeAttributes; import io.undertow.predicate.Predicates; import io.undertow.server.HttpHandler; diff --git a/src/main/java/com/wurrly/server/predicates/MaxRequestContentLengthPredicate.java b/src/main/java/io/proteus/server/predicates/MaxRequestContentLengthPredicate.java similarity index 97% rename from src/main/java/com/wurrly/server/predicates/MaxRequestContentLengthPredicate.java rename to src/main/java/io/proteus/server/predicates/MaxRequestContentLengthPredicate.java index b3a1245..a522908 100644 --- a/src/main/java/com/wurrly/server/predicates/MaxRequestContentLengthPredicate.java +++ b/src/main/java/io/proteus/server/predicates/MaxRequestContentLengthPredicate.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.predicates; +package io.proteus.server.predicates; import java.util.Collections; import java.util.Map; diff --git a/src/main/java/com/wurrly/server/predicates/ServerPredicates.java b/src/main/java/io/proteus/server/predicates/ServerPredicates.java similarity index 96% rename from src/main/java/com/wurrly/server/predicates/ServerPredicates.java rename to src/main/java/io/proteus/server/predicates/ServerPredicates.java index 7156223..12f17fc 100644 --- a/src/main/java/com/wurrly/server/predicates/ServerPredicates.java +++ b/src/main/java/io/proteus/server/predicates/ServerPredicates.java @@ -1,12 +1,11 @@ /** * */ -package com.wurrly.server.predicates; +package io.proteus.server.predicates; import java.util.Collections; -import com.wurrly.server.MimeTypes; - +import io.proteus.server.MimeTypes; import io.undertow.attribute.ExchangeAttributes; import io.undertow.predicate.Predicate; import io.undertow.predicate.Predicates; diff --git a/src/main/java/com/wurrly/server/swagger/AnnotationHelper.java b/src/main/java/io/proteus/server/swagger/AnnotationHelper.java similarity index 98% rename from src/main/java/com/wurrly/server/swagger/AnnotationHelper.java rename to src/main/java/io/proteus/server/swagger/AnnotationHelper.java index b444d60..a09b0d0 100644 --- a/src/main/java/com/wurrly/server/swagger/AnnotationHelper.java +++ b/src/main/java/io/proteus/server/swagger/AnnotationHelper.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.swagger; +package io.proteus.server.swagger; import java.lang.annotation.Annotation; import java.lang.reflect.Parameter; diff --git a/src/main/java/com/wurrly/server/swagger/Reader.java b/src/main/java/io/proteus/server/swagger/Reader.java similarity index 99% rename from src/main/java/com/wurrly/server/swagger/Reader.java rename to src/main/java/io/proteus/server/swagger/Reader.java index 6d08a4f..d1fcab5 100644 --- a/src/main/java/com/wurrly/server/swagger/Reader.java +++ b/src/main/java/io/proteus/server/swagger/Reader.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.swagger; +package io.proteus.server.swagger; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -37,8 +37,8 @@ import com.fasterxml.jackson.databind.introspect.AnnotatedParameter; import com.fasterxml.jackson.databind.type.SimpleType; import com.fasterxml.jackson.databind.type.TypeFactory; -import com.wurrly.server.ServerRequest; +import io.proteus.server.ServerRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; diff --git a/src/main/java/com/wurrly/server/swagger/ServerParameterExtension.java b/src/main/java/io/proteus/server/swagger/ServerParameterExtension.java similarity index 97% rename from src/main/java/com/wurrly/server/swagger/ServerParameterExtension.java rename to src/main/java/io/proteus/server/swagger/ServerParameterExtension.java index 10c1520..2bd383b 100644 --- a/src/main/java/com/wurrly/server/swagger/ServerParameterExtension.java +++ b/src/main/java/io/proteus/server/swagger/ServerParameterExtension.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.swagger; +package io.proteus.server.swagger; import java.lang.annotation.Annotation; import java.lang.reflect.Type; diff --git a/src/main/java/com/wurrly/services/AssetsService.java b/src/main/java/io/proteus/services/AssetsService.java similarity index 95% rename from src/main/java/com/wurrly/services/AssetsService.java rename to src/main/java/io/proteus/services/AssetsService.java index b6e5800..c87f4c5 100644 --- a/src/main/java/com/wurrly/services/AssetsService.java +++ b/src/main/java/io/proteus/services/AssetsService.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.services; +package io.proteus.services; import java.nio.file.Paths; import java.util.Set; @@ -12,8 +12,8 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import com.typesafe.config.Config; -import com.wurrly.server.endpoints.EndpointInfo; +import io.proteus.server.endpoints.EndpointInfo; import io.undertow.predicate.TruePredicate; import io.undertow.server.RoutingHandler; import io.undertow.server.handlers.resource.FileResourceManager; diff --git a/src/main/java/com/wurrly/services/BaseService.java b/src/main/java/io/proteus/services/BaseService.java similarity index 93% rename from src/main/java/com/wurrly/services/BaseService.java rename to src/main/java/io/proteus/services/BaseService.java index 192985f..149bc44 100644 --- a/src/main/java/com/wurrly/services/BaseService.java +++ b/src/main/java/io/proteus/services/BaseService.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.services; +package io.proteus.services; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,7 +9,8 @@ import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import com.typesafe.config.Config; -import com.wurrly.modules.ConfigModule; + +import io.proteus.modules.ConfigModule; /** * @author jbauer diff --git a/src/main/java/com/wurrly/services/SwaggerService.java b/src/main/java/io/proteus/services/SwaggerService.java similarity index 96% rename from src/main/java/com/wurrly/services/SwaggerService.java rename to src/main/java/io/proteus/services/SwaggerService.java index dbef59b..5a44a83 100644 --- a/src/main/java/com/wurrly/services/SwaggerService.java +++ b/src/main/java/io/proteus/services/SwaggerService.java @@ -1,5 +1,5 @@ -package com.wurrly.services; +package io.proteus.services; import java.io.StringWriter; import java.io.Writer; @@ -20,11 +20,11 @@ import com.mitchellbosecke.pebble.PebbleEngine; import com.mitchellbosecke.pebble.template.PebbleTemplate; import com.typesafe.config.Config; -import com.wurrly.server.MimeTypes; -import com.wurrly.server.endpoints.EndpointInfo; -import com.wurrly.server.swagger.ServerParameterExtension; -import com.wurrly.utilities.JsonMapper; +import io.proteus.server.MimeTypes; +import io.proteus.server.endpoints.EndpointInfo; +import io.proteus.server.swagger.ServerParameterExtension; +import io.proteus.utilities.JsonMapper; import io.swagger.jaxrs.ext.SwaggerExtension; import io.swagger.jaxrs.ext.SwaggerExtensions; import io.swagger.models.Info; @@ -46,7 +46,7 @@ public class SwaggerService extends BaseService implements Supplier this.reader.read(c)); diff --git a/src/main/java/com/wurrly/tests/JsonViewTest.java b/src/main/java/io/proteus/tests/JsonViewTest.java similarity index 98% rename from src/main/java/com/wurrly/tests/JsonViewTest.java rename to src/main/java/io/proteus/tests/JsonViewTest.java index d2cf723..d992da6 100644 --- a/src/main/java/com/wurrly/tests/JsonViewTest.java +++ b/src/main/java/io/proteus/tests/JsonViewTest.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.tests; +package io.proteus.tests; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -22,7 +22,8 @@ import com.jsoniter.spi.Encoder; import com.jsoniter.spi.JsoniterSpi; import com.jsoniter.spi.TypeLiteral; -import com.wurrly.tests.JsonViewTest.Views; + +import io.proteus.tests.JsonViewTest.Views; /** * @author jbauer diff --git a/src/main/java/com/wurrly/tests/TestInvoker.java b/src/main/java/io/proteus/tests/TestInvoker.java similarity index 98% rename from src/main/java/com/wurrly/tests/TestInvoker.java rename to src/main/java/io/proteus/tests/TestInvoker.java index aaf2e7d..18f5625 100644 --- a/src/main/java/com/wurrly/tests/TestInvoker.java +++ b/src/main/java/io/proteus/tests/TestInvoker.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.tests; +package io.proteus.tests; import static java.lang.invoke.MethodHandles.lookup; @@ -22,8 +22,9 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Throwables; -import com.wurrly.controllers.Users; -import com.wurrly.server.ServerRequest; + +import io.proteus.controllers.Users; +import io.proteus.server.ServerRequest; /** * @author jbauer diff --git a/src/main/java/com/wurrly/tests/TestJsoniterViews.java b/src/main/java/io/proteus/tests/TestJsoniterViews.java similarity index 98% rename from src/main/java/com/wurrly/tests/TestJsoniterViews.java rename to src/main/java/io/proteus/tests/TestJsoniterViews.java index 041ed98..fc504da 100644 --- a/src/main/java/com/wurrly/tests/TestJsoniterViews.java +++ b/src/main/java/io/proteus/tests/TestJsoniterViews.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.tests; +package io.proteus.tests; import java.io.IOException; @@ -17,7 +17,8 @@ import com.jsoniter.spi.EmptyExtension; import com.jsoniter.spi.Encoder; import com.jsoniter.spi.JsoniterSpi; -import com.wurrly.models.User; + +import io.proteus.models.User; /** * @author jbauer diff --git a/src/main/java/com/wurrly/tests/TestTypes.java b/src/main/java/io/proteus/tests/TestTypes.java similarity index 97% rename from src/main/java/com/wurrly/tests/TestTypes.java rename to src/main/java/io/proteus/tests/TestTypes.java index c43a941..87b2143 100644 --- a/src/main/java/com/wurrly/tests/TestTypes.java +++ b/src/main/java/io/proteus/tests/TestTypes.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.tests; +package io.proteus.tests; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -10,7 +10,7 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; -import com.wurrly.server.ServerResponse; +import io.proteus.server.ServerResponse; /** * @author jbauer diff --git a/src/main/java/com/wurrly/utilities/ChunkedStream.java b/src/main/java/io/proteus/utilities/ChunkedStream.java similarity index 99% rename from src/main/java/com/wurrly/utilities/ChunkedStream.java rename to src/main/java/io/proteus/utilities/ChunkedStream.java index 0340112..73fdad8 100644 --- a/src/main/java/com/wurrly/utilities/ChunkedStream.java +++ b/src/main/java/io/proteus/utilities/ChunkedStream.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package com.wurrly.utilities; +package io.proteus.utilities; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/src/main/java/com/wurrly/utilities/JsonMapper.java b/src/main/java/io/proteus/utilities/JsonMapper.java similarity index 99% rename from src/main/java/com/wurrly/utilities/JsonMapper.java rename to src/main/java/io/proteus/utilities/JsonMapper.java index bde7522..4d11c6e 100644 --- a/src/main/java/com/wurrly/utilities/JsonMapper.java +++ b/src/main/java/io/proteus/utilities/JsonMapper.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.utilities; +package io.proteus.utilities; import java.util.Collection; import java.util.HashSet; diff --git a/src/main/java/com/wurrly/utilities/ReapableQueue.java b/src/main/java/io/proteus/utilities/ReapableQueue.java similarity index 99% rename from src/main/java/com/wurrly/utilities/ReapableQueue.java rename to src/main/java/io/proteus/utilities/ReapableQueue.java index e002d25..e5cd601 100644 --- a/src/main/java/com/wurrly/utilities/ReapableQueue.java +++ b/src/main/java/io/proteus/utilities/ReapableQueue.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.utilities; +package io.proteus.utilities; import java.util.concurrent.atomic.*; diff --git a/src/main/java/com/wurrly/utilities/SecurityOps.java b/src/main/java/io/proteus/utilities/SecurityOps.java similarity index 98% rename from src/main/java/com/wurrly/utilities/SecurityOps.java rename to src/main/java/io/proteus/utilities/SecurityOps.java index a60c4fe..c6fac29 100644 --- a/src/main/java/com/wurrly/utilities/SecurityOps.java +++ b/src/main/java/io/proteus/utilities/SecurityOps.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.utilities; +package io.proteus.utilities; import java.io.InputStream; import java.nio.file.Files; diff --git a/src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerExtension b/src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerExtension deleted file mode 100644 index 8d4cebd..0000000 --- a/src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerExtension +++ /dev/null @@ -1 +0,0 @@ -com.wurrly.server.swagger.ServerExtension \ No newline at end of file diff --git a/src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerModelResolver b/src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerModelResolver deleted file mode 100644 index cfbb108..0000000 --- a/src/main/resources/META-INF/empty/com.wurrly.server.swagger.ServerModelResolver +++ /dev/null @@ -1 +0,0 @@ -com.wurrly.server.swagger.ServerModelResolver \ No newline at end of file