com.opensymphony.xwork2.interceptor.annotations

## Class AnnotationWorkflowInterceptor

- java.lang.Object
- - org.apache.struts2.interceptor.AbstractInterceptor
  - - com.opensymphony.xwork2.interceptor.AbstractInterceptor
    - - com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor

- All Implemented Interfaces:
    Serializable, ConditionalInterceptor, Interceptor, PreResultListener

      public class AnnotationWorkflowInterceptor
      extends AbstractInterceptor
      implements PreResultListener

  Invokes any annotated methods on the action. Specifically, it supports the following annotations:

  - @`Before` - will be invoked before the action method. If the returned value is not null, it is returned as the action result code
  - @`BeforeResult` - will be invoked after the action method but before the result execution
  - @`After` - will be invoked after the action method and result execution

  There can be multiple methods marked with the same annotations, but the order of their execution is not guaranteed. However, the annotated methods on the superclass chain are guaranteed to be invoked before the annotated method in the current class in the case of a `Before` annotations and after, if the annotations is `After`.

        public class BaseAnnotatedAction {
              protected String log = "";

              @Before
              public String baseBefore() {
                      log = log + "baseBefore-";
                      return null;
              }
        }

        public class AnnotatedAction extends BaseAnnotatedAction {
              @Before
              public String before() {
                      log = log + "before";
                      return null;
              }

              public String execute() {
                      log = log + "-execute";
                      return Action.SUCCESS;
              }

              @BeforeResult
              public void beforeResult() throws Exception {
                      log = log +"-beforeResult";
              }

              @After
              public void after() {
                      log = log + "-after";
              }
        }

  With the interceptor applied and the action executed on `AnnotatedAction` the log instance variable will contain `baseBefore-before-execute-beforeResult-after`.

  Configure a stack in xwork.xml that replaces the PrepareInterceptor with the AnnotationWorkflowInterceptor:

       <interceptor-stack name="annotatedStack">
              <interceptor-ref name="staticParams"/>
              <interceptor-ref name="params"/>
              <interceptor-ref name="conversionError"/>
              <interceptor-ref name="annotationWorkflow"/>
       </interceptor-stack>

  Author:
    Zsolt Szasz, zsolt at lorecraft dot com, Rainer Hermanns, Dan Oxlade, dan d0t oxlade at gmail d0t c0m
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.PreResultListener

      `PreResultListener.LegacyAdapter`

    - ### Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor

      `ConditionalInterceptor.LegacyAdapter`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AnnotationWorkflowInterceptor()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `beforeResult(ActionInvocation invocation, String resultCode)` Invokes any @BeforeResult annotated methods
    `protected static int` | `comparePriorities(int val1, int val2)`
    `String` | `intercept(ActionInvocation invocation)` Discovers annotated methods on the action and calls them according to the workflow

    - ### Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor

      `intercept, shouldIntercept, shouldIntercept`

    - ### Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptor

      `destroy, init, setDisabled`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.opensymphony.xwork2.interceptor.PreResultListener

      `adapt, beforeResult`

    - ### Methods inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor

      `adapt`

    - ### Methods inherited from interface com.opensymphony.xwork2.interceptor.Interceptor

      `adapt`

    - ### Methods inherited from interface org.apache.struts2.interceptor.Interceptor

      `destroy, init`

- - ### Constructor Detail

    - #### AnnotationWorkflowInterceptor

          public AnnotationWorkflowInterceptor()

  - ### Method Detail

    - #### intercept

          public String intercept(ActionInvocation invocation)
                           throws Exception

      Discovers annotated methods on the action and calls them according to the workflow
      Specified by:
        `intercept` in class `AbstractInterceptor`
      Throws:
        `Exception`
      See Also:
        `Interceptor.intercept(com.opensymphony.xwork2.ActionInvocation)`

    - #### comparePriorities

          protected static int comparePriorities(int val1,
                                                 int val2)

    - #### beforeResult

          public void beforeResult(ActionInvocation invocation,
                                   String resultCode)

      Invokes any @BeforeResult annotated methods
      See Also:
        `PreResultListener.beforeResult(com.opensymphony.xwork2.ActionInvocation,String)`

Copyright © 2000–2026 Apache Software Foundation. All rights reserved.