Skip to content

Commit

Permalink
WW-5486 Fixes exposing params added by ServletDispatcherResult
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Nov 9, 2024
1 parent 90c9dfa commit 24e6041
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/struts2/ActionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -316,6 +317,7 @@ public String getActionName() {
*/
public ActionContext withParameters(HttpParameters parameters) {
put(PARAMETERS, parameters);
put(DispatcherConstants.PARAMETERS, parameters);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ public Map<String, Object> createContextMap(Map<String, Object> requestMap,
.with(DispatcherConstants.REQUEST, requestMap)
.with(DispatcherConstants.SESSION, sessionMap)
.with(DispatcherConstants.APPLICATION, applicationMap)
.with(DispatcherConstants.PARAMETERS, parameters)
.getContextMap();

AttributeMap attrMap = new AttributeMap(extraContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@

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 {

Expand All @@ -53,8 +56,7 @@ public void testInclude() {
try {
view.execute(null);
} catch (Exception e) {
e.printStackTrace();
fail();
fail(e.getMessage());
}

dispatcherMock.verify();
Expand Down Expand Up @@ -86,8 +88,7 @@ public void testSimple() {
try {
view.execute(null);
} catch (Exception e) {
e.printStackTrace();
fail();
fail(e.getMessage());
}

dispatcherMock.verify();
Expand Down Expand Up @@ -123,12 +124,17 @@ public void testWithParameter() {
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();
Expand Down

0 comments on commit 24e6041

Please sign in to comment.