From 5004d2baa460b4ce9313296757e33446463b3f7f Mon Sep 17 00:00:00 2001 From: JonMR Date: Fri, 12 Oct 2018 14:57:24 -0400 Subject: [PATCH 1/7] Start of v3.0.0 - Build with DW 1.3.7 - Target Java 8 - Use Java 8 Supplier and Optional - Support builds with Java 9 and higher - Upgrade mockito - Remove deprecations --- pom.xml | 30 ++++++++++++------- .../RequestTrackerBundle.java | 4 +-- .../RequestTrackerClientFilter.java | 13 ++++---- .../RequestTrackerServletFilter.java | 11 +++---- .../UuidSupplier.java | 2 +- .../RequestTrackerClientFilterTest.java | 15 +++++----- .../RequestTrackerServletFilterTest.java | 15 +++++----- .../UuidSupplierTest.java | 2 +- 8 files changed, 47 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 7787372..64b7fa5 100644 --- a/pom.xml +++ b/pom.xml @@ -144,14 +144,8 @@ org.mockito mockito-core - 1.10.19 + 2.23.0 test - - - org.hamcrest - hamcrest-core - - org.hamcrest @@ -159,6 +153,19 @@ 1.3 test + + + javax.xml.bind + jaxb-api + 2.3.0 + test + + + javax.activation + activation + 1.1.1 + test + @@ -166,10 +173,11 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.0 - 1.7 - 1.7 + 8 + 1.8 + 1.8 @@ -244,6 +252,6 @@ - 0.9.1 + 1.3.7 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(); From 87491c4bfe31aa8061f68bce0c258194956e92a3 Mon Sep 17 00:00:00 2001 From: JonMR Date: Fri, 12 Oct 2018 17:02:21 -0400 Subject: [PATCH 2/7] Fix dependency convergence issues and upgrade a few maven plugins --- pom.xml | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 64b7fa5..2b010b0 100644 --- a/pom.xml +++ b/pom.xml @@ -106,22 +106,61 @@ + + + + + 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 @@ -207,7 +246,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.3.1 + 1.4.1 enforce @@ -225,7 +264,7 @@ org.apache.maven.plugins maven-source-plugin - 2.3 + 3.0.1 attach-sources @@ -238,7 +277,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.0.1 attach-javadocs From 80c96f2a35d922a3c1a6c55f80a868d59f60dc06 Mon Sep 17 00:00:00 2001 From: JonMR Date: Fri, 12 Oct 2018 17:32:27 -0400 Subject: [PATCH 3/7] Try to fix travis by setting compiler release only on JDKs >= 9 --- .travis.yml | 4 ++++ pom.xml | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dff5f3a..6ec11f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,5 @@ language: java + +jdk: +- openjdk8 +- openjdk11 diff --git a/pom.xml b/pom.xml index 2b010b0..86fb0d9 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,27 @@ + + java-9-and-greater + + [9,) + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.plugin.version} + + 8 + 1.8 + 1.8 + + + + + @@ -209,12 +230,12 @@ + org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + ${maven.compiler.plugin.version} - 8 1.8 1.8 @@ -292,5 +313,6 @@ 1.3.7 + 3.8.0 From 25ee6075af2d9be023fd6f79e2185971c9d51d38 Mon Sep 17 00:00:00 2001 From: JonMR Date: Fri, 12 Oct 2018 17:35:02 -0400 Subject: [PATCH 4/7] Cache m2 repository for faster builds --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6ec11f7..686a253 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,7 @@ language: java jdk: - openjdk8 - openjdk11 + +cache: + directories: + - $HOME/.m2 From 2588a05e00c5a70a215283f93554728d403a0810 Mon Sep 17 00:00:00 2001 From: JonMR Date: Fri, 9 Nov 2018 12:29:10 -0500 Subject: [PATCH 5/7] Update pom version and clarify version differences in README --- README.md | 11 ++++++----- pom.xml | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7d300fa..87b0cbc 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 ``` diff --git a/pom.xml b/pom.xml index 86fb0d9..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 From 8316352cedab8387dc29acaea6410054de8b2540 Mon Sep 17 00:00:00 2001 From: Carl Yute Date: Fri, 7 Dec 2018 19:46:32 -0500 Subject: [PATCH 6/7] change CustomIdSupplier to implement Java 8 Supplier --- README.md | 2 +- .../dropwizardrequesttracker/it/CustomIdSupplier.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87b0cbc..65fdbdf 100644 --- a/README.md +++ b/README.md @@ -81,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/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 From bbda5aaefc5a17699f54bf2503357481d092d527 Mon Sep 17 00:00:00 2001 From: Carl Yute Date: Fri, 7 Dec 2018 19:52:29 -0500 Subject: [PATCH 7/7] use diamond operator to abbreviate RHS of expression --- .../dropwizardrequesttracker/it/BundleApplicationIT.java | 2 +- .../it/CustomIdSupplierBundleApplicationIT.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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