fixes #735 Concurrency conflicts in Spring plugin
* EnhanceRequireObjectCache add clearRequestAndResponse method * invoke EnhanceRequireObjectCache clearRequestAndResponse At AbstractMethodInterceptor
This commit is contained in:
parent
647f4f00a7
commit
44a5526c78
|
|
@ -56,4 +56,9 @@ public class EnhanceRequireObjectCache {
|
|||
this.httpResponse.set(httpResponse);
|
||||
}
|
||||
|
||||
public void clearRequestAndResponse() {
|
||||
setNativeWebRequest(null);
|
||||
setHttpResponse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import java.lang.reflect.Method;
|
|||
/**
|
||||
* the abstract method inteceptor
|
||||
*/
|
||||
public abstract class AbstractMethodInteceptor implements InstanceMethodsAroundInterceptor {
|
||||
public abstract class AbstractMethodInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
public abstract String getRequestURL(Method method);
|
||||
|
||||
@Override
|
||||
|
|
@ -73,17 +73,19 @@ public abstract class AbstractMethodInteceptor implements InstanceMethodsAroundI
|
|||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) throws Throwable {
|
||||
HttpServletResponse response = ((EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField()).getHttpServletResponse();
|
||||
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()));
|
||||
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();
|
||||
}
|
||||
ContextManager.stopSpan();
|
||||
|
||||
((EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField()).setNativeWebRequest(null);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -38,9 +38,6 @@ public class InvokeHandlerMethodInterceptor implements InstanceMethodsAroundInte
|
|||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) throws Throwable {
|
||||
if (allArguments[2] instanceof EnhancedInstance) {
|
||||
((EnhanceRequireObjectCache)((EnhancedInstance)allArguments[2]).getSkyWalkingDynamicField()).setHttpResponse(null);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,16 +19,17 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* The <code>RequestMappingMethodInterceptor</code> only use the first mapping value.
|
||||
* it will inteceptor with <code>@RequestMapping</code>
|
||||
*
|
||||
* @author clevertension
|
||||
*/
|
||||
public class RequestMappingMethodInterceptor extends AbstractMethodInteceptor {
|
||||
public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor {
|
||||
@Override
|
||||
public String getRequestURL(Method method) {
|
||||
String requestURL = "";
|
||||
|
|
|
|||
|
|
@ -19,12 +19,9 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
||||
/**
|
||||
* The <code>RestMappingMethodInterceptor</code> only use the first mapping value.
|
||||
|
|
@ -34,7 +31,7 @@ import org.springframework.web.bind.annotation.PutMapping;
|
|||
*
|
||||
* @author clevertension
|
||||
*/
|
||||
public class RestMappingMethodInterceptor extends AbstractMethodInteceptor {
|
||||
public class RestMappingMethodInterceptor extends AbstractMethodInterceptor {
|
||||
@Override
|
||||
public String getRequestURL(Method method) {
|
||||
String requestURL = "";
|
||||
|
|
|
|||
Loading…
Reference in New Issue