You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2020/03/13 09:01:13 UTC
[skywalking] branch master updated: fix the error of Struts2
plugin: java.lang.NoSuchMethodError:
javax.servlet.http.HttpServletResponse.getStatus() (#4503)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 80911d0 fix the error of Struts2 plugin: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus() (#4503)
80911d0 is described below
commit 80911d088c2869fa5c4a11dc9c9d31e983eef606
Author: muyun12 <11...@qq.com>
AuthorDate: Fri Mar 13 17:01:06 2020 +0800
fix the error of Struts2 plugin: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus() (#4503)
Co-authored-by: 吴晟 Wu Sheng <wu...@foxmail.com>
---
.../skywalking/apm/plugin/struts2/Struts2Interceptor.java | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java
index 18a1599..4f5fa1a 100644
--- a/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/struts2-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/struts2/Struts2Interceptor.java
@@ -26,6 +26,7 @@ import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.util.MethodUtil;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.struts2.ServletActionContext;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
@@ -34,6 +35,15 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
public class Struts2Interceptor implements InstanceMethodsAroundInterceptor {
+
+ private static boolean IS_SERVLET_GET_STATUS_METHOD_EXIST;
+ private static final String SERVLET_RESPONSE_CLASS = "javax.servlet.http.HttpServletResponse";
+ private static final String GET_STATUS_METHOD = "getStatus";
+
+ static {
+ IS_SERVLET_GET_STATUS_METHOD_EXIST = MethodUtil.isMethodExist(Struts2Interceptor.class.getClassLoader(), SERVLET_RESPONSE_CLASS, GET_STATUS_METHOD);
+ }
+
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
@@ -59,7 +69,7 @@ public class Struts2Interceptor implements InstanceMethodsAroundInterceptor {
HttpServletResponse response = ServletActionContext.getResponse();
AbstractSpan span = ContextManager.activeSpan();
- if (response.getStatus() >= 400) {
+ if (IS_SERVLET_GET_STATUS_METHOD_EXIST && response.getStatus() >= 400) {
span.errorOccurred();
Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
}