Skip to content

Commit e6bb08e

Browse files
authored
Merge pull request apache#627 from ascrutae/feature/support-spring3.0
support the 3.0 and 3.1 version of spring mvc framework
2 parents f3a1bf5 + 30ba585 commit e6bb08e

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2017, OpenSkywalking Organization All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Project repository: https://github.com/OpenSkywalking/skywalking
17+
*/
18+
19+
package org.skywalking.apm.plugin.spring.mvc.v3;
20+
21+
import java.lang.reflect.Method;
22+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
23+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
24+
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
25+
import org.springframework.web.context.request.NativeWebRequest;
26+
27+
/**
28+
* {@link HandlerMethodInvokerInterceptor} pass the {@link NativeWebRequest} object into the {@link
29+
* org.springframework.stereotype.Controller} object.
30+
*
31+
* @author zhangxin
32+
*/
33+
public class HandlerMethodInvokerInterceptor implements InstanceMethodsAroundInterceptor {
34+
@Override
35+
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
36+
MethodInterceptResult result) throws Throwable {
37+
Object handler = allArguments[1];
38+
if (handler instanceof EnhancedInstance) {
39+
((EnhanceRequireObjectCache)((EnhancedInstance)handler).getSkyWalkingDynamicField()).setNativeWebRequest((NativeWebRequest)allArguments[2]);
40+
}
41+
}
42+
43+
@Override
44+
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
45+
Object ret) throws Throwable {
46+
return ret;
47+
}
48+
49+
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
50+
Class<?>[] argumentsTypes, Throwable t) {
51+
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2017, OpenSkywalking Organization All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Project repository: https://github.com/OpenSkywalking/skywalking
17+
*/
18+
19+
package org.skywalking.apm.plugin.spring.mvc.v3.define;
20+
21+
import net.bytebuddy.description.method.MethodDescription;
22+
import net.bytebuddy.matcher.ElementMatcher;
23+
import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
24+
import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
25+
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
26+
27+
import static net.bytebuddy.matcher.ElementMatchers.named;
28+
import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
29+
30+
/**
31+
* {@link HandlerMethodInvokerInstrumentation} intercept the <code>invokeHandlerMethod</code> method in the
32+
* <code>org.springframework.web.bind.annotation.support.HandlerMethodInvoker</code> class.
33+
*
34+
* @author zhangxin
35+
*/
36+
public class HandlerMethodInvokerInstrumentation extends AbstractSpring3Instrumentation {
37+
private static final String ENHANCE_CLASS = "org.springframework.web.bind.annotation.support.HandlerMethodInvoker";
38+
private static final String ENHANCE_METHOD = "invokeHandlerMethod";
39+
private static final String INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.spring.mvc.v3.HandlerMethodInvokerInterceptor";
40+
41+
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
42+
return new ConstructorInterceptPoint[0];
43+
}
44+
45+
@Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
46+
return new InstanceMethodsInterceptPoint[] {
47+
new InstanceMethodsInterceptPoint() {
48+
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
49+
return named(ENHANCE_METHOD);
50+
}
51+
52+
@Override public String getMethodsInterceptor() {
53+
return INTERCEPTOR_CLASS;
54+
}
55+
56+
@Override public boolean isOverrideArgs() {
57+
return false;
58+
}
59+
}
60+
};
61+
}
62+
63+
@Override protected ClassMatch enhanceClass() {
64+
return byName(ENHANCE_CLASS);
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.ControllerInstrumentation
22
spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.HandlerMethodInstrumentation
33
spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.InvocableHandlerInstrumentation
4+
spring-mvc-annotation-3.x=org.skywalking.apm.plugin.spring.mvc.v3.define.HandlerMethodInvokerInstrumentation

0 commit comments

Comments
 (0)