File tree Expand file tree Collapse file tree
dd-java-agent/instrumentation/spring/spring-webmvc
spring-webmvc-3.1/src/main/java/datadog/trace/instrumentation/springweb
spring-webmvc-5.3/src/main/java/datadog/trace/instrumentation/springweb Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313import datadog .trace .agent .tooling .InstrumenterModule ;
1414import datadog .trace .api .Config ;
1515import datadog .trace .api .telemetry .EndpointCollector ;
16+ import java .util .HashMap ;
1617import java .util .Map ;
1718import net .bytebuddy .asm .Advice ;
1819import net .bytebuddy .matcher .ElementMatcher ;
@@ -71,13 +72,16 @@ public static class AppSecHandlerMappingAdvice {
7172
7273 @ Advice .OnMethodExit (suppress = Throwable .class )
7374 public static void afterRefresh (@ Advice .Argument (0 ) final ApplicationContext springCtx ) {
74- final RequestMappingHandlerMapping handler =
75- springCtx .getBean (RequestMappingHandlerMapping .class );
76- if (handler == null ) {
75+ final Map < String , RequestMappingHandlerMapping > handlers =
76+ springCtx .getBeansOfType (RequestMappingHandlerMapping .class );
77+ if (handlers == null || handlers . isEmpty () ) {
7778 return ;
7879 }
79- final Map <RequestMappingInfo , HandlerMethod > mappings = handler .getHandlerMethods ();
80- if (mappings == null || mappings .isEmpty ()) {
80+ final Map <RequestMappingInfo , HandlerMethod > mappings = new HashMap <>();
81+ for (RequestMappingHandlerMapping mapping : handlers .values ()) {
82+ mappings .putAll (mapping .getHandlerMethods ());
83+ }
84+ if (mappings .isEmpty ()) {
8185 return ;
8286 }
8387 EndpointCollector .get ().supplier (new RequestMappingInfoIterator (mappings ));
Original file line number Diff line number Diff line change 1212import datadog .trace .agent .tooling .InstrumenterModule ;
1313import datadog .trace .api .Config ;
1414import datadog .trace .api .telemetry .EndpointCollector ;
15+ import java .util .HashMap ;
1516import java .util .Map ;
1617import net .bytebuddy .asm .Advice ;
1718import net .bytebuddy .matcher .ElementMatcher ;
@@ -66,13 +67,16 @@ public static class AppSecHandlerMappingAdvice {
6667
6768 @ Advice .OnMethodExit (suppress = Throwable .class )
6869 public static void afterRefresh (@ Advice .Argument (0 ) final ApplicationContext springCtx ) {
69- final RequestMappingHandlerMapping handler =
70- springCtx .getBean (RequestMappingHandlerMapping .class );
71- if (handler == null ) {
70+ final Map < String , RequestMappingHandlerMapping > handlers =
71+ springCtx .getBeansOfType (RequestMappingHandlerMapping .class );
72+ if (handlers == null || handlers . isEmpty () ) {
7273 return ;
7374 }
74- final Map <RequestMappingInfo , HandlerMethod > mappings = handler .getHandlerMethods ();
75- if (mappings == null || mappings .isEmpty ()) {
75+ final Map <RequestMappingInfo , HandlerMethod > mappings = new HashMap <>();
76+ for (RequestMappingHandlerMapping mapping : handlers .values ()) {
77+ mappings .putAll (mapping .getHandlerMethods ());
78+ }
79+ if (mappings .isEmpty ()) {
7680 return ;
7781 }
7882 EndpointCollector .get ().supplier (new RequestMappingInfoWithPathPatternsIterator (mappings ));
You can’t perform that action at this time.
0 commit comments