Skip to content

Commit

Permalink
WW-3714 Deprecate and migrate assorted Interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Oct 17, 2024
1 parent 717046f commit 1b86f8d
Show file tree
Hide file tree
Showing 26 changed files with 2,332 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
* </pre>
*
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
* </p>
*
*
* <p>
* <b>Note:</b> 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.
* </p>
*
*
* <!-- END SNIPPET: description -->
*
* <p><u>Interceptor parameters:</u></p>
Expand Down Expand Up @@ -85,7 +85,10 @@
* </pre>
*
* @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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* <!-- START SNIPPET: description -->
* <p>
* 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.
* <b>This interceptor does not perform any validation</b>.
* </p>
Expand Down Expand Up @@ -132,7 +132,10 @@
* @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
* </pre>
*
* @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 ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@
* &lt;/action&gt;
* <!-- END SNIPPET: example -->
* </pre>
*
*
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
* ...
* &lt;/action&gt;
* </pre>
*
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
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;

/**
* <p>
* A utility class for invoking prefixed methods in action class.
*
*
* Interceptors that made use of this class are:
* </p>
* <ul>
Expand All @@ -37,35 +37,35 @@
* </ul>
* *
* <!-- START SNIPPET: javadocDefaultWorkflowInterceptor -->
*
*
* <b>In DefaultWorkflowInterceptor</b>
* <p>applies only when action implements {@link com.opensymphony.xwork2.Validateable}</p>
* <ol>
* <li>if the action class have validate{MethodName}(), it will be invoked</li>
* <li>else if the action class have validateDo{MethodName}(), it will be invoked</li>
* <li>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.</li>
* </ol>
*
*
* <!-- END SNIPPET: javadocDefaultWorkflowInterceptor -->
*
*
*
*
* <!-- START SNIPPET: javadocPrepareInterceptor -->
*
*
* <b>In PrepareInterceptor</b>
* <p>Applies only when action implements Preparable</p>
* <ol>
* <li>if the action class have prepare{MethodName}(), it will be invoked</li>
* <li>else if the action class have prepareDo(MethodName()}(), it will be invoked</li>
* <li>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.</li>
* </ol>
*
*
* <!-- END SNIPPET: javadocPrepareInterceptor -->
*
*
* @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";
Expand All @@ -76,7 +76,7 @@ public class PrefixMethodInvocationUtil {
* <p>
* This method will prefix <code>actionInvocation</code>'s <code>ActionProxy</code>'s
* <code>method</code> with <code>prefixes</code> before invoking the prefixed method.
* Order of the <code>prefixes</code> is important, as this method will return once
* Order of the <code>prefixes</code> is important, as this method will return once
* a prefixed method is found in the action class.
* </p>
*
Expand All @@ -89,7 +89,7 @@ public class PrefixMethodInvocationUtil {
* </pre>
*
* <p>
* Assuming <code>actionInvocation.getProxy(),getMethod()</code> returns "submit",
* Assuming <code>actionInvocation.getProxy(),getMethod()</code> returns "submit",
* the order of invocation would be as follows:-
* </p>
*
Expand All @@ -99,12 +99,12 @@ public class PrefixMethodInvocationUtil {
* </ol>
*
* <p>
* If <code>prepareSubmit()</code> exists, it will be invoked and this method
* will return, <code>prepareDoSubmit()</code> will NOT be invoked.
* If <code>prepareSubmit()</code> exists, it will be invoked and this method
* will return, <code>prepareDoSubmit()</code> will NOT be invoked.
* </p>
*
* <p>
* On the other hand, if <code>prepareDoSubmit()</code> does not exists, and
* On the other hand, if <code>prepareDoSubmit()</code> does not exists, and
* <code>prepareDoSubmit()</code> exists, it will be invoked.
* </p>
*
Expand All @@ -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 <code>action</code>. The method
* This method returns a {@link Method} in <code>action</code>. The method
* returned is found by searching for method in <code>action</code> whose method name
* is equals to the result of appending each <code>prefixes</code>
* to <code>methodName</code>. Only the first method found will be returned, hence
* the order of <code>prefixes</code> is important. If none is found this method
* will return null.
*
*
* @param prefixes the prefixes to prefix the <code>methodName</code>
* @param methodName the method name to be prefixed with <code>prefixes</code>
* @param action the action class of which the prefixed method is to be search for.
Expand All @@ -162,7 +165,7 @@ public static Method getPrefixedMethod(String[] prefixes, String methodName, Obj
}
return null;
}

/**
* <p>
* This method capitalized the first character of <code>methodName</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1b86f8d

Please sign in to comment.