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 {
|
||||
// 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 {
|
||||
events "started"
|
||||
}
|
||||
|
|
|
@ -10,7 +10,9 @@ import org.jboss.byteman.rule.Rule;
|
|||
/** Patch the Jetty Servlet during the init steps */
|
||||
public class JettyServletHelper extends DDAgentTracingHelper<ServletContextHandler> {
|
||||
|
||||
public JettyServletHelper(Rule rule) {
|
||||
private static final String pattern = "/*";
|
||||
|
||||
public JettyServletHelper(final Rule rule) {
|
||||
super(rule);
|
||||
}
|
||||
|
||||
|
@ -21,18 +23,19 @@ public class JettyServletHelper extends DDAgentTracingHelper<ServletContextHandl
|
|||
* @return The same current contextHandler but patched
|
||||
* @throws Exception
|
||||
*/
|
||||
protected ServletContextHandler doPatch(ServletContextHandler contextHandler) throws Exception {
|
||||
|
||||
String[] patterns = {"/*"};
|
||||
|
||||
Filter filter = new TracingFilter(tracer);
|
||||
FilterRegistration.Dynamic registration =
|
||||
contextHandler.getServletContext().addFilter("tracingFilter", filter);
|
||||
registration.setAsyncSupported(true);
|
||||
registration.addMappingForUrlPatterns(
|
||||
EnumSet.allOf(javax.servlet.DispatcherType.class), true, patterns);
|
||||
|
||||
setState(contextHandler.getServletContext(), 1);
|
||||
@Override
|
||||
protected ServletContextHandler doPatch(final ServletContextHandler contextHandler)
|
||||
throws Exception {
|
||||
if (contextHandler.getServletContext().getFilterRegistration("tracingFilter") == null) {
|
||||
final Filter filter = new TracingFilter(tracer);
|
||||
final FilterRegistration.Dynamic registration =
|
||||
contextHandler.getServletContext().addFilter("tracingFilter", filter);
|
||||
if (registration != null) { // filter of that name must already be registered.
|
||||
registration.setAsyncSupported(true);
|
||||
registration.addMappingForUrlPatterns(
|
||||
EnumSet.allOf(javax.servlet.DispatcherType.class), true, pattern);
|
||||
}
|
||||
}
|
||||
return contextHandler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ import javax.servlet.FilterRegistration;
|
|||
import org.apache.catalina.core.ApplicationContext;
|
||||
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 TomcatServletHelper(Rule rule) {
|
||||
private static final String pattern = "/*";
|
||||
|
||||
public TomcatServletHelper(final Rule rule) {
|
||||
super(rule);
|
||||
}
|
||||
|
||||
|
@ -21,16 +23,18 @@ public class TomcatServletHelper extends DDAgentTracingHelper<ApplicationContext
|
|||
* @return The same current contextHandler but patched
|
||||
* @throws Exception
|
||||
*/
|
||||
protected ApplicationContext doPatch(ApplicationContext contextHandler) throws Exception {
|
||||
|
||||
String[] patterns = {"/*"};
|
||||
|
||||
Filter filter = new TracingFilter(tracer);
|
||||
FilterRegistration.Dynamic registration = contextHandler.addFilter("tracingFilter", filter);
|
||||
registration.setAsyncSupported(true);
|
||||
registration.addMappingForUrlPatterns(
|
||||
EnumSet.allOf(javax.servlet.DispatcherType.class), true, patterns);
|
||||
|
||||
@Override
|
||||
protected ApplicationContext doPatch(final ApplicationContext contextHandler) throws Exception {
|
||||
if (contextHandler.getFilterRegistration("tracingFilter") == null) {
|
||||
final Filter filter = new TracingFilter(tracer);
|
||||
final FilterRegistration.Dynamic registration =
|
||||
contextHandler.addFilter("tracingFilter", filter);
|
||||
if (registration != null) { // filter of that name must already be registered.
|
||||
registration.setAsyncSupported(true);
|
||||
registration.addMappingForUrlPatterns(
|
||||
EnumSet.allOf(javax.servlet.DispatcherType.class), true, pattern);
|
||||
}
|
||||
}
|
||||
return contextHandler;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue