use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.
the class ControllerConstructorInterceptor method onConstruct.
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String basePath = "";
RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class);
if (basePathRequestMapping != null) {
if (basePathRequestMapping.value().length > 0) {
basePath = basePathRequestMapping.value()[0];
}
}
EnhanceRequireObjectCache enhanceCache = new EnhanceRequireObjectCache();
enhanceCache.setPathMappingCache(new PathMappingCache(basePath));
objInst.setSkyWalkingDynamicField(enhanceCache);
}
use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.
the class AbstractMethodInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
String requestURL = pathMappingCache.findPathMapping(method);
if (requestURL == null) {
requestURL = getRequestURL(method);
pathMappingCache.addPathMapping(method, requestURL);
requestURL = pathMappingCache.findPathMapping(method);
}
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(request.getHeader(next.getHeadKey()));
}
AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier);
Tags.URL.set(span, request.getRequestURL().toString());
Tags.HTTP.METHOD.set(span, request.getMethod());
span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION);
SpanLayer.asHttp(span);
}
use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.
the class ControllerConstructorInterceptor method onConstruct.
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String basePath = "";
RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class);
if (basePathRequestMapping != null) {
if (basePathRequestMapping.value().length > 0) {
basePath = basePathRequestMapping.value()[0];
} else if (basePathRequestMapping.path().length > 0) {
basePath = basePathRequestMapping.path()[0];
}
}
EnhanceRequireObjectCache enhanceRequireObjectCache = new EnhanceRequireObjectCache();
enhanceRequireObjectCache.setPathMappingCache(new PathMappingCache(basePath));
objInst.setSkyWalkingDynamicField(enhanceRequireObjectCache);
}
use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.
the class GetBeanInterceptorTest method setUp.
@Before
public void setUp() {
interceptor = new GetBeanInterceptor();
when(enhanceRet.getSkyWalkingDynamicField()).thenReturn(new EnhanceRequireObjectCache());
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(request);
}
use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.
the class ControllerConstructorInterceptorTest method testOnConstruct_Accuracy3.
@Test
public void testOnConstruct_Accuracy3() throws Throwable {
controllerConstructorInterceptor.onConstruct(inst3, null);
EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache) inst3.getSkyWalkingDynamicField();
Assert.assertNotNull(cache);
Object obj = new Object();
Method m = obj.getClass().getMethods()[0];
cache.addPathMapping(m, "#toString");
Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/test3#toString");
}
Aggregations