Alireza Fattahi
Alireza Fattahi

Reputation: 45475

Override an struts 2 interceptor

We are using the store interceptor. In some rare cases it happens that this interceptor throws Session Already Invalidate exception, while try to put error messages in session (MessageStoreInterceptor line: 282).

I tried to override this interceptor and silently shallow the exception, and let the action be executed.

It seems to be simple but I can not find what should I return when exception happens ( how do I get the next interceptor?!) :

public class MyMessageStoreInterceptor extends MessageStoreInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {

        try{
            return super.intercept(invocation);
        }catch(IllegalStateException ex){
            return ??; 
        }

    }    
}

Upvotes: 1

Views: 580

Answers (1)

Roman C
Roman C

Reputation: 1

If you want to get to the next interceptor you should return invocation.invoke(). It returns an action result. If you didn't get a result due to the exception, and you want to continue the action invocation, you should return your own result or one of the predefined results such as SUCCESS or ERROR.

@Override
public String intercept(ActionInvocation invocation) throws Exception {

    try{
        return super.intercept(invocation);
    }catch(IllegalStateException ex){
        return Action.ERROR; 
    }

}    

Upvotes: 2

Related Questions