提交 44a5526c 编写于 作者: 公众号-芋道源码's avatar 公众号-芋道源码

fixes #735 Concurrency conflicts in Spring plugin

* EnhanceRequireObjectCache add clearRequestAndResponse method
* invoke EnhanceRequireObjectCache clearRequestAndResponse At AbstractMethodInterceptor
上级 647f4f00
......@@ -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 = "";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册