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

This commit is contained in:
Lukasz Lenart
2016-03-18 20:41:06 +01:00
parent 519c767114
commit 6b497ef8f7
4 changed files with 28 additions and 9 deletions
@@ -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);
}
@@ -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);
@@ -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 {
@@ -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);