Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
javalover123888
SkyWalking
提交
ef8b5aaa
S
SkyWalking
项目概览
javalover123888
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
2
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
ef8b5aaa
编写于
8月 11, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adjust the springMVC plugin.
上级
62817eed
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
11 deletion
+52
-11
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/ControllerConstructorInterceptor.java
...m/plugin/spring/mvc/ControllerConstructorInterceptor.java
+15
-5
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/ControllerServiceMethodInterceptor.java
...plugin/spring/mvc/ControllerServiceMethodInterceptor.java
+9
-6
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/PathMappingCache.java
...rg/skywalking/apm/plugin/spring/mvc/PathMappingCache.java
+28
-0
未找到文件。
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/ControllerConstructorInterceptor.java
浏览文件 @
ef8b5aaa
package
org.skywalking.apm.plugin.spring.mvc
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.springframework.web.bind.annotation.RequestMapping
;
/**
* The <code>ControllerConstructorInterceptor</code> intercepts the Controller's constructor, in order to acquire the
* mapping annotation, if exist.
*
* But, you can see we only use the first mapping value, <B>Why?</B>
*
* Right now, we intercept the controller by annotation as you known, so we CAN'T know which uri patten is actually
* matched. Even we know, that costs a lot.
*
* If we want to resolve that, we must intercept the Spring MVC core codes, that is not a good choice for now.
*
* Comment by @wu-sheng
*/
public
class
ControllerConstructorInterceptor
implements
InstanceConstructorInterceptor
{
@Override
...
...
@@ -15,8 +26,7 @@ public class ControllerConstructorInterceptor implements InstanceConstructorInte
if
(
basePathRequestMapping
!=
null
)
{
basePath
=
basePathRequestMapping
.
value
()[
0
];
}
Map
<
Object
,
String
>
cacheRequestPath
=
new
HashMap
<
Object
,
String
>();
cacheRequestPath
.
put
(
"BASE_PATH"
,
basePath
);
objInst
.
setSkyWalkingDynamicField
(
cacheRequestPath
);
PathMappingCache
pathMappingCache
=
new
PathMappingCache
(
basePath
);
objInst
.
setSkyWalkingDynamicField
(
pathMappingCache
);
}
}
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/ControllerServiceMethodInterceptor.java
浏览文件 @
ef8b5aaa
package
org.skywalking.apm.plugin.spring.mvc
;
import
java.lang.reflect.Method
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.skywalking.apm.agent.core.conf.Config
;
...
...
@@ -18,16 +17,20 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
/**
* The <code>ControllerServiceMethodInterceptor</code> only use the first mapping value.
*
* @See {@link ControllerConstructorInterceptor} to explain why we are doing this.
*/
public
class
ControllerServiceMethodInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
Map
<
Object
,
String
>
cacheRequestURL
=
(
Map
<
Object
,
String
>
)
objInst
.
getSkyWalkingDynamicField
();
String
requestURL
=
cacheRequestURL
.
get
(
method
);
PathMappingCache
pathMappingCache
=
(
PathMappingCache
)
objInst
.
getSkyWalkingDynamicField
();
String
requestURL
=
pathMappingCache
.
findPathMapping
(
method
);
if
(
requestURL
==
null
)
{
requestURL
=
new
String
(
cacheRequestURL
.
get
(
"BASE_PATH"
));
requestURL
+=
method
.
getAnnotation
(
RequestMapping
.
class
).
value
()[
0
];
cacheRequestURL
.
put
(
method
,
requestURL
.
toString
());
requestURL
=
method
.
getAnnotation
(
RequestMapping
.
class
).
value
()[
0
];
pathMappingCache
.
addPathMapping
(
method
,
requestURL
.
toString
());
}
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
...
...
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/PathMappingCache.java
0 → 100644
浏览文件 @
ef8b5aaa
package
org.skywalking.apm.plugin.spring.mvc
;
import
java.lang.reflect.Method
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* The <code>PathMappingCache</code> represents a field
*
*
* @author wusheng
*/
public
class
PathMappingCache
{
private
String
classPath
=
""
;
private
ConcurrentHashMap
<
Method
,
String
>
methodPathMapping
=
new
ConcurrentHashMap
<
Method
,
String
>();
public
PathMappingCache
(
String
classPath
)
{
this
.
classPath
=
classPath
;
}
public
String
findPathMapping
(
Method
method
)
{
return
methodPathMapping
.
get
(
method
);
}
public
void
addPathMapping
(
Method
method
,
String
methodPath
)
{
methodPathMapping
.
put
(
method
,
classPath
+
methodPath
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录