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 22, 2024
1 parent deb6c09 commit 45a1f5e
Show file tree
Hide file tree
Showing 23 changed files with 2,308 additions and 40 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* <p>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.</p>
*
*
* <!-- END SNIPPET: description -->
*
* <p><u>Interceptor parameters:</u></p>
Expand All @@ -46,7 +46,7 @@
* <ul>
*
* <li>className - The model class name. Defaults to the class name of the object returned by the getModel() method.</li>
*
*
* <li>name - The key to use when storing or retrieving the instance in a scope. Defaults to the model
* class name.</li>
*
Expand All @@ -67,42 +67,45 @@
*
* <pre>
* <!-- START SNIPPET: example -->
*
*
* &lt;-- Basic usage --&gt;
* &lt;interceptor name="scopedModelDriven" class="com.opensymphony.interceptor.ScopedModelDrivenInterceptor" /&gt;
*
*
* &lt;-- Using all available parameters --&gt;
* &lt;interceptor name="gangsterForm" class="com.opensymphony.interceptor.ScopedModelDrivenInterceptor"&gt;
* &lt;param name="scope"&gt;session&lt;/param&gt;
* &lt;param name="name"&gt;gangsterForm&lt;/param&gt;
* &lt;param name="className"&gt;com.opensymphony.example.GangsterForm&lt;/param&gt;
* &lt;/interceptor&gt;
*
*
* <!-- END SNIPPET: example -->
* </pre>
*
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ScopedModelDrivenInterceptor} instead.
*/
@Deprecated
public class ScopedModelDrivenInterceptor extends AbstractInterceptor {

private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];

private static final String GET_MODEL = "getModel";
private String scope;
private String name;
private String className;
private ObjectFactory objectFactory;

@Inject
public void setObjectFactory(ObjectFactory factory) {
this.objectFactory = factory;
}

protected Object resolveModel(ObjectFactory factory, ActionContext actionContext, String modelClassName, String modelScope, String modelName) throws Exception {
Object model;
Map<String, Object> scopeMap = actionContext.getContextMap();
if ("session".equals(modelScope)) {
scopeMap = actionContext.getSession();
}

model = scopeMap.get(modelName);
if (model == null) {
model = factory.buildBean(modelClassName, null);
Expand All @@ -120,7 +123,7 @@ public String intercept(ActionInvocation invocation) throws Exception {
if (modelDriven.getModel() == null) {
ActionContext ctx = ActionContext.getContext();
ActionConfig config = invocation.getProxy().getConfig();

String cName = className;
if (cName == null) {
try {
Expand Down Expand Up @@ -162,5 +165,5 @@ public void setName(String name) {
*/
public void setScope(String scope) {
this.scope = scope;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@
* </pre>
*
* @author Patrick Lightbody
*
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.StaticParametersInterceptor} instead.
*/
@Deprecated
public class StaticParametersInterceptor extends AbstractInterceptor {

private boolean parse;
Expand Down
Loading

0 comments on commit 45a1f5e

Please sign in to comment.