Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start of v3.0.0 #34

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
language: java

jdk:
- openjdk8
- openjdk11

cache:
directories:
- $HOME/.m2
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------------------
Expand All @@ -29,7 +30,7 @@ Add the following dependency into your pom.xml
<dependency>
<groupId>com.serviceenabled</groupId>
<artifactId>dropwizard-request-tracker</artifactId>
<version>0.2.0</version>
<version>3.0.0</version>
</dependency>
```

Expand Down Expand Up @@ -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<String>`. Here's an example ID supplier:

```java
import com.google.common.base.Supplier;
import java.util.function.Supplier;

public class CustomIdSupplier implements Supplier<String> {
@Override
Expand Down
99 changes: 84 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.serviceenabled</groupId>
<artifactId>dropwizard-request-tracker</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<name>Dropwizard Request Tracker</name>
<url>https://github.com/service-enabled/dropwizard-request-tracker</url>
<description>
Expand Down Expand Up @@ -104,24 +104,84 @@
</plugins>
</build>
</profile>
<profile>
<id>java-9-and-greater</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<build>
<plugins>
<!-- Set release in JDK 9 and higher -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<release>8</release>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencyManagement>
<dependencies>
<!-- Added for a conflict between dropwizard-util, com.papertrail:profiler, and jackson-datatype-joda -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>
<!-- Added for a conflict between dropwizard-client and jersey-apache-connector -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-client</artifactId>
<version>${dropwizard.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-logging</artifactId>
<version>${dropwizard.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -144,32 +204,40 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<version>2.23.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<!-- Java 9 javax removals -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Maven compiler is redefined in a profile for JDK 9 and up -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -199,7 +267,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
Expand All @@ -217,7 +285,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.3</version>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -230,7 +298,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -244,6 +312,7 @@
</build>

<properties>
<dropwizard.version>0.9.1</dropwizard.version>
<dropwizard.version>1.3.7</dropwizard.version>
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -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<T> implements ConfiguredBundle<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -24,8 +22,9 @@ public RequestTrackerClientFilter(RequestTrackerConfiguration configuration, Sup

@Override
public void filter(ClientRequestContext clientRequest) {
Optional<String> requestId = Optional.fromNullable(MDC.get(configuration.getMdcKey()));
Optional<String> requestId = Optional.ofNullable(MDC.get(configuration.getMdcKey()));

clientRequest.getHeaders().add(configuration.getHeaderName(), requestId.or(idSupplier));
clientRequest.getHeaders().add(configuration.getHeaderName(),
requestId.orElseGet(idSupplier));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> idSupplier;
Expand All @@ -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<String> requestId = Optional.fromNullable(httpServletRequest.getHeader(configuration.getHeaderName()));
String resolvedId = requestId.or(idSupplier);
Optional<String> requestId = Optional.ofNullable(httpServletRequest.getHeader(configuration.getHeaderName()));
String resolvedId = requestId.orElseGet(idSupplier);

MDC.put(configuration.getMdcKey(), resolvedId);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -34,15 +35,15 @@ public void setUp() {
}

@After
public void tearDown() throws Exception {
public void tearDown() {
MDC.clear();
}

@Test
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
Expand Down
Loading