lukaszlenart commented on code in PR #571:
URL: https://github.com/apache/struts/pull/571#discussion_r899827537


##########
core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java:
##########
@@ -656,6 +649,36 @@ public void serviceAction(HttpServletRequest request, 
HttpServletResponse respon
         }
     }
 
+    private ActionProxy prepareActionProxy(Map<String, Object> extraContext, 
String actionNamespace, String actionName, String actionMethod) {
+        ActionProxy proxy;
+        //check if we are probably in an async resuming
+        ActionInvocation invocation = 
ActionContext.getContext().getActionInvocation();
+        if (invocation == null || invocation.isExecuted()) {
+            LOG.trace("Creating a new action, namespace: {}, name: {}, method: 
{}", actionNamespace, actionName, actionMethod);
+            proxy = createActionProxy(actionNamespace, actionName, 
actionMethod, extraContext);
+        } else {
+            proxy = invocation.getProxy();
+            if (isSameAction(proxy, actionNamespace, actionName, 
actionMethod)) {
+                LOG.trace("Proxy: {} matches requested action, namespace: {}, 
name: {}, method: {} - reusing proxy", proxy, actionNamespace, actionName, 
actionMethod);
+            } else {
+                LOG.trace("Proxy: {} doesn't match action namespace: {}, name: 
{}, method: {} - creating new proxy", proxy, actionNamespace, actionName, 
actionMethod);
+                proxy = createActionProxy(actionNamespace, actionName, 
actionMethod, extraContext);

Review Comment:
   No, the problem here is with reusing the same `ActionInvocation` which is 
bound to the current thread (which means it wasn't recreated to handle a new 
action) and all this happens in the same thread: initial action -> JSP forward 
-> final action. Because of that the same result is executed again and again. 
Before introducing support for Async the action proxy was created each time 
from scratch. And `ActionInvocation#isExecuted()` flag won't help as this 
happens on a result level (the `executed` flag is set to `true` once a result 
has been executed, which won't happen here).
   
   ```
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:126) - Checking if /dispatch is a static 
resource
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:129) - Assuming uri /dispatch as a normal 
action
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:139) - Found mapping 
ActionMapping{name='dispatch', namespace='/', method='null', extension='null', 
params={}, result=null} for /dispatch
   [DEBUG] interceptor.I18nInterceptor (I18nInterceptor.java:120) - Intercept 
'//dispatch'
   [DEBUG] interceptor.I18nInterceptor (I18nInterceptor.java:167) - Using 
LocaleFinder implementation 
org.apache.struts2.interceptor.I18nInterceptor$SessionLocaleHandler
   [DEBUG] interceptor.I18nInterceptor$RequestLocaleHandler 
(I18nInterceptor.java:247) - Searching locale in request under parameter 
request_only_locale
   [DEBUG] interceptor.I18nInterceptor$SessionLocaleHandler 
(I18nInterceptor.java:318) - Searching locale in request under parameter 
request_locale
   [DEBUG] interceptor.I18nInterceptor$SessionLocaleHandler 
(I18nInterceptor.java:345) - Checks session for saved locale
   [DEBUG] interceptor.I18nInterceptor$SessionLocaleHandler 
(I18nInterceptor.java:360) - No Locale defined in session, fetching from 
current request and it won't be stored in session!
   [DEBUG] interceptor.I18nInterceptor$RequestLocaleHandler 
(I18nInterceptor.java:264) - Searching current Invocation context
   [DEBUG] interceptor.I18nInterceptor$RequestLocaleHandler 
(I18nInterceptor.java:268) - Applied invocation context locale: en_US
   [DEBUG] interceptor.I18nInterceptor (I18nInterceptor.java:136) - Before 
action invocation Locale=en_US
   [DEBUG] interceptor.FileUploadInterceptor (FileUploadInterceptor.java:239) - 
Bypassing //dispatch
   [DEBUG] result.ServletDispatcherResult (ServletDispatcherResult.java:127) - 
Forwarding to location: /dispatch-result.jsp
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:126) - Checking if /dispatch-result.jsp is 
a static resource
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:129) - Assuming uri /dispatch-result.jsp as 
a normal action
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:136) - Cannot find mapping for 
/dispatch-result.jsp, passing to other filters
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:126) - Checking if /index.action is a 
static resource
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:129) - Assuming uri /index.action as a 
normal action
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:139) - Found mapping 
ActionMapping{name='index', namespace='/', method='null', extension='action', 
params={}, result=null} for /index.action
   [DEBUG] result.ServletDispatcherResult (ServletDispatcherResult.java:127) - 
Forwarding to location: /dispatch-result.jsp
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:126) - Checking if /dispatch-result.jsp is 
a static resource
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:129) - Assuming uri /dispatch-result.jsp as 
a normal action
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:136) - Cannot find mapping for 
/dispatch-result.jsp, passing to other filters
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:126) - Checking if /index.action is a 
static resource
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:129) - Assuming uri /index.action as a 
normal action
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:139) - Found mapping 
ActionMapping{name='index', namespace='/', method='null', extension='action', 
params={}, result=null} for /index.action
   [DEBUG] result.ServletDispatcherResult (ServletDispatcherResult.java:127) - 
Forwarding to location: /dispatch-result.jsp
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:126) - Checking if /dispatch-result.jsp is 
a static resource
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:129) - Assuming uri /dispatch-result.jsp as 
a normal action
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:136) - Cannot find mapping for 
/dispatch-result.jsp, passing to other filters
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:126) - Checking if /index.action is a 
static resource
   [TRACE] filter.StrutsPrepareAndExecuteFilter 
(StrutsPrepareAndExecuteFilter.java:129) - Assuming uri /index.action as a 
normal action
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@struts.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to