From c91e03213f1d27e01c32bd9bd6d922139a395593 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 | 3 + .../interceptor/ChainingInterceptor.java | 3 + .../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 | 3 + .../ScopedModelDrivenInterceptor.java | 25 +- .../StaticParametersInterceptor.java | 3 + .../xwork2/util/TextParseUtil.java | 3 + .../xwork2/util/ValueStackFactory.java | 7 +- .../struts2/interceptor/AliasInterceptor.java | 293 ++++++++++++++++ .../interceptor/ChainingInterceptor.java | 275 +++++++++++++++ .../ConversionErrorInterceptor.java | 149 ++++++++ .../DefaultWorkflowInterceptor.java | 245 +++++++++++++ .../ExceptionMappingInterceptor.java | 324 ++++++++++++++++++ .../interceptor/LoggingInterceptor.java | 90 +++++ .../interceptor/ModelDrivenInterceptor.java | 148 ++++++++ .../ParameterRemoverInterceptor.java | 124 +++++++ .../interceptor/PrepareInterceptor.java | 177 ++++++++++ .../ScopedModelDrivenInterceptor.java | 165 +++++++++ .../StaticParametersInterceptor.java | 242 +++++++++++++ 26 files changed, 2332 insertions(+), 45 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 334525d277..943aaacf42 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java @@ -91,7 +91,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); 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 7284dc037d..a21d18c56d 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java @@ -118,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 b549cc0196..21e3d9f659 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java @@ -42,13 +42,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:

@@ -85,7 +85,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 05749ae195..d238e1ceb3 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java @@ -32,7 +32,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. *

@@ -132,7 +132,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 f513deb1c6..84170b6696 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 e4d5af634f..43bb12c2b8 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java @@ -96,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 ae2266be0e..03473034d1 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java @@ -36,7 +36,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:

@@ -46,7 +46,7 @@ *