WW-5486 Fixes exposing params added by ServletDispatcherResult

This commit is contained in:
Lukasz Lenart
2024-11-09 10:48:02 +01:00
parent 90c9dfa923
commit 24e60416f6
3 changed files with 21 additions and 14 deletions
@@ -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;
}
@@ -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);
@@ -20,16 +20,19 @@ package org.apache.struts2.result;
import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.Mock;
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 jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.struts2.ActionContext;
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 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();