Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
1c3606a8
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1c3606a8
编写于
7月 19, 2018
作者:
X
Xin,Zhang
提交者:
wu-sheng
7月 19, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change the way to transmit the Request and Response (#1471)
上级
06b6f054
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
60 addition
and
45 deletion
+60
-45
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java
...plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java
+2
-4
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java
...king/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java
+8
-0
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java
...in/spring/mvc/v4/RequestMappingMethodInterceptorTest.java
+2
-2
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java
...lugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java
+2
-0
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/SpringTestCaseHelper.java
...alking/apm/plugin/spring/mvc/v4/SpringTestCaseHelper.java
+0
-3
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java
...e/skywalking/apm/plugin/spring/mvc/commons/Constants.java
+0
-4
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java
.../plugin/spring/mvc/commons/EnhanceRequireObjectCache.java
+23
-0
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java
...ng/mvc/commons/interceptor/AbstractMethodInterceptor.java
+16
-13
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java
...in/spring/mvc/commons/interceptor/GetBeanInterceptor.java
+2
-6
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java
.../mvc/commons/interceptor/InvokeForRequestInterceptor.java
+2
-7
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeHandlerMethodInterceptor.java
...c/commons/interceptor/InvokeHandlerMethodInterceptor.java
+3
-6
未找到文件。
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/HandlerMethodInvokerInterceptor.java
浏览文件 @
1c3606a8
...
...
@@ -19,14 +19,12 @@
package
org.apache.skywalking.apm.plugin.spring.mvc.v3
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
RESPONSE_KEY_IN_RUNTIME_CONTEXT
;
/**
* {@link HandlerMethodInvokerInterceptor} pass the {@link NativeWebRequest} object into the {@link
* org.springframework.stereotype.Controller} object.
...
...
@@ -39,7 +37,7 @@ public class HandlerMethodInvokerInterceptor implements InstanceMethodsAroundInt
MethodInterceptResult
result
)
throws
Throwable
{
Object
handler
=
allArguments
[
1
];
if
(
handler
instanceof
EnhancedInstance
)
{
ContextManager
.
getRuntimeContext
().
put
(
RESPONSE_KEY_IN_RUNTIME_CONTEXT
,
((
NativeWebRequest
)
allArguments
[
2
]).
getNativeResponse
()
);
((
EnhanceRequireObjectCache
)((
EnhancedInstance
)
handler
).
getSkyWalkingDynamicField
()).
setNativeWebRequest
((
NativeWebRequest
)
allArguments
[
2
]
);
}
}
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v3/GetBeanInterceptorTest.java
浏览文件 @
1c3606a8
...
...
@@ -61,4 +61,12 @@ public class GetBeanInterceptorTest {
verify
(
enhanceRet
,
times
(
0
)).
setSkyWalkingDynamicField
(
Matchers
.
any
());
}
@Test
public
void
testResultIsEnhanceInstance
()
throws
Throwable
{
interceptor
.
afterMethod
(
enhancedInstance
,
null
,
null
,
null
,
enhanceRet
);
verify
(
enhanceRet
,
times
(
0
)).
setSkyWalkingDynamicField
(
Matchers
.
any
());
}
}
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RequestMappingMethodInterceptorTest.java
浏览文件 @
1c3606a8
...
...
@@ -174,9 +174,9 @@ public class RequestMappingMethodInterceptorTest {
@Override
public
Object
getSkyWalkingDynamicField
()
{
value
.
setPathMappingCache
(
new
PathMappingCache
(
"/test"
));
value
.
setHttpResponse
(
response
);
value
.
setNativeWebRequest
(
nativeWebRequest
);
return
value
;
}
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/RestMappingMethodInterceptorTest.java
浏览文件 @
1c3606a8
...
...
@@ -306,6 +306,8 @@ public class RestMappingMethodInterceptorTest {
@Override
public
Object
getSkyWalkingDynamicField
()
{
value
.
setPathMappingCache
(
new
PathMappingCache
(
"/test"
));
value
.
setHttpResponse
(
response
);
value
.
setNativeWebRequest
(
nativeWebRequest
);
return
value
;
}
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/mvc/v4/SpringTestCaseHelper.java
浏览文件 @
1c3606a8
...
...
@@ -21,15 +21,12 @@ package org.apache.skywalking.apm.plugin.spring.mvc.v4;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants
;
public
final
class
SpringTestCaseHelper
{
public
final
static
void
createCaseHandler
(
HttpServletRequest
request
,
HttpServletResponse
response
,
CaseHandler
a
)
throws
Throwable
{
ContextManager
.
createLocalSpan
(
"For-Test"
);
ContextManager
.
getRuntimeContext
().
put
(
Constants
.
REQUEST_KEY_IN_RUNTIME_CONTEXT
,
request
);
ContextManager
.
getRuntimeContext
().
put
(
Constants
.
RESPONSE_KEY_IN_RUNTIME_CONTEXT
,
response
);
a
.
handleCase
();
ContextManager
.
stopSpan
();
}
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java
浏览文件 @
1c3606a8
...
...
@@ -34,10 +34,6 @@ public class Constants {
public
static
final
String
HYSTRIX_COMMAND_ANNOTATION
=
"com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand"
;
public
static
final
String
REQUEST_KEY_IN_RUNTIME_CONTEXT
=
"SW_REQUEST"
;
public
static
final
String
RESPONSE_KEY_IN_RUNTIME_CONTEXT
=
"SW_RESPONSE"
;
public
static
final
String
ISOLATE_STRATEGY_KEY_IN_RUNNING_CONTEXT
=
"ISOLATE_STRATEGY"
;
public
static
final
String
FORWARD_REQUEST_FLAG
=
"SW_FORWARD_REQUEST_FLAG"
;
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java
浏览文件 @
1c3606a8
...
...
@@ -18,15 +18,28 @@
package
org.apache.skywalking.apm.plugin.spring.mvc.commons
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.Method
;
public
class
EnhanceRequireObjectCache
{
private
PathMappingCache
pathMappingCache
;
private
ThreadLocal
<
NativeWebRequest
>
nativeWebRequest
=
new
ThreadLocal
<
NativeWebRequest
>();
private
ThreadLocal
<
HttpServletResponse
>
httpResponse
=
new
ThreadLocal
<
HttpServletResponse
>();
public
void
setPathMappingCache
(
PathMappingCache
pathMappingCache
)
{
this
.
pathMappingCache
=
pathMappingCache
;
}
public
HttpServletResponse
getHttpServletResponse
()
{
return
httpResponse
.
get
()
==
null
?
(
HttpServletResponse
)
nativeWebRequest
.
get
().
getNativeResponse
()
:
httpResponse
.
get
();
}
public
void
setNativeWebRequest
(
NativeWebRequest
nativeWebRequest
)
{
this
.
nativeWebRequest
.
set
(
nativeWebRequest
);
}
public
String
findPathMapping
(
Method
method
)
{
return
pathMappingCache
.
findPathMapping
(
method
);
}
...
...
@@ -38,4 +51,14 @@ public class EnhanceRequireObjectCache {
public
PathMappingCache
getPathMappingCache
()
{
return
pathMappingCache
;
}
public
void
setHttpResponse
(
HttpServletResponse
httpResponse
)
{
this
.
httpResponse
.
set
(
httpResponse
);
}
public
void
clearRequestAndResponse
()
{
setNativeWebRequest
(
null
);
setHttpResponse
(
null
);
}
}
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java
浏览文件 @
1c3606a8
...
...
@@ -32,11 +32,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
FORWARD_REQUEST_FLAG
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
ISOLATE_STRATEGY_KEY_IN_RUNNING_CONTEXT
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
REQUEST_KEY_IN_RUNTIME_CONTEXT
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
RESPONSE_KEY_IN_RUNTIME_CONTEXT
;
/**
* the abstract method inteceptor
...
...
@@ -66,7 +66,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
}
String
hystrixIsolateStrategy
=
(
String
)
ContextManager
.
getRuntimeContext
().
get
(
ISOLATE_STRATEGY_KEY_IN_RUNNING_CONTEXT
);
HttpServletRequest
request
=
(
HttpServletRequest
)
ContextManager
.
getRuntimeContext
().
get
(
REQUEST_KEY_IN_RUNTIME_CONTEXT
);
HttpServletRequest
request
=
(
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
(
);
if
(
hystrixIsolateStrategy
!=
null
)
{
ContextManager
.
createLocalSpan
(
requestURL
);
...
...
@@ -99,17 +99,20 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
}
String
hystrixIsolateStrategy
=
(
String
)
ContextManager
.
getRuntimeContext
().
get
(
ISOLATE_STRATEGY_KEY_IN_RUNNING_CONTEXT
);
HttpServletResponse
response
=
(
HttpServletResponse
)
ContextManager
.
getRuntimeContext
().
get
(
RESPONSE_KEY_IN_RUNTIME_CONTEXT
);
if
(
hystrixIsolateStrategy
!=
null
)
{
ContextManager
.
stopSpan
();
}
else
if
(
response
!=
null
)
{
AbstractSpan
span
=
ContextManager
.
activeSpan
();
if
(
response
.
getStatus
()
>=
400
)
{
span
.
errorOccurred
();
Tags
.
STATUS_CODE
.
set
(
span
,
Integer
.
toString
(
response
.
getStatus
()));
HttpServletResponse
response
=
((
EnhanceRequireObjectCache
)
objInst
.
getSkyWalkingDynamicField
()).
getHttpServletResponse
();
try
{
if
(
hystrixIsolateStrategy
!=
null
)
{
ContextManager
.
stopSpan
();
}
else
if
(
response
!=
null
)
{
AbstractSpan
span
=
ContextManager
.
activeSpan
();
if
(
response
.
getStatus
()
>=
400
)
{
span
.
errorOccurred
();
Tags
.
STATUS_CODE
.
set
(
span
,
Integer
.
toString
(
response
.
getStatus
()));
}
ContextManager
.
stopSpan
();
}
ContextManager
.
stopSpan
();
}
finally
{
((
EnhanceRequireObjectCache
)
objInst
.
getSkyWalkingDynamicField
()).
clearRequestAndResponse
();
}
return
ret
;
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/GetBeanInterceptor.java
浏览文件 @
1c3606a8
...
...
@@ -19,15 +19,11 @@
package
org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
REQUEST_KEY_IN_RUNTIME_CONTEXT
;
/**
* {@link GetBeanInterceptor} pass the {@link NativeWebRequest} object into the {@link
...
...
@@ -45,7 +41,7 @@ public class GetBeanInterceptor implements InstanceMethodsAroundInterceptor {
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
if
(
ret
instanceof
EnhancedInstance
)
{
ContextManager
.
getRuntimeContext
().
put
(
REQUEST_KEY_IN_RUNTIME_CONTEXT
,
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
((
EnhanceRequireObjectCache
)((
EnhancedInstance
)
ret
).
getSkyWalkingDynamicField
()).
setNativeWebRequest
((
NativeWebRequest
)
objInst
.
getSkyWalkingDynamicField
());
}
return
ret
;
}
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeForRequestInterceptor.java
浏览文件 @
1c3606a8
...
...
@@ -16,19 +16,14 @@
*
*/
package
org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
java.lang.reflect.Method
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
RESPONSE_KEY_IN_RUNTIME_CONTEXT
;
/**
* {@link InvokeForRequestInterceptor} pass the {@link NativeWebRequest} object into the {@link
* org.springframework.stereotype.Controller} object.
...
...
@@ -39,7 +34,7 @@ public class InvokeForRequestInterceptor implements InstanceMethodsAroundInterce
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
ContextManager
.
getRuntimeContext
().
put
(
RESPONSE_KEY_IN_RUNTIME_CONTEXT
,
((
NativeWebRequest
)
allArguments
[
0
]).
getNativeResponse
()
);
objInst
.
setSkyWalkingDynamicField
(
allArguments
[
0
]
);
}
@Override
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/InvokeHandlerMethodInterceptor.java
浏览文件 @
1c3606a8
...
...
@@ -19,21 +19,18 @@
package
org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
REQUEST_KEY_IN_RUNTIME_CONTEXT
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
RESPONSE_KEY_IN_RUNTIME_CONTEXT
;
import
org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache
;
public
class
InvokeHandlerMethodInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
if
(
allArguments
[
2
]
instanceof
EnhancedInstance
)
{
ContextManager
.
getRuntimeContext
().
put
(
RESPONSE_KEY_IN_RUNTIME_CONTEXT
,
allArguments
[
1
]);
ContextManager
.
getRuntimeContext
().
put
(
REQUEST_KEY_IN_RUNTIME_CONTEXT
,
allArguments
[
0
]);
((
EnhanceRequireObjectCache
)((
EnhancedInstance
)
allArguments
[
2
]).
getSkyWalkingDynamicField
()).
setHttpResponse
((
HttpServletResponse
)
allArguments
[
1
]);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录