This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/master by this push:
new afd04ea5a WW-5199 Allow forwarding from/to actions
new 579796de5 Merge pull request #642 from atlassian/WW-5199-forward-action
afd04ea5a is described below
commit afd04ea5af64768ba61b941a4fdd277674196820
Author: Kusal Kithul-Godage <[email protected]>
AuthorDate: Fri Dec 9 00:26:40 2022 +1100
WW-5199 Allow forwarding from/to actions
---
.../org/apache/struts2/showcase/DispatcherResultTest.java | 9 ++-------
.../org/apache/struts2/dispatcher/PrepareOperations.java | 15 +++++++++++----
.../struts2/dispatcher/filter/StrutsExecuteFilter.java | 13 +++----------
.../struts2/dispatcher/filter/StrutsPrepareFilter.java | 2 +-
4 files changed, 17 insertions(+), 22 deletions(-)
diff --git
a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/DispatcherResultTest.java
b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/DispatcherResultTest.java
index 6564270c2..3819e27ab 100644
---
a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/DispatcherResultTest.java
+++
b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/DispatcherResultTest.java
@@ -43,13 +43,8 @@ public class DispatcherResultTest {
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
final HtmlPage page =
webClient.getPage(ParameterUtils.getBaseUrl() + "/dispatcher/forward.action");
- //DomElement div = page.getElementById("dispatcher-result");
- //Assert.assertEquals("This page is a result of \"dispatching\" to
it from an action", div.asNormalizedText());
- // support for forwarding to another action is broken on
StrutsPrepareFilter/StrutsExecuteFilter
- // it only works in StrutsPrepareAndExecuteFilter
- // this will be fixed in Struts 6.1.x
-
- Assert.assertEquals(404, page.getWebResponse().getStatusCode());
+ DomElement div = page.getElementById("dispatcher-result");
+ Assert.assertEquals("This page is a result of \"dispatching\" to
it from an action", div.asNormalizedText());
}
}
diff --git
a/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java
b/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java
index 1d6981bb1..a25e372cf 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java
@@ -52,6 +52,7 @@ public class PrepareOperations {
private Dispatcher dispatcher;
private static final String STRUTS_ACTION_MAPPING_KEY =
"struts.actionMapping";
+ private static final String NO_ACTION_MAPPING = "noActionMapping";
public static final String CLEANUP_RECURSION_COUNTER =
"__cleanup_recursion_counter";
public PrepareOperations(Dispatcher dispatcher) {
@@ -73,7 +74,7 @@ public class PrepareOperations {
if (oldCounter != null) {
counter = oldCounter + 1;
}
-
+
ActionContext oldContext = ActionContext.getContext();
if (oldContext != null) {
// detected existing context, so we are probably in a forward
@@ -172,7 +173,7 @@ public class PrepareOperations {
* has already been found, otherwise, it creates it and stores it in the
request. No mapping will be created in the
* case of static resource requests or unidentifiable requests for other
servlets, for example.
* @param forceLookup if true, the action mapping will be looked up from
the ActionMapper instance, ignoring if there is one
- * in the request or not
+ * in the request or not
*
* @param request servlet request
* @param response servlet response
@@ -180,18 +181,24 @@ public class PrepareOperations {
* @return the action mapping
*/
public ActionMapping findActionMapping(HttpServletRequest request,
HttpServletResponse response, boolean forceLookup) {
- ActionMapping mapping = (ActionMapping)
request.getAttribute(STRUTS_ACTION_MAPPING_KEY);
- if (mapping == null || forceLookup) {
+ ActionMapping mapping = null;
+
+ Object mappingAttr = request.getAttribute(STRUTS_ACTION_MAPPING_KEY);
+ if (mappingAttr == null || forceLookup) {
try {
mapping =
dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request,
dispatcher.getConfigurationManager());
if (mapping != null) {
request.setAttribute(STRUTS_ACTION_MAPPING_KEY, mapping);
+ } else {
+ request.setAttribute(STRUTS_ACTION_MAPPING_KEY,
NO_ACTION_MAPPING);
}
} catch (Exception ex) {
if (dispatcher.isHandleException() || dispatcher.isDevMode()) {
dispatcher.sendError(request, response,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
}
}
+ } else if (!NO_ACTION_MAPPING.equals(mappingAttr)) {
+ mapping = (ActionMapping) mappingAttr;
}
return mapping;
diff --git
a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java
b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java
index 30913f6bb..0e479c449 100644
---
a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java
+++
b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java
@@ -73,17 +73,10 @@ public class StrutsExecuteFilter implements StrutsStatics,
Filter {
ActionMapping mapping = prepare.findActionMapping(request, response);
- //if recursion counter is > 1, it means we are in a "forward", in that
case a mapping will still be
- //in the request, if we handle it, it will lead to an infinite loop,
see WW-3077
- Integer recursionCounter = (Integer)
request.getAttribute(PrepareOperations.CLEANUP_RECURSION_COUNTER);
-
- if (mapping == null || recursionCounter > 1) {
- boolean handled = execute.executeStaticResourceRequest(request,
response);
- if (!handled) {
- chain.doFilter(request, response);
- }
- } else {
+ if (mapping != null) {
execute.executeAction(request, response, mapping);
+ } else if (!execute.executeStaticResourceRequest(request, response)) {
+ chain.doFilter(request, response);
}
}
diff --git
a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java
b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java
index 0332fa342..b35d6cb10 100644
---
a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java
+++
b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java
@@ -86,7 +86,7 @@ public class StrutsPrepareFilter implements StrutsStatics,
Filter {
prepare.createActionContext(request, response);
prepare.assignDispatcherToThread();
request = prepare.wrapRequest(request);
- prepare.findActionMapping(request, response);
+ prepare.findActionMapping(request, response, true);
}
chain.doFilter(request, response);
} finally {