-
Notifications
You must be signed in to change notification settings - Fork 823
WW-5548 Defines proper request attributes when forwarding or including final path #1265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the handling of request attributes when forwarding or including a resource to align with the Jakarta Servlet 6.0 specification. Key changes include:
- Updating test cases in ServletDispatcherResultTest.java to validate the proper request attributes for forward and include scenarios.
- Refactoring ServletDispatcherResult.java to remove the conditional setting of FORWARD_SERVLET_PATH based on query parameters and instead set all required forwarding attributes.
- Introducing analogous attribute settings for include operations to comply with the specification.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java | Updated tests to assert correct request attributes for forwarding and including resources. |
core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java | Refactored attribute assignment for forwarding and including to align with the Jakarta Servlet 6.0 specification. |
core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for your swift response to this issue! It's very much appreciated.
Please see inline comments regarding some issues I still see.
@@ -173,9 +166,28 @@ public void doExecute(String finalLocation, ActionInvocation invocation) throws | |||
request.setAttribute("struts.view_uri", finalLocation); | |||
request.setAttribute("struts.request_uri", request.getRequestURI()); | |||
|
|||
// These attributes are required when forwarding to another servlet, see specification: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think setting these is the responsibility of the servlet container e.g. tomcat, inside the implementation of the forward
method. We should not have to do it here at all.
request.setAttribute(RequestDispatcher.FORWARD_MAPPING, request.getHttpServletMapping()); | ||
request.setAttribute(RequestDispatcher.FORWARD_REQUEST_URI, request.getRequestURI()); | ||
request.setAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH, request.getContextPath()); | ||
request.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH, request.getServletPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is missing a guard to set the attribute only if it is not already set. There can be multiple forwards, and this attribute should contain the original request as far as I understand.
Per the other comment I think this is redundant, the servlet container should be setting these properties and we should not touch them.
…by Servlet container
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fabulous, thank you very much! 😀
@MFAshby thanks a lot for review, you were right and these attributes should be controlled by the container. |
WW-5548