From 0323795d67ae4fa1c9964e7cf5c0865f2deb250d Mon Sep 17 00:00:00 2001 From: Aleksandr Mashchenko Date: Sun, 3 Feb 2019 12:41:18 +0200 Subject: [PATCH 1/2] WW-5009 EmptyStackException in JSON plugin due to concurrency --- .../java/org/apache/struts2/json/JSONInterceptor.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java b/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java index 2c793de42..d3b1b4833 100644 --- a/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java +++ b/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java @@ -71,13 +71,6 @@ public class JSONInterceptor extends AbstractInterceptor { private String jsonContentType = "application/json"; private String jsonRpcContentType = "application/json-rpc"; - private JSONUtil jsonUtil; - - @Inject - public void setJsonUtil(JSONUtil jsonUtil) { - this.jsonUtil = jsonUtil; - } - @SuppressWarnings("unchecked") public String intercept(ActionInvocation invocation) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); @@ -175,6 +168,8 @@ public class JSONInterceptor extends AbstractInterceptor { result = rpcResponse; } + JSONUtil jsonUtil = invocation.getInvocationContext().getContainer().getInstance(JSONUtil.class); + String json = jsonUtil.serialize(result, excludeProperties, getIncludeProperties(), ignoreHierarchy, excludeNullProperties); json = addCallbackIfApplicable(request, json); From 7242a8716553781a31a93818c888bc455c6e5854 Mon Sep 17 00:00:00 2001 From: Aleksandr Mashchenko Date: Sun, 3 Feb 2019 12:58:43 +0200 Subject: [PATCH 2/2] WW-5009 Fix tests --- .../struts2/json/JSONInterceptorTest.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java b/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java index dd8492799..9f6b76fc4 100644 --- a/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java +++ b/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java @@ -93,9 +93,6 @@ public class JSONInterceptorTest extends StrutsTestCase { this.request.addHeader("Content-Type", "application/json-rpc"); JSONInterceptor interceptor = new JSONInterceptor(); - JSONUtil jsonUtil = new JSONUtil(); - jsonUtil.setWriter(new DefaultJSONWriter()); - interceptor.setJsonUtil(jsonUtil); SMDActionTest1 action = new SMDActionTest1(); this.invocation.setAction(action); @@ -116,9 +113,6 @@ public class JSONInterceptorTest extends StrutsTestCase { JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); - JSONUtil jsonUtil = new JSONUtil(); - jsonUtil.setWriter(new DefaultJSONWriter()); - interceptor.setJsonUtil(jsonUtil); SMDActionTest2 action = new SMDActionTest2(); this.invocation.setAction(action); @@ -137,9 +131,6 @@ public class JSONInterceptorTest extends StrutsTestCase { JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); - JSONUtil jsonUtil = new JSONUtil(); - jsonUtil.setWriter(new DefaultJSONWriter()); - interceptor.setJsonUtil(jsonUtil); SMDActionTest2 action = new SMDActionTest2(); this.invocation.setAction(action); @@ -158,9 +149,6 @@ public class JSONInterceptorTest extends StrutsTestCase { JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); - JSONUtil jsonUtil = new JSONUtil(); - jsonUtil.setWriter(new DefaultJSONWriter()); - interceptor.setJsonUtil(jsonUtil); SMDActionTest1 action = new SMDActionTest1(); this.invocation.setAction(action); @@ -206,9 +194,6 @@ public class JSONInterceptorTest extends StrutsTestCase { JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); - JSONUtil jsonUtil = new JSONUtil(); - jsonUtil.setWriter(new DefaultJSONWriter()); - interceptor.setJsonUtil(jsonUtil); SMDActionTest1 action = new SMDActionTest1(); this.invocation.setAction(action); @@ -244,9 +229,6 @@ public class JSONInterceptorTest extends StrutsTestCase { JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); - JSONUtil jsonUtil = new JSONUtil(); - jsonUtil.setWriter(new DefaultJSONWriter()); - interceptor.setJsonUtil(jsonUtil); SMDActionTest2 action = new SMDActionTest2(); this.invocation.setAction(action); @@ -272,9 +254,6 @@ public class JSONInterceptorTest extends StrutsTestCase { JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); - JSONUtil jsonUtil = new JSONUtil(); - jsonUtil.setWriter(new DefaultJSONWriter()); - interceptor.setJsonUtil(jsonUtil); SMDActionTest1 action = new SMDActionTest1(); this.invocation.setAction(action);