You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2016/03/18 20:41:19 UTC

struts git commit: WW-4605 Reverts to previous flow when result is created just before executing it

Repository: struts
Updated Branches:
  refs/heads/support-2-3 519c76711 -> 6b497ef8f


WW-4605 Reverts to previous flow when result is created just before executing it


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/6b497ef8
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/6b497ef8
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/6b497ef8

Branch: refs/heads/support-2-3
Commit: 6b497ef8f7091224b4e87a825fdbc50b02a21c3d
Parents: 519c767
Author: Lukasz Lenart <lu...@apache.org>
Authored: Fri Mar 18 20:41:06 2016 +0100
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Fri Mar 18 20:41:06 2016 +0100

----------------------------------------------------------------------
 .../MessageStorePreResultListener.java          |  8 ++++++-
 .../MessageStorePreResultListenerTest.java      | 22 ++++++++++++++++----
 .../apache/struts2/views/jsp/ActionTagTest.java |  3 +--
 .../xwork2/DefaultActionInvocation.java         |  4 ++--
 4 files changed, 28 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/6b497ef8/core/src/main/java/org/apache/struts2/interceptor/MessageStorePreResultListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/interceptor/MessageStorePreResultListener.java b/core/src/main/java/org/apache/struts2/interceptor/MessageStorePreResultListener.java
index d78313c..5415a73 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/MessageStorePreResultListener.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/MessageStorePreResultListener.java
@@ -21,10 +21,12 @@ package org.apache.struts2.interceptor;
 
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ValidationAware;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
 import com.opensymphony.xwork2.interceptor.PreResultListener;
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
 import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.ServletActionRedirectResult;
 import org.apache.struts2.dispatcher.ServletRedirectResult;
 
 import java.util.Map;
@@ -68,7 +70,11 @@ class MessageStorePreResultListener implements PreResultListener {
 
         boolean isRedirect = false;
         try {
-            isRedirect = invocation.getResult() instanceof ServletRedirectResult;
+            ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(resultCode);
+            if (resultConfig != null) {
+                isRedirect = ServletRedirectResult.class.getName().equals(resultConfig.getClassName())
+                        || ServletActionRedirectResult.class.getName().equals(resultConfig.getClassName());
+            }
         } catch (Exception e) {
             LOG.warn("Cannot read result!", e);
         }

http://git-wip-us.apache.org/repos/asf/struts/blob/6b497ef8/core/src/test/java/org/apache/struts2/interceptor/MessageStorePreResultListenerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/interceptor/MessageStorePreResultListenerTest.java b/core/src/test/java/org/apache/struts2/interceptor/MessageStorePreResultListenerTest.java
index 599ab09..0b4340b 100644
--- a/core/src/test/java/org/apache/struts2/interceptor/MessageStorePreResultListenerTest.java
+++ b/core/src/test/java/org/apache/struts2/interceptor/MessageStorePreResultListenerTest.java
@@ -4,9 +4,13 @@ import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ActionSupport;
+import com.opensymphony.xwork2.config.entities.ActionConfig;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.mock.MockActionProxy;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsInternalTestCase;
 import org.apache.struts2.dispatcher.ServletActionRedirectResult;
+import org.apache.struts2.dispatcher.ServletRedirectResult;
 import org.easymock.EasyMock;
 
 import javax.servlet.http.HttpServletRequest;
@@ -138,8 +142,13 @@ public class MessageStorePreResultListenerTest extends StrutsInternalTestCase {
         EasyMock.expectLastCall().andReturn(action);
         EasyMock.expectLastCall().anyTimes();
 
-        mockActionInvocation.getResult();
-        EasyMock.expectLastCall().andReturn(new ServletActionRedirectResult());
+        mockActionInvocation.getProxy();
+        MockActionProxy actionProxy = new MockActionProxy();
+        ResultConfig resultConfig = new ResultConfig.Builder(Action.SUCCESS, ServletRedirectResult.class.getName()).build();
+        ActionConfig actionConfig = new ActionConfig.Builder("", "test", action.getClass().getName()).addResultConfig(resultConfig).build();
+        actionProxy.setConfig(actionConfig);
+        EasyMock.expectLastCall().andReturn(actionProxy);
+        EasyMock.expectLastCall().anyTimes();
 
         EasyMock.replay(mockActionInvocation);
 
@@ -213,8 +222,13 @@ public class MessageStorePreResultListenerTest extends StrutsInternalTestCase {
         mockActionInvocation.getAction();
         EasyMock.expectLastCall().andReturn(action);
 
-        mockActionInvocation.getResult();
-        EasyMock.expectLastCall().andReturn(new ServletActionRedirectResult());
+        mockActionInvocation.getProxy();
+        MockActionProxy actionProxy = new MockActionProxy();
+        ResultConfig resultConfig = new ResultConfig.Builder(Action.SUCCESS, ServletRedirectResult.class.getName()).build();
+        ActionConfig actionConfig = new ActionConfig.Builder("", "test", action.getClass().getName()).addResultConfig(resultConfig).build();
+        actionProxy.setConfig(actionConfig);
+        EasyMock.expectLastCall().andReturn(actionProxy);
+        EasyMock.expectLastCall().anyTimes();
 
         EasyMock.replay(mockActionInvocation);
 

http://git-wip-us.apache.org/repos/asf/struts/blob/6b497ef8/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java
index f7d8a3b..d31e498 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java
@@ -179,8 +179,7 @@ public class ActionTagTest extends AbstractTagTest {
 
         assertTrue(stack.getContext().containsKey(ServletActionContext.PAGE_CONTEXT));
         assertTrue(stack.getContext().get(ServletActionContext.PAGE_CONTEXT)instanceof PageContext);
-        assertNotNull(result);
-        assertFalse(result.isExecuted());
+        assertNull(result); // result is never executed, hence never set into invocation
     }
 
      public void testExecuteButResetReturnSameInvocation() throws Exception {

http://git-wip-us.apache.org/repos/asf/struts/blob/6b497ef8/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
index b82efaf..fcf397e 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
@@ -254,8 +254,6 @@ public class DefaultActionInvocation implements ActionInvocation {
             // this is needed because the result will be executed, then control will return to the Interceptor, which will
             // return above and flow through again
             if (!executed) {
-                result = createResult();
-
                 if (preResultListeners != null) {
                     LOG.trace("Executing PreResultListeners for result [#0]", result);
 
@@ -365,6 +363,8 @@ public class DefaultActionInvocation implements ActionInvocation {
      * @throws ConfigurationException If not result can be found with the returned code
      */
     private void executeResult() throws Exception {
+        result = createResult();
+
         String timerKey = "executeResult: " + getResultCode();
         try {
             UtilTimerStack.push(timerKey);