diff --git a/README.md b/README.md index 54cfde6..f790623 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ The current version of the project is **0.2**. | dropwizard-spring | Dropwizard | Spring | |:------------------:|:------------:|:-------------:| +| master (0.3.2) | 0.7.0-rc1 | 3.1.4.RELEASE | | master (0.3.1) | 0.6.2 | 3.1.4.RELEASE | | 0.2 | 0.6.0 | 3.1.3.RELEASE | | 0.1 | 0.5.1 | 3.1.1.RELEASE | diff --git a/pom.xml b/pom.xml index feef020..341bf7c 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ - 0.6.2 + 0.7.0-rc1 3.1.4.RELEASE UTF-8 @@ -66,7 +66,7 @@ - com.yammer.dropwizard + io.dropwizard dropwizard-core ${dropwizard.version} true diff --git a/src/main/java/com/github/nhuray/dropwizard/spring/SpringBundle.java b/src/main/java/com/github/nhuray/dropwizard/spring/SpringBundle.java index 77f7280..3eae55a 100644 --- a/src/main/java/com/github/nhuray/dropwizard/spring/SpringBundle.java +++ b/src/main/java/com/github/nhuray/dropwizard/spring/SpringBundle.java @@ -1,17 +1,17 @@ package com.github.nhuray.dropwizard.spring; +import com.codahale.metrics.health.HealthCheck; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.nhuray.dropwizard.spring.config.ConfigurationPlaceholderConfigurer; import com.google.common.base.Preconditions; import com.sun.jersey.spi.inject.InjectableProvider; -import com.yammer.dropwizard.ConfiguredBundle; -import com.yammer.dropwizard.config.Bootstrap; -import com.yammer.dropwizard.config.Configuration; -import com.yammer.dropwizard.config.Environment; -import com.yammer.dropwizard.lifecycle.Managed; -import com.yammer.dropwizard.lifecycle.ServerLifecycleListener; -import com.yammer.dropwizard.tasks.Task; -import com.yammer.metrics.core.HealthCheck; +import io.dropwizard.ConfiguredBundle; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.Configuration; +import io.dropwizard.setup.Environment; +import io.dropwizard.lifecycle.Managed; +import io.dropwizard.lifecycle.ServerLifecycleListener; +import io.dropwizard.servlets.tasks.Task; import org.eclipse.jetty.util.component.LifeCycle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -112,7 +112,7 @@ public void run(T configuration, Environment environment) throws Exception { registerInjectableProviders(environment, context); registerProviders(environment, context); registerResources(environment, context); - environment.manage(new SpringContextManaged(context)); + environment.lifecycle().manage(new SpringContextManaged(context)); } @@ -151,7 +151,7 @@ private void registerManaged(Environment environment, ConfigurableApplicationCon for (String beanName : beansOfType.keySet()) { // Add managed to Dropwizard environment Managed managed = beansOfType.get(beanName); - environment.manage(managed); + environment.lifecycle().manage(managed); LOG.info("Registering managed: " + managed.getClass().getName()); } } @@ -169,7 +169,7 @@ private void registerLifecycle(Environment environment, ConfigurableApplicationC // Add lifeCycle to Dropwizard environment if (!beanName.equals(ENVIRONMENT_BEAN_NAME)) { LifeCycle lifeCycle = beansOfType.get(beanName); - environment.manage(lifeCycle); + environment.lifecycle().manage(lifeCycle); LOG.info("Registering lifeCycle: " + lifeCycle.getClass().getName()); } } @@ -188,7 +188,7 @@ private void registerServerLifecycleListeners(Environment environment, Configura // Add serverLifecycleListener to Dropwizard environment if (!beanName.equals(ENVIRONMENT_BEAN_NAME)) { ServerLifecycleListener serverLifecycleListener = beansOfType.get(beanName); - environment.addServerLifecycleListener(serverLifecycleListener); + environment.servlets().addServletListeners(serverLifecycleListener); LOG.info("Registering serverLifecycleListener: " + serverLifecycleListener.getClass().getName()); } } @@ -206,7 +206,7 @@ private void registerTasks(Environment environment, ConfigurableApplicationConte for (String beanName : beansOfType.keySet()) { // Add task to Dropwizard environment Task task = beansOfType.get(beanName); - environment.addTask(task); + environment.admin().addTask(task); LOG.info("Registering task: " + task.getClass().getName()); } } @@ -223,7 +223,7 @@ private void registerHealthChecks(Environment environment, ConfigurableApplicati for (String beanName : beansOfType.keySet()) { // Add healthCheck to Dropwizard environment HealthCheck healthCheck = beansOfType.get(beanName); - environment.addHealthCheck(healthCheck); + environment.healthChecks().register(beanName, healthCheck); LOG.info("Registering healthCheck: " + healthCheck.getClass().getName()); } } @@ -240,7 +240,7 @@ private void registerInjectableProviders(Environment environment, ConfigurableAp for (String beanName : beansOfType.keySet()) { // Add injectableProvider to Dropwizard environment InjectableProvider injectableProvider = beansOfType.get(beanName); - environment.addProvider(injectableProvider); + environment.jersey().register(injectableProvider); LOG.info("Registering injectable provider: " + injectableProvider.getClass().getName()); } } @@ -256,7 +256,7 @@ private void registerProviders(Environment environment, ConfigurableApplicationC for (String beanName : beansWithAnnotation.keySet()) { // Add injectableProvider to Dropwizard environment Object provider = beansWithAnnotation.get(beanName); - environment.addProvider(provider); + environment.jersey().register(provider); LOG.info("Registering provider : " + provider.getClass().getName()); } } @@ -273,7 +273,7 @@ private void registerResources(Environment environment, ConfigurableApplicationC for (String beanName : beansWithAnnotation.keySet()) { // Add injectableProvider to Dropwizard environment Object resource = beansWithAnnotation.get(beanName); - environment.addResource(resource); + environment.jersey().register(resource); LOG.info("Registering resource : " + resource.getClass().getName()); } } @@ -312,8 +312,8 @@ private void registerEnvironment(Environment environment, ConfigurableApplicatio */ private void registerPlaceholder(Environment environment, T configuration, ConfigurableApplicationContext context) { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); - final ObjectMapper objectMapper = environment.getObjectMapperFactory().build(); - placeholderConfigurer.setObjectMapper(objectMapper); + final ObjectMapper objectMapper = environment.getObjectMapper(); + placeholderConfigurer.setObjectMapper(objectMapper); placeholderConfigurer.setConfiguration(configuration); beanFactory.registerSingleton(PLACEHOLDER_BEAN_NAME, placeholderConfigurer); beanFactory.registerSingleton(OBJECT_MAPPER_BEAN_NAME, objectMapper); diff --git a/src/main/java/com/github/nhuray/dropwizard/spring/SpringContextManaged.java b/src/main/java/com/github/nhuray/dropwizard/spring/SpringContextManaged.java index 97336a7..d4b4b24 100644 --- a/src/main/java/com/github/nhuray/dropwizard/spring/SpringContextManaged.java +++ b/src/main/java/com/github/nhuray/dropwizard/spring/SpringContextManaged.java @@ -1,8 +1,9 @@ package com.github.nhuray.dropwizard.spring; +import io.dropwizard.lifecycle.Managed; import org.springframework.context.ConfigurableApplicationContext; -import com.yammer.dropwizard.lifecycle.Managed; +import io.dropwizard.lifecycle.Managed; public class SpringContextManaged implements Managed { private final ConfigurableApplicationContext context; diff --git a/src/main/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurer.java b/src/main/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurer.java index c259765..604428a 100644 --- a/src/main/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurer.java +++ b/src/main/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurer.java @@ -1,7 +1,7 @@ package com.github.nhuray.dropwizard.spring.config; import com.fasterxml.jackson.databind.ObjectMapper; -import com.yammer.dropwizard.config.Configuration; +import io.dropwizard.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; diff --git a/src/test/java/com/github/nhuray/dropwizard/spring/SpringBundleTest.java b/src/test/java/com/github/nhuray/dropwizard/spring/SpringBundleTest.java index 395181d..a198b15 100644 --- a/src/test/java/com/github/nhuray/dropwizard/spring/SpringBundleTest.java +++ b/src/test/java/com/github/nhuray/dropwizard/spring/SpringBundleTest.java @@ -1,12 +1,18 @@ package com.github.nhuray.dropwizard.spring; +import com.codahale.metrics.health.HealthCheckRegistry; +import com.codahale.metrics.servlets.HealthCheckServlet; import com.fasterxml.jackson.databind.ObjectMapper; -import com.yammer.dropwizard.config.Configuration; -import com.yammer.dropwizard.config.Environment; -import com.yammer.dropwizard.json.ObjectMapperFactory; -import com.yammer.dropwizard.lifecycle.ServerLifecycleListener; -import com.yammer.dropwizard.tasks.Task; -import com.yammer.metrics.core.HealthCheck; +import io.dropwizard.Configuration; +import io.dropwizard.jackson.Jackson; +import io.dropwizard.jersey.setup.JerseyEnvironment; +import io.dropwizard.jetty.setup.ServletEnvironment; +import io.dropwizard.lifecycle.setup.LifecycleEnvironment; +import io.dropwizard.setup.AdminEnvironment; +import io.dropwizard.setup.Environment; +import io.dropwizard.lifecycle.ServerLifecycleListener; +import io.dropwizard.servlets.tasks.Task; +import com.codahale.metrics.health.HealthCheck; import hello.server_lifecycle_listeners.HelloServerLifecycleListener; import hello.config.HelloAppConfiguration; @@ -22,6 +28,7 @@ import org.mockito.MockitoAnnotations; import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertNotNull; @@ -35,7 +42,19 @@ public class SpringBundleTest { private Environment environment; @Mock - private ObjectMapperFactory objectMapperFactory; + private JerseyEnvironment jersey; + + @Mock + private AdminEnvironment admin; + + @Mock + private ServletEnvironment servlets; + + @Mock + private LifecycleEnvironment lifecycle ; + + @Mock + private HealthCheckRegistry healthChecks ; private HelloAppConfiguration configuration; @@ -57,8 +76,17 @@ public void setup() { configuration = new HelloAppConfiguration(); configuration.setHello(hello); - when(environment.getObjectMapperFactory()).thenReturn(objectMapperFactory); - when(objectMapperFactory.build()).thenReturn(new ObjectMapper()); + when(environment.getObjectMapper()).thenReturn(Jackson.newObjectMapper()); + + when(environment.jersey()).thenReturn(jersey); + + when(environment.admin()).thenReturn(admin); + + when(environment.servlets()).thenReturn(servlets); + + when(environment.lifecycle()).thenReturn(lifecycle); + + when(environment.healthChecks()).thenReturn(healthChecks); } @Test @@ -68,7 +96,7 @@ public void registerResources() throws Exception { // Then ArgumentCaptor resource = ArgumentCaptor.forClass(HelloResource.class); - verify(environment).addResource(resource.capture()); + verify(jersey).register(resource.capture()); assertThat(resource.getValue(), is(HelloResource.class)); } @@ -79,7 +107,10 @@ public void registerHealthChecks() throws Exception { // Then ArgumentCaptor healthCheck = ArgumentCaptor.forClass(HealthCheck.class); - verify(environment).addHealthCheck(healthCheck.capture()); + ArgumentCaptor healthCheckName = ArgumentCaptor.forClass(String.class); + verify(healthChecks).register(healthCheckName.capture(), healthCheck.capture()); + + assertThat(healthCheckName.getValue(), is("helloHealthCheck")); // is the bean name assertThat(healthCheck.getValue(), is(HelloHealthCheck.class)); } @@ -90,7 +121,7 @@ public void registerTasks() throws Exception { // Then ArgumentCaptor task = ArgumentCaptor.forClass(Task.class); - verify(environment).addTask(task.capture()); + verify(admin).addTask(task.capture()); assertThat(task.getValue(), is(HelloTask.class)); } @@ -101,7 +132,7 @@ public void registerServerLifecycleListener() throws Exception { // Then ArgumentCaptor listener = ArgumentCaptor.forClass(ServerLifecycleListener.class); - verify(environment).addServerLifecycleListener(listener.capture()); + verify(servlets).addServletListeners(listener.capture()); assertThat(listener.getValue(), is(HelloServerLifecycleListener.class)); } @@ -112,10 +143,10 @@ public void registerConfiguration() throws Exception { // Then ArgumentCaptor resource = ArgumentCaptor.forClass(HelloResource.class); - verify(environment).addResource(resource.capture()); + verify(jersey).register(resource.capture()); HelloResource r = resource.getValue(); - assertThat(r.getPort(), is(8080)); // Defaut port + assertThat(r.getPort(), is(8080)); // Default port } @Test @@ -135,7 +166,7 @@ public void wiresUpDependencies() throws Exception { // Then ArgumentCaptor resource = ArgumentCaptor.forClass(HelloResource.class); - verify(environment).addResource(resource.capture()); + verify(jersey).register(resource.capture()); HelloResource r = resource.getValue(); final HelloService helloService = r.getHelloService(); diff --git a/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurerTest.java b/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurerTest.java index 13bd666..9d0af7d 100644 --- a/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurerTest.java +++ b/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationPlaceholderConfigurerTest.java @@ -1,9 +1,10 @@ package com.github.nhuray.dropwizard.spring.config; +import ch.qos.logback.classic.Level; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; -import com.yammer.dropwizard.config.Configuration; +import io.dropwizard.Configuration; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -36,7 +37,7 @@ public void defaultPlaceholder() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerBeanDefinition("testBean", rootBeanDefinition(ConfigurationTestBean.class) - .addPropertyValue("connectorType", "${http.connectorType}") + .addPropertyValue("loggingLevel", "${logging.level.levelStr}") .getBeanDefinition()); placeholder.setObjectMapper(new ObjectMapper()); @@ -45,7 +46,7 @@ public void defaultPlaceholder() { // Then ConfigurationTestBean bean = bf.getBean(ConfigurationTestBean.class); - assertThat(bean.getConnectorType(), equalTo("blocking")); + assertThat(bean.getLoggingLevel(), equalTo(Level.INFO)); } @Test @@ -58,7 +59,7 @@ public void customPlaceholderPrefixAndSuffix() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerBeanDefinition("testBean", rootBeanDefinition(ConfigurationTestBean.class) - .addPropertyValue("connectorType", "@") + .addPropertyValue("loggingLevel", "@") .addPropertyValue("rootPath", "${key2}") .getBeanDefinition()); placeholder.setObjectMapper(new ObjectMapper()); @@ -68,7 +69,7 @@ public void customPlaceholderPrefixAndSuffix() { // Then ConfigurationTestBean bean = bf.getBean(ConfigurationTestBean.class); - assertThat(bean.getConnectorType(), is("blocking")); + assertThat(bean.getLoggingLevel(), is(Level.INFO)); assertThat(bean.getRootPath(), is("${key2}")); } @@ -99,4 +100,4 @@ private class ConfigurationWithNull extends Configuration { } -} \ No newline at end of file +} diff --git a/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationTestBean.java b/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationTestBean.java index 3d556a6..8e0789c 100644 --- a/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationTestBean.java +++ b/src/test/java/com/github/nhuray/dropwizard/spring/config/ConfigurationTestBean.java @@ -1,10 +1,14 @@ package com.github.nhuray.dropwizard.spring.config; +import ch.qos.logback.classic.Level; + public class ConfigurationTestBean { private String connectorType; private String rootPath; + private Level loggingLevel; + public String getConnectorType() { return connectorType; } @@ -20,4 +24,12 @@ public String getRootPath() { public void setRootPath(String rootPath) { this.rootPath = rootPath; } -} \ No newline at end of file + + public Level getLoggingLevel() { + return loggingLevel; + } + + public void setLoggingLevel(Level loggingLevel) { + this.loggingLevel = loggingLevel; + } +} diff --git a/src/test/java/hello/HelloApp.java b/src/test/java/hello/HelloApp.java index 321d027..2163388 100644 --- a/src/test/java/hello/HelloApp.java +++ b/src/test/java/hello/HelloApp.java @@ -3,16 +3,17 @@ import com.github.nhuray.dropwizard.spring.SpringBundle; import com.github.nhuray.dropwizard.spring.config.ConfigurationPlaceholderConfigurer; -import com.yammer.dropwizard.Service; -import com.yammer.dropwizard.config.Bootstrap; -import com.yammer.dropwizard.config.Environment; +import io.dropwizard.Application; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; import hello.config.HelloAppConfiguration; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import sun.misc.Service; -public class HelloApp extends Service { +public class HelloApp extends Application { private static final String CONFIGURATION_FILE = "src/test/resources/hello/hello.yml"; diff --git a/src/test/java/hello/config/HelloAppConfiguration.java b/src/test/java/hello/config/HelloAppConfiguration.java index a0903ce..593c1b4 100644 --- a/src/test/java/hello/config/HelloAppConfiguration.java +++ b/src/test/java/hello/config/HelloAppConfiguration.java @@ -1,7 +1,7 @@ package hello.config; import com.fasterxml.jackson.annotation.JsonProperty; -import com.yammer.dropwizard.config.Configuration; +import io.dropwizard.Configuration; public class HelloAppConfiguration extends Configuration { diff --git a/src/test/java/hello/health/HelloHealthCheck.java b/src/test/java/hello/health/HelloHealthCheck.java index b28e816..951fd66 100644 --- a/src/test/java/hello/health/HelloHealthCheck.java +++ b/src/test/java/hello/health/HelloHealthCheck.java @@ -1,13 +1,9 @@ package hello.health; -import com.yammer.metrics.core.HealthCheck; +import com.codahale.metrics.health.HealthCheck; public class HelloHealthCheck extends HealthCheck { - public HelloHealthCheck() { - super("hello-health"); - } - @Override protected Result check() throws Exception { return Result.healthy(); diff --git a/src/test/java/hello/resources/HelloResource.java b/src/test/java/hello/resources/HelloResource.java index 3f9f38d..fa0a8df 100644 --- a/src/test/java/hello/resources/HelloResource.java +++ b/src/test/java/hello/resources/HelloResource.java @@ -1,10 +1,8 @@ package hello.resources; -import com.yammer.dropwizard.config.Configuration; -import com.yammer.dropwizard.config.Environment; -import com.yammer.dropwizard.config.HttpConfiguration; -import com.yammer.dropwizard.validation.Validator; +import io.dropwizard.Configuration; +import io.dropwizard.setup.Environment; import hello.service.HelloService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -21,7 +19,7 @@ public class HelloResource { @Autowired private HelloService helloService; - @Value("${http.port}") + @Value("${server.applicationConnectors[0].port}") private Integer port; @Value("#{dw}") @@ -32,7 +30,10 @@ public class HelloResource { @GET public Response doGet() { - return Response.ok(String.format("%s
Hello application is running on port : %d; connectorType : %s", helloService.greeting(), port, configuration.getHttpConfiguration().getConnectorType())).build(); + return Response.ok(String.format("%s
Hello application is running on port : %d;", + helloService.greeting(), + port) + ).build(); } public HelloService getHelloService() { diff --git a/src/test/java/hello/server_lifecycle_listeners/HelloServerLifecycleListener.java b/src/test/java/hello/server_lifecycle_listeners/HelloServerLifecycleListener.java index b6fbe85..888a33d 100644 --- a/src/test/java/hello/server_lifecycle_listeners/HelloServerLifecycleListener.java +++ b/src/test/java/hello/server_lifecycle_listeners/HelloServerLifecycleListener.java @@ -2,7 +2,7 @@ import org.eclipse.jetty.server.Server; -import com.yammer.dropwizard.lifecycle.ServerLifecycleListener; +import io.dropwizard.lifecycle.ServerLifecycleListener; public class HelloServerLifecycleListener implements ServerLifecycleListener { @Override diff --git a/src/test/java/hello/tasks/HelloTask.java b/src/test/java/hello/tasks/HelloTask.java index 7bde737..eef2551 100644 --- a/src/test/java/hello/tasks/HelloTask.java +++ b/src/test/java/hello/tasks/HelloTask.java @@ -1,7 +1,7 @@ package hello.tasks; import com.google.common.collect.ImmutableMultimap; -import com.yammer.dropwizard.tasks.Task; +import io.dropwizard.servlets.tasks.Task; import java.io.PrintWriter; diff --git a/src/test/resources/hello/hello.yml b/src/test/resources/hello/hello.yml index d0ac042..c19fa66 100644 --- a/src/test/resources/hello/hello.yml +++ b/src/test/resources/hello/hello.yml @@ -1,18 +1,11 @@ # HTTP-specific options. -http: - - # The port on which the HTTP server listens for service requests. - port: 9898 - - # The type of connector to use. Other valid values are "nonblocking" or "legacy". In general, the - # blocking connector should be used for low-latency services with short request durations. The - # nonblocking connector should be used for services with long request durations or which - # specifically take advantage of Jetty's continuation support. - # If you need SSL support, you can either choose from "nonblocking+ssl" or "legacy+ssl". - connectorType: blocking +server: + applicationContectors: + - type: http + port: 9898 hello: # The hello message to display at http://localhost:9898/hello - message: Welcome to the hello application !!! \ No newline at end of file + message: Welcome to the hello application !!!