I have a project that is using struts 2 TokenSessionStoreInterceptor
. I assumed this interceptor would display an action error in the event it deemed the token invalid (cases where it isn't just a double submit but the token never existed). I noticed that the parent class TokenInterceptor
has a resouce key you can override to provide internationalization or a custom error message. Is there a way to have the TokenSessionStoreInterceptor
use this same resource key?
I ended up extending the TokenSessionStoreInterceptor
with my own class and only overriding the handleInvalidToken()
method, calling super and if super returned an invalid token result adding an action error. Such as what I have below:
public class CustomTokenSessionStoreInterceptor extends TokenSessionStoreInterceptor {
@Override
protected String handleInvalidToken(final ActionInvocation invocation) throws Exception {
final String result = super.handleInvalidToken(invocation);
if (INVALID_TOKEN_CODE.equals(result)) {
final String errorMessage = this.getErrorMessage(invocation);
Object action = invocation.getAction();
if (action instanceof ValidationAware) {
((ValidationAware) action).addActionError(errorMessage);
}
}
return result;
}
}
I'm surpised that this isn't done by default, is there a built in way to provide this functionality?