From ba639d7a92b76acf9f3b4624449eb5499f326fc8 Mon Sep 17 00:00:00 2001 From: joshua bauer Date: Wed, 12 Apr 2017 15:22:14 -0700 Subject: [PATCH] Cleanup modules. --- conf/logback.xml | 3 +- src/main/java/com/wurrly/Application.java | 13 ++++-- .../java/com/wurrly/modules/ConfigModule.java | 40 ++++--------------- .../com/wurrly/modules/RoutingModule.java | 5 ++- .../java/com/wurrly/server/Extractors.java | 2 +- .../java/com/wurrly/server/ServerRequest.java | 2 + .../com/wurrly/server/ServerResponse.java | 1 + .../ServerDefaultResponseListener.java | 2 +- .../MaxRequestContentLengthPredicate.java | 2 +- .../{ => predicates}/ServerPredicates.java | 4 +- .../com/wurrly/services/AssetsService.java | 8 +++- 11 files changed, 36 insertions(+), 46 deletions(-) rename src/main/java/com/wurrly/server/{handlers => }/predicates/MaxRequestContentLengthPredicate.java (97%) rename src/main/java/com/wurrly/server/{ => predicates}/ServerPredicates.java (93%) diff --git a/conf/logback.xml b/conf/logback.xml index 3e04985..2c628ce 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -20,7 +20,8 @@ - + + diff --git a/src/main/java/com/wurrly/Application.java b/src/main/java/com/wurrly/Application.java index 0d9247f..5b5405e 100644 --- a/src/main/java/com/wurrly/Application.java +++ b/src/main/java/com/wurrly/Application.java @@ -21,6 +21,11 @@ import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.name.Named; +import com.jsoniter.DecodingMode; +import com.jsoniter.JsonIterator; +import com.jsoniter.annotation.JsoniterAnnotationSupport; +import com.jsoniter.output.EncodingMode; +import com.jsoniter.output.JsonStream; import com.typesafe.config.Config; import com.wurrly.controllers.Users; import com.wurrly.modules.ConfigModule; @@ -47,9 +52,7 @@ public class Application private static Logger log = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Application.class.getCanonicalName()); - - - static final String CHARSET = "UTF-8"; + private static final String CHARSET = "UTF-8"; @@ -211,7 +214,9 @@ public static void main(String[] args) try { - + JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH); + JsonStream.setMode(EncodingMode.DYNAMIC_MODE); + JsoniterAnnotationSupport.enable(); Application app = new Application(); diff --git a/src/main/java/com/wurrly/modules/ConfigModule.java b/src/main/java/com/wurrly/modules/ConfigModule.java index 1bcacf3..052201b 100644 --- a/src/main/java/com/wurrly/modules/ConfigModule.java +++ b/src/main/java/com/wurrly/modules/ConfigModule.java @@ -57,32 +57,10 @@ public ConfigModule(String configFile) @Override protected void configure() - { - - if(this.configFile != null ) - { - this.bindConfig(fileConfig(configFile)); - } - - JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH); - JsonStream.setMode(EncodingMode.DYNAMIC_MODE); - JsoniterAnnotationSupport.enable(); - - install(new RoutingModule(this.config)); - - - -// try -// { -// Class defaultResponseListener = (Class) Class.forName(config.getString("application.defaultResponseListener")); -// -// this.bind(DefaultResponseListener.class).to(defaultResponseListener).in(Singleton.class); -// -// } catch (Exception e) -// { -// log.error(e.getMessage(),e); -// } - + { + this.bindConfig(fileConfig(configFile)); + + install(new RoutingModule(this.config)); } @@ -92,7 +70,7 @@ public void bindFileConfig(String fileName) } @SuppressWarnings("unchecked") - public void bindConfig(final Config config) + private void bindConfig(final Config config) { traverse(this.binder(), "", config.root()); @@ -120,15 +98,13 @@ public void bindConfig(final Config config) this.config = ConfigFactory.load(config); - this.binder().bind(Config.class).toInstance( config ); - - log.info("Config:\n" + config); + this.binder().bind(Config.class).toInstance( config ); } - public static void traverse(final Binder binder, final String p, final ConfigObject root) + private static void traverse(final Binder binder, final String p, final ConfigObject root) { root.forEach((n, v) -> { if (v instanceof ConfigObject) @@ -143,7 +119,7 @@ public static void traverse(final Binder binder, final String p, final ConfigObj } - public static Config fileConfig(final String fname) + private static Config fileConfig(final String fname) { File dir = new File(System.getProperty("user.dir")); File froot = new File(dir, fname); diff --git a/src/main/java/com/wurrly/modules/RoutingModule.java b/src/main/java/com/wurrly/modules/RoutingModule.java index 4cc7b3c..7465028 100644 --- a/src/main/java/com/wurrly/modules/RoutingModule.java +++ b/src/main/java/com/wurrly/modules/RoutingModule.java @@ -59,8 +59,6 @@ protected void configure() RoutingHandler router = new RoutingHandler() .setFallbackHandler(BaseHandlers::notFoundHandler); - this.bind(XmlMapper.class).toInstance(new XmlMapper()); - this.bind(RoutingHandler.class).toInstance(router); @@ -81,6 +79,9 @@ protected void configure() this.bind(new TypeLiteral>>() {}).annotatedWith(Names.named("registeredControllers")).toInstance(registeredControllers); this.bind(new TypeLiteral>() {}).annotatedWith(Names.named("registeredEndpoints")).toInstance(registeredEndpoints); + + this.bind(XmlMapper.class).toInstance(new XmlMapper()); + } diff --git a/src/main/java/com/wurrly/server/Extractors.java b/src/main/java/com/wurrly/server/Extractors.java index 5aae615..04ec704 100644 --- a/src/main/java/com/wurrly/server/Extractors.java +++ b/src/main/java/com/wurrly/server/Extractors.java @@ -25,7 +25,7 @@ import com.jsoniter.JsonIterator; import com.jsoniter.any.Any; import com.jsoniter.spi.TypeLiteral; -import com.wurrly.server.handlers.predicates.MaxRequestContentLengthPredicate; +import com.wurrly.server.predicates.MaxRequestContentLengthPredicate; import io.undertow.attribute.ExchangeAttributes; import io.undertow.predicate.Predicate; diff --git a/src/main/java/com/wurrly/server/ServerRequest.java b/src/main/java/com/wurrly/server/ServerRequest.java index 0a461c7..1e0f790 100644 --- a/src/main/java/com/wurrly/server/ServerRequest.java +++ b/src/main/java/com/wurrly/server/ServerRequest.java @@ -16,6 +16,8 @@ import org.slf4j.LoggerFactory; import org.xnio.channels.StreamSourceChannel; +import com.wurrly.server.predicates.ServerPredicates; + import io.undertow.connector.PooledByteBuffer; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.form.FormData; diff --git a/src/main/java/com/wurrly/server/ServerResponse.java b/src/main/java/com/wurrly/server/ServerResponse.java index d8334ac..6d849d8 100644 --- a/src/main/java/com/wurrly/server/ServerResponse.java +++ b/src/main/java/com/wurrly/server/ServerResponse.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.jsoniter.any.Any; import com.jsoniter.output.JsonStream; +import com.wurrly.server.predicates.ServerPredicates; import io.undertow.attribute.ExchangeAttributes; import io.undertow.io.IoCallback; diff --git a/src/main/java/com/wurrly/server/handlers/ServerDefaultResponseListener.java b/src/main/java/com/wurrly/server/handlers/ServerDefaultResponseListener.java index 56e35a9..538af97 100644 --- a/src/main/java/com/wurrly/server/handlers/ServerDefaultResponseListener.java +++ b/src/main/java/com/wurrly/server/handlers/ServerDefaultResponseListener.java @@ -16,7 +16,7 @@ import com.google.inject.Singleton; import com.jsoniter.output.JsonStream; import com.wurrly.server.MimeTypes; -import com.wurrly.server.ServerPredicates; +import com.wurrly.server.predicates.ServerPredicates; import io.undertow.server.DefaultResponseListener; import io.undertow.server.HttpServerExchange; diff --git a/src/main/java/com/wurrly/server/handlers/predicates/MaxRequestContentLengthPredicate.java b/src/main/java/com/wurrly/server/predicates/MaxRequestContentLengthPredicate.java similarity index 97% rename from src/main/java/com/wurrly/server/handlers/predicates/MaxRequestContentLengthPredicate.java rename to src/main/java/com/wurrly/server/predicates/MaxRequestContentLengthPredicate.java index 2234a60..b3a1245 100644 --- a/src/main/java/com/wurrly/server/handlers/predicates/MaxRequestContentLengthPredicate.java +++ b/src/main/java/com/wurrly/server/predicates/MaxRequestContentLengthPredicate.java @@ -1,7 +1,7 @@ /** * */ -package com.wurrly.server.handlers.predicates; +package com.wurrly.server.predicates; import java.util.Collections; import java.util.Map; diff --git a/src/main/java/com/wurrly/server/ServerPredicates.java b/src/main/java/com/wurrly/server/predicates/ServerPredicates.java similarity index 93% rename from src/main/java/com/wurrly/server/ServerPredicates.java rename to src/main/java/com/wurrly/server/predicates/ServerPredicates.java index 53b482d..eb4e804 100644 --- a/src/main/java/com/wurrly/server/ServerPredicates.java +++ b/src/main/java/com/wurrly/server/predicates/ServerPredicates.java @@ -1,11 +1,11 @@ /** * */ -package com.wurrly.server; +package com.wurrly.server.predicates; import java.util.Collections; -import com.wurrly.server.handlers.predicates.MaxRequestContentLengthPredicate; +import com.wurrly.server.MimeTypes; import io.undertow.attribute.ExchangeAttributes; import io.undertow.predicate.Predicate; diff --git a/src/main/java/com/wurrly/services/AssetsService.java b/src/main/java/com/wurrly/services/AssetsService.java index 4f84742..b6e5800 100644 --- a/src/main/java/com/wurrly/services/AssetsService.java +++ b/src/main/java/com/wurrly/services/AssetsService.java @@ -6,6 +6,9 @@ import java.nio.file.Paths; import java.util.Set; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.inject.Inject; import com.google.inject.name.Named; import com.typesafe.config.Config; @@ -23,6 +26,7 @@ */ public class AssetsService extends BaseService { + private static Logger log = LoggerFactory.getLogger(AssetsService.class.getCanonicalName()); @Inject @Named("registeredEndpoints") @@ -34,12 +38,12 @@ public class AssetsService extends BaseService @Inject @Named("assets") protected Config serviceConfig; + /** * */ public AssetsService() - { - // TODO Auto-generated constructor stub + { }