Skip to content

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

Merged
merged 3 commits into from
May 12, 2025

Conversation

lukaszlenart
Copy link
Member

Copy link
Contributor

@Copilot Copilot AI left a 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.

Co-authored-by: Copilot <[email protected]>
Copy link

@MFAshby MFAshby left a 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:
Copy link

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());
Copy link

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.

Copy link

@MFAshby MFAshby left a 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! 😀

@lukaszlenart
Copy link
Member Author

@MFAshby thanks a lot for review, you were right and these attributes should be controlled by the container.

@lukaszlenart lukaszlenart merged commit d27d3fb into main May 12, 2025
9 checks passed
@lukaszlenart lukaszlenart deleted the fix/WW-5548-forward branch May 12, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants