user1884155
user1884155

Reputation: 3736

Struts2 letting an interceptor not run for certain classes

I have a custom interceptor. I would like this interceptor to run on all action invocations except a few. I would like to program this (for extendibility/clarity) rather than using if/else statements checking the action's name inside the interceptor's intercept() method itself.

I think it might be done with the "exclude method" capacities of Struts2, but I'm stuck with the exact details. I think my interceptor needs to extend the MethodFilterInterceptor, but it has 2 intercept methods and the API is not very helpful in saying what each should do:

protected abstract String doIntercept(ActionInvocation invocation)

      Subclasses must override to implement the interceptor logic.

String intercept(ActionInvocation invocation)

      Override to handle interception

Upvotes: 0

Views: 245

Answers (2)

Andrea Ligios
Andrea Ligios

Reputation: 50261

You are thinking it the other way around:

instead of checking the Action name (or better, the instanceOf to check for a specific Action Interface) to see if it should do some business, simply tell that Action to use a different Interceptor Stack.

For example, you can say that your Custom Stack (the Stack containing your Interceptor) is the default (then applied to all actions), but that ActionA, ActionB and ActionX run with the DefaultStack...

Upvotes: 3

Dave Newton
Dave Newton

Reputation: 160261

  1. Interceptors shouldn't extend ActionSupport, yuck. They're not actions.
  2. Mark the actions it should (or should not) run for with an interface or annotation and check for that in the interceptor.

Upvotes: 1

Related Questions