This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch fix/WW-5450-forward in repository https://gitbox.apache.org/repos/asf/struts.git
commit 16dac7b0b548935b57b3a7f4d8e1afc6fba8bc6c Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Sat Aug 31 07:04:24 2024 +0200 WW-5450 Sets RequestDispatcher#FORWARD_REQUEST_URI attribute when forwarding --- .../main/java/org/apache/struts2/result/ServletDispatcherResult.java | 3 +++ .../java/org/apache/struts2/result/ServletDispatcherResultTest.java | 1 + 2 files changed, 4 insertions(+) diff --git a/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java b/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java index df0896cf4..7de36e805 100644 --- a/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java +++ b/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java @@ -166,6 +166,9 @@ public class ServletDispatcherResult extends StrutsResultSupport { request.setAttribute("struts.view_uri", finalLocation); request.setAttribute("struts.request_uri", request.getRequestURI()); + LOG.debug("Sets request attribute: {} to value: {}", RequestDispatcher.FORWARD_REQUEST_URI, finalLocation); + request.setAttribute(RequestDispatcher.FORWARD_REQUEST_URI, finalLocation); + dispatcher.forward(request, response); } else { LOG.debug("Including location: {}", finalLocation); 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 90da7b6c9..c1ab57b11 100644 --- a/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java +++ b/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java @@ -75,6 +75,7 @@ public class ServletDispatcherResultTest extends StrutsInternalTestCase implemen requestMock.expectAndReturn("getRequestDispatcher", C.args(C.eq("foo.jsp")), dispatcherMock.proxy()); requestMock.expect("setAttribute", C.ANY_ARGS); // this is a bad mock, but it works requestMock.expect("setAttribute", C.ANY_ARGS); // this is a bad mock, but it works + requestMock.expect("setAttribute", C.args(C.eq(RequestDispatcher.FORWARD_REQUEST_URI), C.eq("foo.jsp"))); requestMock.matchAndReturn("getRequestURI", "foo.jsp"); Mock responseMock = new Mock(HttpServletResponse.class);