This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch fix/WW-5486-request-params in repository https://gitbox.apache.org/repos/asf/struts.git
commit 24e60416f69e972579d8f17563a41814af15fba5 Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Sat Nov 9 10:48:02 2024 +0100 WW-5486 Fixes exposing params added by ServletDispatcherResult --- .../java/org/apache/struts2/ActionContext.java | 2 ++ .../org/apache/struts2/dispatcher/Dispatcher.java | 1 - .../result/ServletDispatcherResultTest.java | 28 +++++++++++++--------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/ActionContext.java b/core/src/main/java/org/apache/struts2/ActionContext.java index febedd04f..bad8f6705 100644 --- a/core/src/main/java/org/apache/struts2/ActionContext.java +++ b/core/src/main/java/org/apache/struts2/ActionContext.java @@ -24,6 +24,7 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.PageContext; import org.apache.struts2.action.Action; import org.apache.struts2.conversion.impl.ConversionData; +import org.apache.struts2.dispatcher.DispatcherConstants; import org.apache.struts2.dispatcher.HttpParameters; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.inject.Container; @@ -316,6 +317,7 @@ public class ActionContext implements Serializable { */ public ActionContext withParameters(HttpParameters parameters) { put(PARAMETERS, parameters); + put(DispatcherConstants.PARAMETERS, parameters); return this; } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index deab70ce1..cb85639d1 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -851,7 +851,6 @@ public class Dispatcher { .with(DispatcherConstants.REQUEST, requestMap) .with(DispatcherConstants.SESSION, sessionMap) .with(DispatcherConstants.APPLICATION, applicationMap) - .with(DispatcherConstants.PARAMETERS, parameters) .getContextMap(); AttributeMap attrMap = new AttributeMap(extraContext); diff --git a/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java b/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java index 219f3d218..22a6312ea 100644 --- a/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java +++ b/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java @@ -20,16 +20,19 @@ package org.apache.struts2.result; import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.Mock; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.struts2.ActionContext; -import org.apache.struts2.mock.MockActionInvocation; -import org.apache.struts2.util.ValueStackFactory; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsInternalTestCase; import org.apache.struts2.StrutsStatics; +import org.apache.struts2.dispatcher.DispatcherConstants; +import org.apache.struts2.dispatcher.Parameter; +import org.apache.struts2.mock.MockActionInvocation; +import org.apache.struts2.util.ValueStackFactory; -import jakarta.servlet.RequestDispatcher; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import java.util.Map; public class ServletDispatcherResultTest extends StrutsInternalTestCase implements StrutsStatics { @@ -53,8 +56,7 @@ public class ServletDispatcherResultTest extends StrutsInternalTestCase implemen try { view.execute(null); } catch (Exception e) { - e.printStackTrace(); - fail(); + fail(e.getMessage()); } dispatcherMock.verify(); @@ -86,8 +88,7 @@ public class ServletDispatcherResultTest extends StrutsInternalTestCase implemen try { view.execute(null); } catch (Exception e) { - e.printStackTrace(); - fail(); + fail(e.getMessage()); } dispatcherMock.verify(); @@ -123,12 +124,17 @@ public class ServletDispatcherResultTest extends StrutsInternalTestCase implemen try { view.execute(mockActionInvocation); } catch (Exception e) { - e.printStackTrace(); - fail(); + fail(e.getMessage()); } assertTrue(mockActionInvocation.getInvocationContext().getParameters().contains("bar")); assertEquals("1", mockActionInvocation.getInvocationContext().getParameters().get("bar").getValue()); + + // See https://issues.apache.org/jira/browse/WW-5486 + Map<String, Parameter> contextMap = (Map<String, Parameter>) mockActionInvocation.getInvocationContext().getContextMap().get(DispatcherConstants.PARAMETERS); + assertTrue(contextMap.containsKey("bar")); + assertEquals("1", contextMap.get("bar").getValue()); + dispatcherMock.verify(); requestMock.verify(); dispatcherMock.verify();