diff --git a/.travis.yml b/.travis.yml index dff5f3a..686a253 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,9 @@ language: java + +jdk: +- openjdk8 +- openjdk11 + +cache: + directories: + - $HOME/.m2 diff --git a/README.md b/README.md index 7d300fa..65fdbdf 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,11 @@ There's a Dropwizard bundle that will add in the servlet filter for you. Jersey Compatibility ------------- -| Version | Dropwizard Version | -| ------------- |:------------------------------:| -| 2.0.x | 1.2.x, 1.1.x, 1.0.x, 0.9.x | -| 0.2.x | 0.8.x, 0.7.x | +| Version | Dropwizard Version | Java Version | +| ------------- |:-------------------------------------|--------------:| +| 3.0.x | 1.3.x, | 8+ | +| 2.0.x | 1.3.x, 1.2.x, 1.1.x, 1.0.x, 0.9.x | 7+ | +| 0.2.x | 0.8.x, 0.7.x | 7+ | Integrating with existing dropwizard project -------------------------------------------- @@ -29,7 +30,7 @@ Add the following dependency into your pom.xml com.serviceenabled dropwizard-request-tracker - 0.2.0 + 3.0.0 ``` @@ -80,7 +81,7 @@ The `RequestTrackerConfiguration` sets the HTTP header name to `X-Request-Tracke By default `UuidSupplier` is used by the bundle and filters. The provided bundle and filters provide constructors for you to pass in your own custom ID supplier. Your custom ID supplier must implement Guava's `Supplier`. Here's an example ID supplier: ```java -import com.google.common.base.Supplier; +import java.util.function.Supplier; public class CustomIdSupplier implements Supplier { @Override diff --git a/pom.xml b/pom.xml index 7787372..93a3567 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.serviceenabled dropwizard-request-tracker - 2.0.1-SNAPSHOT + 3.0.0-SNAPSHOT Dropwizard Request Tracker https://github.com/service-enabled/dropwizard-request-tracker @@ -104,24 +104,84 @@ + + java-9-and-greater + + [9,) + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.plugin.version} + + 8 + 1.8 + 1.8 + + + + + + + + + + joda-time + joda-time + 2.9.9 + + + + org.apache.httpcomponents + httpclient + 4.5.5 + + + + io.dropwizard dropwizard-client ${dropwizard.version} + + com.google.code.findbugs + jsr305 + org.slf4j slf4j-api + + org.javassist + javassist + + + org.hibernate + hibernate-validator + io.dropwizard dropwizard-logging ${dropwizard.version} + + + com.google.code.findbugs + jsr305 + + + com.google.guava + guava + + junit @@ -144,14 +204,8 @@ org.mockito mockito-core - 1.10.19 + 2.23.0 test - - - org.hamcrest - hamcrest-core - - org.hamcrest @@ -159,17 +213,31 @@ 1.3 test + + + javax.xml.bind + jaxb-api + 2.3.0 + test + + + javax.activation + activation + 1.1.1 + test + + org.apache.maven.plugins maven-compiler-plugin - 3.1 + ${maven.compiler.plugin.version} - 1.7 - 1.7 + 1.8 + 1.8 @@ -199,7 +267,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.3.1 + 1.4.1 enforce @@ -217,7 +285,7 @@ org.apache.maven.plugins maven-source-plugin - 2.3 + 3.0.1 attach-sources @@ -230,7 +298,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.0.1 attach-javadocs @@ -244,6 +312,7 @@ - 0.9.1 + 1.3.7 + 3.8.0 diff --git a/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerBundle.java b/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerBundle.java index b7b84b1..c3d399a 100644 --- a/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerBundle.java +++ b/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerBundle.java @@ -1,12 +1,10 @@ package com.serviceenabled.dropwizardrequesttracker; -import com.google.common.base.Supplier; import io.dropwizard.ConfiguredBundle; import io.dropwizard.setup.Bootstrap; import io.dropwizard.setup.Environment; - import java.util.EnumSet; - +import java.util.function.Supplier; import javax.servlet.DispatcherType; public abstract class RequestTrackerBundle implements ConfiguredBundle { diff --git a/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilter.java b/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilter.java index 26f599b..23a5786 100644 --- a/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilter.java +++ b/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilter.java @@ -1,12 +1,10 @@ package com.serviceenabled.dropwizardrequesttracker; -import org.slf4j.MDC; - -import com.google.common.base.Optional; -import com.google.common.base.Supplier; - +import java.util.Optional; +import java.util.function.Supplier; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; +import org.slf4j.MDC; public class RequestTrackerClientFilter implements ClientRequestFilter { @@ -24,8 +22,9 @@ public RequestTrackerClientFilter(RequestTrackerConfiguration configuration, Sup @Override public void filter(ClientRequestContext clientRequest) { - Optional requestId = Optional.fromNullable(MDC.get(configuration.getMdcKey())); + Optional requestId = Optional.ofNullable(MDC.get(configuration.getMdcKey())); - clientRequest.getHeaders().add(configuration.getHeaderName(), requestId.or(idSupplier)); + clientRequest.getHeaders().add(configuration.getHeaderName(), + requestId.orElseGet(idSupplier)); } } \ No newline at end of file diff --git a/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilter.java b/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilter.java index 02ce9bd..ec1038a 100644 --- a/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilter.java +++ b/src/main/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilter.java @@ -1,7 +1,8 @@ package com.serviceenabled.dropwizardrequesttracker; import java.io.IOException; - +import java.util.Optional; +import java.util.function.Supplier; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -10,12 +11,8 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.slf4j.MDC; -import com.google.common.base.Optional; -import com.google.common.base.Supplier; - public class RequestTrackerServletFilter implements Filter { // Use a supplier so we only generate id's when they're needed private final Supplier idSupplier; @@ -37,8 +34,8 @@ public void init(FilterConfig filterConfig) throws ServletException {} public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; - Optional requestId = Optional.fromNullable(httpServletRequest.getHeader(configuration.getHeaderName())); - String resolvedId = requestId.or(idSupplier); + Optional requestId = Optional.ofNullable(httpServletRequest.getHeader(configuration.getHeaderName())); + String resolvedId = requestId.orElseGet(idSupplier); MDC.put(configuration.getMdcKey(), resolvedId); diff --git a/src/main/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplier.java b/src/main/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplier.java index dda3e78..0306608 100644 --- a/src/main/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplier.java +++ b/src/main/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplier.java @@ -1,6 +1,6 @@ package com.serviceenabled.dropwizardrequesttracker; -import com.google.common.base.Supplier; +import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilterTest.java b/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilterTest.java index b806928..17ad283 100644 --- a/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilterTest.java +++ b/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerClientFilterTest.java @@ -2,24 +2,25 @@ import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.slf4j.MDC; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.core.MultivaluedMap; import java.util.UUID; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) public class RequestTrackerClientFilterTest { + @Rule public MockitoRule rule = MockitoJUnit.rule(); + private RequestTrackerClientFilter requestTrackerClientFilter; private RequestTrackerConfiguration configuration; @@ -34,7 +35,7 @@ public void setUp() { } @After - public void tearDown() throws Exception { + public void tearDown() { MDC.clear(); } @@ -42,7 +43,7 @@ public void tearDown() throws Exception { public void setsTheRequestTrackerHeader() { requestTrackerClientFilter.filter(clientRequest); - verify(headersMap).add(eq(this.configuration.getHeaderName()), Mockito.any(UUID.class)); + verify(headersMap).add(eq(this.configuration.getHeaderName()), Mockito.any(String.class)); } @Test diff --git a/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilterTest.java b/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilterTest.java index 818efd6..f6f8924 100644 --- a/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilterTest.java +++ b/src/test/java/com/serviceenabled/dropwizardrequesttracker/RequestTrackerServletFilterTest.java @@ -2,28 +2,27 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.isNotNull; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.UUID; import javax.servlet.FilterChain; -import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.slf4j.MDC; -@RunWith(MockitoJUnitRunner.class) public class RequestTrackerServletFilterTest { + @Rule public MockitoRule rule = MockitoJUnit.rule(); + private RequestTrackerServletFilter requestTrackerServletFilter; private RequestTrackerConfiguration configuration; @@ -32,13 +31,13 @@ public class RequestTrackerServletFilterTest { @Mock private FilterChain chain; @Before - public void setUp() throws Exception { + public void setUp() { this.configuration = new RequestTrackerConfiguration(); requestTrackerServletFilter = new RequestTrackerServletFilter(this.configuration); } @After - public void tearDown() throws Exception { + public void tearDown() { MDC.clear(); } diff --git a/src/test/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplierTest.java b/src/test/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplierTest.java index 166c185..f386e15 100644 --- a/src/test/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplierTest.java +++ b/src/test/java/com/serviceenabled/dropwizardrequesttracker/UuidSupplierTest.java @@ -8,7 +8,7 @@ public class UuidSupplierTest { @Test - public void suppliesAnId() throws Exception { + public void suppliesAnId() { UuidSupplier uuidSupplier = new UuidSupplier(); String id = uuidSupplier.get(); diff --git a/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/BundleApplicationIT.java b/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/BundleApplicationIT.java index 367fc8d..a2edd14 100644 --- a/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/BundleApplicationIT.java +++ b/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/BundleApplicationIT.java @@ -19,7 +19,7 @@ public class BundleApplicationIT { - private static final DropwizardAppRule DROPWIZARD_APP_RULE = new DropwizardAppRule(BundleApplication.class); + private static final DropwizardAppRule DROPWIZARD_APP_RULE = new DropwizardAppRule<>(BundleApplication.class); private static final IntegrationTestSetupRule INTEGRATION_TEST_SETUP_RULE = new IntegrationTestSetupRule(DROPWIZARD_APP_RULE); @ClassRule diff --git a/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplier.java b/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplier.java index 1679805..f776278 100644 --- a/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplier.java +++ b/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplier.java @@ -1,6 +1,6 @@ package com.serviceenabled.dropwizardrequesttracker.it; -import com.google.common.base.Supplier; +import java.util.function.Supplier; public class CustomIdSupplier implements Supplier { @Override diff --git a/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplierBundleApplicationIT.java b/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplierBundleApplicationIT.java index 0074897..1c01edd 100644 --- a/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplierBundleApplicationIT.java +++ b/src/test/java/com/serviceenabled/dropwizardrequesttracker/it/CustomIdSupplierBundleApplicationIT.java @@ -15,7 +15,7 @@ public class CustomIdSupplierBundleApplicationIT { - private static final DropwizardAppRule DROPWIZARD_APP_RULE = new DropwizardAppRule(CustomIdSupplierBundleApplication.class); + private static final DropwizardAppRule DROPWIZARD_APP_RULE = new DropwizardAppRule<>(CustomIdSupplierBundleApplication.class); private static final IntegrationTestSetupRule INTEGRATION_TEST_SETUP_RULE = new IntegrationTestSetupRule(DROPWIZARD_APP_RULE); @ClassRule