Search in sources :

Example 1 with EnhanceRequireObjectCache

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);
}
Also used : EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) PathMappingCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EnhanceRequireObjectCache

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 3 with EnhanceRequireObjectCache

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);
}
Also used : EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) PathMappingCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with 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);
}
Also used : GetBeanInterceptor(org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.GetBeanInterceptor) EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) Before(org.junit.Before)

Example 5 with EnhanceRequireObjectCache

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");
}
Also used : Method(java.lang.reflect.Method) EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) Test(org.junit.Test)

Aggregations

EnhanceRequireObjectCache (org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache)8 Method (java.lang.reflect.Method)3 Test (org.junit.Test)3 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)2 PathMappingCache (org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)1 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)1 GetBeanInterceptor (org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.GetBeanInterceptor)1 Before (org.junit.Before)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1