com.opensymphony.xwork2.interceptor
Interface Interceptor

All Superinterfaces:
Serializable
All Known Implementing Classes:
AbstractInterceptor, ActionAutowiringInterceptor, AliasInterceptor, AnnotationValidationInterceptor, AnnotationWorkflowInterceptor, ChainingInterceptor, CheckboxInterceptor, ConversionErrorInterceptor, CookieInterceptor, CreateSessionInterceptor, DebuggingInterceptor, DefaultWorkflowInterceptor, ExceptionMappingInterceptor, ExecuteAndWaitInterceptor, FileUploadInterceptor, I18nInterceptor, LoggingInterceptor, MessageStoreInterceptor, MethodFilterInterceptor, MockInterceptor, ModelDrivenInterceptor, ParameterFilterInterceptor, ParameterRemoverInterceptor, ParametersInterceptor, PortletAwareInterceptor, PortletPreferencesInterceptor, PortletStateInterceptor, PrepareInterceptor, ProfilingActivationInterceptor, RolesInterceptor, ScopedModelDrivenInterceptor, ScopeInterceptor, ServletConfigInterceptor, StaticParametersInterceptor, StrutsConversionErrorInterceptor, TimerInterceptor, TokenInterceptor, TokenSessionStoreInterceptor, ValidationInterceptor

public interface Interceptor
extends Serializable

An interceptor is a stateless class that follows the interceptor pattern, as found in Filter and in AOP languages.

Interceptors are objects that dynamically intercept Action invocations. They provide the developer with the opportunity to define code that can be executed before and/or after the execution of an action. They also have the ability to prevent an action from executing. Interceptors provide developers a way to encapulate common functionality in a re-usable form that can be applied to one or more Actions.

Interceptors must be stateless and not assume that a new instance will be created for each request or Action. Interceptors may choose to either short-circuit the ActionInvocation execution and return a return code (such as Action.SUCCESS), or it may choose to do some processing before and/or after delegating the rest of the procesing using ActionInvocation.invoke().

Interceptor's parameter could be overriden through the following ways :-

Method 1:

 <action name="myAction" class="myActionClass">
   <interceptor-ref name="exception"/>
     <interceptor-ref name="alias"/>
     <interceptor-ref name="params"/>
     <interceptor-ref name="servlet-config"/>
     <interceptor-ref name="prepare"/>
     <interceptor-ref name="i18n"/>
     <interceptor-ref name="chain"/>
     <interceptor-ref name="model-driven"/>
     <interceptor-ref name="fileUpload"/>
     <interceptor-ref name="static-params"/>
     <interceptor-ref name="params"/>
     <interceptor-ref name="conversionError"/>
     <interceptor-ref name="validation">
       <param name="excludeMethods">myValidationExcudeMethod</param>
     </interceptor-ref>
     <interceptor-ref name="workflow">
       <param name="excludeMethods">myWorkflowExcludeMethod</param>
     </interceptor-ref>
 </action>
 
Method 2:
 <action name="myAction" class="myActionClass">
   <interceptor-ref name="defaultStack">
     <param name="validation.excludeMethods">myValidationExcludeMethod</param>
     <param name="workflow.excludeMethods">myWorkflowExcludeMethod</param>
   </interceptor-ref>
 </action>
 

In the first method, the whole default stack is copied and the parameter then changed accordingly.

In the second method, the refer to an existing interceptor-stack, namely default-stack in this example, and override the validator and workflow interceptor excludeMethods typically in this case. Note that in the tag, the name attribute contains a dot (.) the word before the dot(.) specifies the interceptor name whose parameter is to be overriden and the word after the dot (.) specifies the parameter itself. Essetially it is as follows :-

    <interceptor-name>.<parameter-name>
 
Note also that in this case the name attribute is used to indicate an interceptor stack which makes sense as if it is refering to the interceptor itself it would be just using Method 1 describe above.

Version:
$Date: 2006-07-10 02:30:29 +0200 (Mo, 10 Jul 2006) $ $Id: Interceptor.java 1063 2006-07-10 00:30:29Z mrdon $
Author:
Jason Carreira

Method Summary
 void destroy()
          Called to let an interceptor clean up any resources it has allocated.
 void init()
          Called after an interceptor is created, but before any requests are processed using intercept , giving the Interceptor a chance to initialize any needed resources.
 String intercept(ActionInvocation invocation)
          Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the ActionInvocation or to short-circuit the processing and just return a String return code.
 

Method Detail

destroy

void destroy()
Called to let an interceptor clean up any resources it has allocated.


init

void init()
Called after an interceptor is created, but before any requests are processed using intercept , giving the Interceptor a chance to initialize any needed resources.


intercept

String intercept(ActionInvocation invocation)
                 throws Exception
Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the ActionInvocation or to short-circuit the processing and just return a String return code.

Returns:
the return code, either returned from ActionInvocation.invoke(), or from the interceptor itself.
Throws:
Exception - any system-level error, as defined in Action.execute().


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.