Struts 2 Tutorial Series: Illustration for Struts 2 Interceptors

After understanding how action works under Struts 2 framework, it's time to understand another important concept of the framework - Interceptor. Interceptor is used for separating different concerns(e.g. logging) and improve MVC designs(e.g. let action only dealing with model level functions).

First of all here is a diagram from Manning book. It mainly shows that ActionInvocation class encapsulate the execution of an action with its associated interceptors and results.

Struts2 Interceptor

ActionInvocation class plays an essential role for interceptors. The diagram below demonstrate how the ActionInvocation controls the interceptors' execution.

From the diagram, we can observe:

  1. Framework calls invoke() method in ActionInvocation class.
  2. invoke() method starts from the first interceptor in stack.
  3. intercept() method from AuthenticationInterceptor is invoked

intercept() method determins whether invocation is invoked for next interceptor.

There is a state variable which records what interceptor it should execute next. So ActionInvocation is responsible for remembering the current state.

Struts2 ActionInvocation

Question: why is this a recursive process? Answer is in the diagram above.

Category >> Struts 2  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>

  1. fsdfs on 2014-2-12

    dffs

Leave a comment

*