From 6fbd9e53210bd3a18f3c0778f3bed1d3cef3236f Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sun, 3 Nov 2024 11:17:04 +1100 Subject: [PATCH 1/2] WW-3714 Ensure correct delegation of new Result API --- .../xwork2/DefaultActionInvocation.java | 2 +- .../apache/struts2/dispatcher/Dispatcher.java | 2 +- .../TokenSessionStoreInterceptor.java | 16 ++++++++-------- .../struts2/rest/RestActionInvocation.java | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java index db171d1915..f04b765ae8 100644 --- a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java +++ b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java @@ -378,7 +378,7 @@ private void executeResult() throws Exception { result = createResult(); if (result != null) { - result.execute(this); + result.execute((org.apache.struts2.ActionInvocation) this); } else if (resultCode != null && !Action.NONE.equals(resultCode)) { throw new ConfigurationException("No result defined for action " + getAction().getClass().getName() + " and result " + getResultCode(), proxy.getConfig()); diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index a1f9094d1c..ec5333864b 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -734,7 +734,7 @@ public void serviceAction(HttpServletRequest request, HttpServletResponse respon // if the ActionMapping says to go straight to a result, do it! if (mapping.getResult() != null) { Result result = mapping.getResult(); - result.execute(proxy.getInvocation()); + result.execute((org.apache.struts2.ActionInvocation) proxy.getInvocation()); } else { proxy.execute(); } diff --git a/core/src/main/java/org/apache/struts2/interceptor/TokenSessionStoreInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/TokenSessionStoreInterceptor.java index 05e491eeba..2657fb7e68 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/TokenSessionStoreInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/TokenSessionStoreInterceptor.java @@ -116,15 +116,15 @@ protected String handleToken(ActionInvocation invocation) throws Exception { * Handles processing of invalid tokens. If a previously stored invocation is * available, the method will attempt to return and render its result. Otherwise * it will return INVALID_TOKEN_CODE. - * + * * Note: Because a stored (previously completed) invocation's PageContext will be closed, * this method must replace the stored PageContext with the current invocation's one (or a null). * See {@link org.apache.struts2.util.InvocationSessionStore#loadInvocation(String key, String token)} for details. - * + * * @param invocation - * + * * @return - * @throws Exception + * @throws Exception */ @Override protected String handleInvalidToken(ActionInvocation invocation) throws Exception { @@ -154,7 +154,7 @@ protected String handleInvalidToken(ActionInvocation invocation) throws Exceptio Result result = savedInvocation.getResult(); if ((result != null) && (savedInvocation.getProxy().getExecuteResult())) { - result.execute(savedInvocation); + result.execute((org.apache.struts2.ActionInvocation) savedInvocation); } // turn off execution of this invocations result @@ -171,11 +171,11 @@ protected String handleInvalidToken(ActionInvocation invocation) throws Exceptio * Handles processing of valid tokens. Stores the current invocation for * later use by {@see #handleValidToken(ActionInvocation)}. * See {@link org.apache.struts2.util.InvocationSessionStore#storeInvocation(String key, String token, ActionInvocation invocation)} for details. - * + * * @param invocation - * + * * @return - * @throws Exception + * @throws Exception */ @Override protected String handleValidToken(ActionInvocation invocation) throws Exception { diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java index 076f94d87a..6399478e06 100644 --- a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java +++ b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java @@ -207,7 +207,7 @@ private void executeResult() throws Exception { if (this.result instanceof HttpHeaderResult) { // execute the result to apply headers and status in every representations - this.result.execute(this); + this.result.execute((org.apache.struts2.ActionInvocation) this); updateStatusFromResult(); } @@ -219,7 +219,7 @@ private void executeResult() throws Exception { // Normal struts execution (html o other struts result) findResult(); if (result != null) { - this.result.execute(this); + this.result.execute((org.apache.struts2.ActionInvocation) this); } else { if (LOG.isDebugEnabled()) { LOG.debug("No result returned for action {} at {}", getAction().getClass().getName(), proxy.getConfig().getLocation()); From be82a7240350bb0b26a0d36deb73159abe7cc6db Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sun, 3 Nov 2024 11:20:04 +1100 Subject: [PATCH 2/2] WW-3714 Ensure correct delegation of new Interceptor API --- .../com/opensymphony/xwork2/DefaultActionInvocation.java | 6 +++--- .../xwork2/interceptor/AbstractInterceptor.java | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java index f04b765ae8..cb2047f06c 100644 --- a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java +++ b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java @@ -257,7 +257,7 @@ public String invoke() throws Exception { resultCode = executeConditional((ConditionalInterceptor) interceptor); } else { LOG.debug("Executing normal interceptor: {}", interceptorMapping.getName()); - resultCode = interceptor.intercept(this); + resultCode = interceptor.intercept((org.apache.struts2.ActionInvocation) this); } } else { resultCode = invokeActionOnly(); @@ -298,9 +298,9 @@ public String invoke() throws Exception { } protected String executeConditional(ConditionalInterceptor conditionalInterceptor) throws Exception { - if (conditionalInterceptor.shouldIntercept(this)) { + if (conditionalInterceptor.shouldIntercept((org.apache.struts2.ActionInvocation) this)) { LOG.debug("Executing conditional interceptor: {}", conditionalInterceptor.getClass().getSimpleName()); - return conditionalInterceptor.intercept(this); + return conditionalInterceptor.intercept((org.apache.struts2.ActionInvocation) this); } else { LOG.debug("Interceptor: {} is disabled, skipping to next", conditionalInterceptor.getClass().getSimpleName()); return this.invoke(); diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java index 69c6674621..fd160ae9f7 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java @@ -38,6 +38,11 @@ public String intercept(org.apache.struts2.ActionInvocation invocation) throws E @Override public boolean shouldIntercept(ActionInvocation invocation) { - return shouldIntercept((org.apache.struts2.ActionInvocation) invocation); + return super.shouldIntercept(invocation); + } + + @Override + public boolean shouldIntercept(org.apache.struts2.ActionInvocation invocation) { + return shouldIntercept(ActionInvocation.adapt(invocation)); } }