Search in sources :

Example 6 with EnhanceRequireObjectCache

use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.

the class ControllerConstructorInterceptorTest method testOnConstruct_Accuracy1.

@Test
public void testOnConstruct_Accuracy1() throws Throwable {
    controllerConstructorInterceptor.onConstruct(inst1, null);
    EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache) inst1.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), "/test1#toString");
}
Also used : Method(java.lang.reflect.Method) EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) Test(org.junit.Test)

Example 7 with EnhanceRequireObjectCache

use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.

the class ControllerConstructorInterceptorTest method testOnConstruct_Accuracy2.

@Test
public void testOnConstruct_Accuracy2() throws Throwable {
    controllerConstructorInterceptor.onConstruct(inst2, null);
    EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache) inst2.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), "#toString");
}
Also used : Method(java.lang.reflect.Method) EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) Test(org.junit.Test)

Example 8 with EnhanceRequireObjectCache

use of org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache in project incubator-skywalking by apache.

the class AbstractMethodInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    try {
        HttpServletResponse response = ((EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField()).getHttpServletResponse();
        AbstractSpan span = ContextManager.activeSpan();
        if (response.getStatus() >= 400) {
            span.errorOccurred();
            Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
        }
        ContextManager.stopSpan();
        return ret;
    } finally {
        ((EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField()).clearRequestAndResponse();
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

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