Merge pull request #131 from DataDog/tyler/handle-double-registration
Prevent NPE for double registrations
This commit is contained in:
commit
13ffdc5bbb
|
@ -45,9 +45,9 @@ test {
|
||||||
|
|
||||||
doFirst {
|
doFirst {
|
||||||
// Defining here to allow jacoco to be first on the command line.
|
// Defining here to allow jacoco to be first on the command line.
|
||||||
jvmArgs "-javaagent:${project(':dd-java-agent').buildDir}/libs/dd-java-agent-${project.version}.jar"
|
jvmArgs "-javaagent:${project(':dd-java-agent').tasks.shadowJar.archivePath}"
|
||||||
}
|
}
|
||||||
|
|
||||||
testLogging {
|
testLogging {
|
||||||
events "started"
|
events "started"
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import org.jboss.byteman.rule.Rule;
|
||||||
/** Patch the Jetty Servlet during the init steps */
|
/** Patch the Jetty Servlet during the init steps */
|
||||||
public class JettyServletHelper extends DDAgentTracingHelper<ServletContextHandler> {
|
public class JettyServletHelper extends DDAgentTracingHelper<ServletContextHandler> {
|
||||||
|
|
||||||
public JettyServletHelper(Rule rule) {
|
private static final String pattern = "/*";
|
||||||
|
|
||||||
|
public JettyServletHelper(final Rule rule) {
|
||||||
super(rule);
|
super(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,18 +23,19 @@ public class JettyServletHelper extends DDAgentTracingHelper<ServletContextHandl
|
||||||
* @return The same current contextHandler but patched
|
* @return The same current contextHandler but patched
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected ServletContextHandler doPatch(ServletContextHandler contextHandler) throws Exception {
|
@Override
|
||||||
|
protected ServletContextHandler doPatch(final ServletContextHandler contextHandler)
|
||||||
String[] patterns = {"/*"};
|
throws Exception {
|
||||||
|
if (contextHandler.getServletContext().getFilterRegistration("tracingFilter") == null) {
|
||||||
Filter filter = new TracingFilter(tracer);
|
final Filter filter = new TracingFilter(tracer);
|
||||||
FilterRegistration.Dynamic registration =
|
final FilterRegistration.Dynamic registration =
|
||||||
contextHandler.getServletContext().addFilter("tracingFilter", filter);
|
contextHandler.getServletContext().addFilter("tracingFilter", filter);
|
||||||
registration.setAsyncSupported(true);
|
if (registration != null) { // filter of that name must already be registered.
|
||||||
registration.addMappingForUrlPatterns(
|
registration.setAsyncSupported(true);
|
||||||
EnumSet.allOf(javax.servlet.DispatcherType.class), true, patterns);
|
registration.addMappingForUrlPatterns(
|
||||||
|
EnumSet.allOf(javax.servlet.DispatcherType.class), true, pattern);
|
||||||
setState(contextHandler.getServletContext(), 1);
|
}
|
||||||
|
}
|
||||||
return contextHandler;
|
return contextHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,12 @@ import javax.servlet.FilterRegistration;
|
||||||
import org.apache.catalina.core.ApplicationContext;
|
import org.apache.catalina.core.ApplicationContext;
|
||||||
import org.jboss.byteman.rule.Rule;
|
import org.jboss.byteman.rule.Rule;
|
||||||
|
|
||||||
/** Patch the Jetty Servlet during the init steps */
|
/** Patch the Tomcat Servlet during the init steps */
|
||||||
public class TomcatServletHelper extends DDAgentTracingHelper<ApplicationContext> {
|
public class TomcatServletHelper extends DDAgentTracingHelper<ApplicationContext> {
|
||||||
|
|
||||||
public TomcatServletHelper(Rule rule) {
|
private static final String pattern = "/*";
|
||||||
|
|
||||||
|
public TomcatServletHelper(final Rule rule) {
|
||||||
super(rule);
|
super(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,16 +23,18 @@ public class TomcatServletHelper extends DDAgentTracingHelper<ApplicationContext
|
||||||
* @return The same current contextHandler but patched
|
* @return The same current contextHandler but patched
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected ApplicationContext doPatch(ApplicationContext contextHandler) throws Exception {
|
@Override
|
||||||
|
protected ApplicationContext doPatch(final ApplicationContext contextHandler) throws Exception {
|
||||||
String[] patterns = {"/*"};
|
if (contextHandler.getFilterRegistration("tracingFilter") == null) {
|
||||||
|
final Filter filter = new TracingFilter(tracer);
|
||||||
Filter filter = new TracingFilter(tracer);
|
final FilterRegistration.Dynamic registration =
|
||||||
FilterRegistration.Dynamic registration = contextHandler.addFilter("tracingFilter", filter);
|
contextHandler.addFilter("tracingFilter", filter);
|
||||||
registration.setAsyncSupported(true);
|
if (registration != null) { // filter of that name must already be registered.
|
||||||
registration.addMappingForUrlPatterns(
|
registration.setAsyncSupported(true);
|
||||||
EnumSet.allOf(javax.servlet.DispatcherType.class), true, patterns);
|
registration.addMappingForUrlPatterns(
|
||||||
|
EnumSet.allOf(javax.servlet.DispatcherType.class), true, pattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
return contextHandler;
|
return contextHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue