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 d78313cab..5415a73e4 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); } 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 599ab0972..0b4340b36 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); 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 f7d8a3b17..d31e498c4 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 { 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 b82efaf5c..fcf397ec0 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);