Repository: struts
Updated Branches:
  refs/heads/master 774e3a630 -> 885261803


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/88526180
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/88526180
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/88526180

Branch: refs/heads/master
Commit: 88526180375f958ea57eceedb3017f4b7637ef68
Parents: 774e3a6
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Fri Mar 18 20:41:06 2016 +0100
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Sat Mar 19 06:58:28 2016 +0100

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


http://git-wip-us.apache.org/repos/asf/struts/blob/88526180/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java 
b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
index a8dcf56..167159c 100644
--- a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
+++ b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
@@ -248,8 +248,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 [{}]", 
result);
 
@@ -359,6 +357,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);

http://git-wip-us.apache.org/repos/asf/struts/blob/88526180/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 0f45b1a..60fcffe 100644
--- 
a/core/src/main/java/org/apache/struts2/interceptor/MessageStorePreResultListener.java
+++ 
b/core/src/main/java/org/apache/struts2/interceptor/MessageStorePreResultListener.java
@@ -20,11 +20,13 @@
 package org.apache.struts2.interceptor;
 
 import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
 import com.opensymphony.xwork2.interceptor.PreResultListener;
 import com.opensymphony.xwork2.interceptor.ValidationAware;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.result.ServletActionRedirectResult;
 import org.apache.struts2.result.ServletRedirectResult;
 
 import java.util.Map;
@@ -69,7 +71,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/88526180/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 4e46b3a..e9f589d 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,11 @@ 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.result.ServletActionRedirectResult;
 import org.easymock.EasyMock;
 
 import javax.servlet.http.HttpServletRequest;
@@ -138,8 +140,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 +220,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/88526180/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 2b1cd82..42d9a71 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 {

Reply via email to