From a6c4b522086e6e4e5d8b3e7ececa5ff1ad3168ea Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Thu, 17 Oct 2024 17:53:30 +1100 Subject: [PATCH] WW-3714 Deprecate and migrate assorted Interceptors --- .../conversion/impl/XWorkConverter.java | 19 +- .../xwork2/interceptor/AliasInterceptor.java | 11 +- .../interceptor/ChainingInterceptor.java | 16 +- .../ConversionErrorInterceptor.java | 7 +- .../DefaultWorkflowInterceptor.java | 5 +- .../ExceptionMappingInterceptor.java | 5 +- .../interceptor/LoggingInterceptor.java | 3 + .../interceptor/ModelDrivenInterceptor.java | 5 +- .../ParameterRemoverInterceptor.java | 3 + .../PrefixMethodInvocationUtil.java | 51 +-- .../interceptor/PrepareInterceptor.java | 5 +- .../ScopedModelDrivenInterceptor.java | 25 +- .../StaticParametersInterceptor.java | 5 +- .../xwork2/util/TextParseUtil.java | 3 + .../xwork2/util/ValueStackFactory.java | 7 +- .../struts2/interceptor/AliasInterceptor.java | 294 ++++++++++++++++ .../interceptor/ChainingInterceptor.java | 275 +++++++++++++++ .../ConversionErrorInterceptor.java | 150 ++++++++ .../DefaultWorkflowInterceptor.java | 248 ++++++++++++++ .../ExceptionMappingInterceptor.java | 324 ++++++++++++++++++ .../interceptor/LoggingInterceptor.java | 90 +++++ .../interceptor/ModelDrivenInterceptor.java | 148 ++++++++ .../ParameterRemoverInterceptor.java | 124 +++++++ .../interceptor/PrepareInterceptor.java | 177 ++++++++++ .../ScopedModelDrivenInterceptor.java | 166 +++++++++ .../StaticParametersInterceptor.java | 243 +++++++++++++ 26 files changed, 2353 insertions(+), 56 deletions(-) create mode 100644 core/src/main/java/org/apache/struts2/interceptor/AliasInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/ChainingInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/ConversionErrorInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/DefaultWorkflowInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/ExceptionMappingInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/LoggingInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/ModelDrivenInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/ParameterRemoverInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/PrepareInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/ScopedModelDrivenInterceptor.java create mode 100644 core/src/main/java/org/apache/struts2/interceptor/StaticParametersInterceptor.java diff --git a/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java b/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java index 3cda3e34dd..5d16d0e4d2 100644 --- a/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java +++ b/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java @@ -18,12 +18,21 @@ */ package com.opensymphony.xwork2.conversion.impl; -import com.opensymphony.xwork2.*; -import com.opensymphony.xwork2.conversion.*; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.FileManager; +import com.opensymphony.xwork2.FileManagerFactory; +import com.opensymphony.xwork2.LocalizedTextProvider; +import com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor; +import com.opensymphony.xwork2.conversion.ConversionFileProcessor; +import com.opensymphony.xwork2.conversion.TypeConverter; +import com.opensymphony.xwork2.conversion.TypeConverterHolder; import com.opensymphony.xwork2.conversion.annotations.Conversion; import com.opensymphony.xwork2.conversion.annotations.TypeConversion; import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.*; +import com.opensymphony.xwork2.util.AnnotationUtils; +import com.opensymphony.xwork2.util.ClassLoaderUtil; +import com.opensymphony.xwork2.util.CompoundRoot; +import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.reflection.ReflectionContextState; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -220,6 +229,10 @@ public static String getConversionErrorMessage(String propertyName, Class toClas return message; } + public static String getConversionErrorMessage(String propertyName, Class toClass, org.apache.struts2.util.ValueStack stack) { + return getConversionErrorMessage(propertyName, toClass, ValueStack.adapt(stack)); + } + private static String removeAllIndexesInPropertyName(String propertyName) { return propertyName.replaceAll(MESSAGE_INDEX_PATTERN, PERIOD); } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java index 9edafe3fc4..d874310f85 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java @@ -20,21 +20,21 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.LocalizedTextProvider; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.security.AcceptedPatternsChecker; import com.opensymphony.xwork2.security.ExcludedPatternsChecker; import com.opensymphony.xwork2.util.ClearableValueStack; import com.opensymphony.xwork2.util.Evaluated; -import com.opensymphony.xwork2.LocalizedTextProvider; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; import com.opensymphony.xwork2.util.reflection.ReflectionContextState; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.struts2.StrutsConstants; import org.apache.struts2.dispatcher.HttpParameters; import org.apache.struts2.dispatcher.Parameter; -import org.apache.struts2.StrutsConstants; import java.util.Map; @@ -90,7 +90,10 @@ * * * @author Matthew Payne + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.AliasInterceptor} instead. */ +@Deprecated public class AliasInterceptor extends AbstractInterceptor { private static final Logger LOG = LogManager.getLogger(AliasInterceptor.class); @@ -108,7 +111,7 @@ public class AliasInterceptor extends AbstractInterceptor { @Inject(StrutsConstants.STRUTS_DEVMODE) public void setDevMode(String mode) { this.devMode = Boolean.parseBoolean(mode); - } + } @Inject public void setValueStackFactory(ValueStackFactory valueStackFactory) { @@ -225,7 +228,7 @@ public void setAliasesKey(String aliasesKey) { LOG.debug("invalid alias expression: {}", aliasesKey); } } - + return invocation.invoke(); } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java index 31b0075a35..f068fc1ac9 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java @@ -23,16 +23,21 @@ import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.Unchainable; import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.ProxyUtil; import com.opensymphony.xwork2.util.CompoundRoot; +import com.opensymphony.xwork2.util.ProxyUtil; import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import com.opensymphony.xwork2.util.reflection.ReflectionProvider; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.struts2.StrutsConstants; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; /** @@ -113,7 +118,10 @@ * @author mrdon * @author tm_jee ( tm_jee(at)yahoo.co.uk ) * @see com.opensymphony.xwork2.ActionChainResult + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ChainingInterceptor} instead. */ +@Deprecated public class ChainingInterceptor extends AbstractInterceptor { private static final Logger LOG = LogManager.getLogger(ChainingInterceptor.class); diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java index ee8e392815..54d4b6634d 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java @@ -41,13 +41,13 @@ * display the original string ("abc") again rather than the int value (likely 0, which would make very little sense to * the user). *

- * + * *

* Note: Since 2.5.2, this interceptor extends {@link MethodFilterInterceptor}, therefore being * able to deal with excludeMethods / includeMethods parameters. See [Workflow Interceptor] * (class {@link DefaultWorkflowInterceptor}) for documentation and examples on how to use this feature. *

- * + * * * *

Interceptor parameters:

@@ -84,7 +84,10 @@ * * * @author Jason Carreira + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ConversionErrorInterceptor} instead. */ +@Deprecated public class ConversionErrorInterceptor extends MethodFilterInterceptor { public static final String ORIGINAL_PROPERTY_OVERRIDE = "original.property.override"; diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java index d2cbd0b780..913638913b 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java @@ -29,7 +29,7 @@ /** * *

- * An interceptor that makes sure there are not validation, conversion or action errors before allowing the interceptor chain to continue. + * An interceptor that makes sure there are not validation, conversion or action errors before allowing the interceptor chain to continue. * If a single FieldError or ActionError (including the ones replicated by the Message Store Interceptor in a redirection) is found, the INPUT result will be triggered. * This interceptor does not perform any validation. *

@@ -129,7 +129,10 @@ * @author Alexandru Popescu * @author Philip Luppens * @author tm_jee + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.DefaultWorkflowInterceptor} instead. */ +@Deprecated public class DefaultWorkflowInterceptor extends MethodFilterInterceptor { private static final long serialVersionUID = 7563014655616490865L; diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java index e60550ca69..3bb70bcb8a 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java @@ -20,8 +20,8 @@ import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.struts2.dispatcher.HttpParameters; import java.util.List; @@ -153,7 +153,10 @@ * * @author Matthew E. Porter (matthew dot porter at metissian dot com) * @author Claus Ibsen + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ExceptionMappingInterceptor} instead. */ +@Deprecated public class ExceptionMappingInterceptor extends AbstractInterceptor { private static final Logger LOG = LogManager.getLogger(ExceptionMappingInterceptor.class); diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java index 6ba498b3cb..3f012288c2 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java @@ -59,7 +59,10 @@ * * * @author Jason Carreira + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.LoggingInterceptor} instead. */ +@Deprecated public class LoggingInterceptor extends AbstractInterceptor { private static final Logger LOG = LogManager.getLogger(LoggingInterceptor.class); private static final String FINISH_MESSAGE = "Finishing execution stack for action "; diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java index fa90a315ca..a22075d115 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java @@ -71,10 +71,13 @@ * </action> * * - * + * * @author tm_jee * @version $Date$ $Id$ + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ModelDrivenInterceptor} instead. */ +@Deprecated public class ModelDrivenInterceptor extends AbstractInterceptor { protected boolean refreshModelBeforeResult = false; diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java index c0f83765c2..f33ebf6e27 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java @@ -66,7 +66,10 @@ * ... * </action> * + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ParameterRemoverInterceptor} instead. */ +@Deprecated public class ParameterRemoverInterceptor extends AbstractInterceptor { private static final Logger LOG = LogManager.getLogger(ParameterRemoverInterceptor.class); diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java index 040080824e..0ac840c7a8 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java @@ -19,8 +19,8 @@ package com.opensymphony.xwork2.interceptor; import com.opensymphony.xwork2.ActionInvocation; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -28,7 +28,7 @@ /** *

* A utility class for invoking prefixed methods in action class. - * + * * Interceptors that made use of this class are: *

* * * * - * + * * In DefaultWorkflowInterceptor *

applies only when action implements {@link com.opensymphony.xwork2.Validateable}

*
    @@ -45,12 +45,12 @@ *
  1. else if the action class have validateDo{MethodName}(), it will be invoked
  2. *
  3. no matter if 1] or 2] is performed, if alwaysInvokeValidate property of the interceptor is "true" (which is by default "true"), validate() will be invoked.
  4. *
- * + * * - * - * + * + * * - * + * * In PrepareInterceptor *

Applies only when action implements Preparable

*
    @@ -58,14 +58,14 @@ *
  1. else if the action class have prepareDo(MethodName()}(), it will be invoked
  2. *
  3. no matter if 1] or 2] is performed, if alwaysinvokePrepare property of the interceptor is "true" (which is by default "true"), prepare() will be invoked.
  4. *
- * + * * - * + * * @author Philip Luppens * @author tm_jee */ public class PrefixMethodInvocationUtil { - + private static final Logger LOG = LogManager.getLogger(PrefixMethodInvocationUtil.class); private static final String DEFAULT_INVOCATION_METHODNAME = "execute"; @@ -76,7 +76,7 @@ public class PrefixMethodInvocationUtil { *

* This method will prefix actionInvocation's ActionProxy's * method with prefixes before invoking the prefixed method. - * Order of the prefixes is important, as this method will return once + * Order of the prefixes is important, as this method will return once * a prefixed method is found in the action class. *

* @@ -89,7 +89,7 @@ public class PrefixMethodInvocationUtil { * * *

- * Assuming actionInvocation.getProxy(),getMethod() returns "submit", + * Assuming actionInvocation.getProxy(),getMethod() returns "submit", * the order of invocation would be as follows:- *

* @@ -99,12 +99,12 @@ public class PrefixMethodInvocationUtil { * * *

- * If prepareSubmit() exists, it will be invoked and this method - * will return, prepareDoSubmit() will NOT be invoked. + * If prepareSubmit() exists, it will be invoked and this method + * will return, prepareDoSubmit() will NOT be invoked. *

* *

- * On the other hand, if prepareDoSubmit() does not exists, and + * On the other hand, if prepareDoSubmit() does not exists, and * prepareDoSubmit() exists, it will be invoked. *

* @@ -119,29 +119,32 @@ public class PrefixMethodInvocationUtil { */ public static void invokePrefixMethod(ActionInvocation actionInvocation, String[] prefixes) throws InvocationTargetException, IllegalAccessException { Object action = actionInvocation.getAction(); - + String methodName = actionInvocation.getProxy().getMethod(); - + if (methodName == null) { - // if null returns (possible according to the docs), use the default execute + // if null returns (possible according to the docs), use the default execute methodName = DEFAULT_INVOCATION_METHODNAME; } - + Method method = getPrefixedMethod(prefixes, methodName, action); if (method != null) { method.invoke(action, new Object[0]); } } - - + + public static void invokePrefixMethod(org.apache.struts2.ActionInvocation actionInvocation, String[] prefixes) throws InvocationTargetException, IllegalAccessException { + invokePrefixMethod(ActionInvocation.adapt(actionInvocation), prefixes); + } + /** - * This method returns a {@link Method} in action. The method + * This method returns a {@link Method} in action. The method * returned is found by searching for method in action whose method name * is equals to the result of appending each prefixes * to methodName. Only the first method found will be returned, hence * the order of prefixes is important. If none is found this method * will return null. - * + * * @param prefixes the prefixes to prefix the methodName * @param methodName the method name to be prefixed with prefixes * @param action the action class of which the prefixed method is to be search for. @@ -162,7 +165,7 @@ public static Method getPrefixedMethod(String[] prefixes, String methodName, Obj } return null; } - + /** *

* This method capitalized the first character of methodName. diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java index 4516d760c6..f2a6aef37c 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java @@ -20,8 +20,6 @@ import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.Preparable; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import java.lang.reflect.InvocationTargetException; @@ -98,7 +96,10 @@ * @author Philip Luppens * @author tm_jee * @see com.opensymphony.xwork2.Preparable + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.PrepareInterceptor} instead. */ +@Deprecated public class PrepareInterceptor extends MethodFilterInterceptor { private static final long serialVersionUID = -5216969014510719786L; diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java index 22da179d46..0837d0486a 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java @@ -35,7 +35,7 @@ * *

This interceptor only activates on actions that implement the {@link ScopedModelDriven} interface. If * detected, it will retrieve the model class from the configured scope, then provide it to the Action.

- * + * * * *

Interceptor parameters:

@@ -45,7 +45,7 @@ *