Após efetuar um session.invalidate na http-session do usuário, recebo um IllegalStateException.
SEVERE: StandardWrapperValve[default]: PWC1406: Servlet.service() for servlet default threw exception
br.com.caelum.vraptor.InterceptionException: java.lang.IllegalStateException: PWC2789: setAttribute:
Session already invalidated
at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:76)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
at br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor.intercept(ParametersInstantiatorInterceptor.java:83)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:45)
[...]
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.process(SSLReadTask.java:440)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.doTask(SSLReadTask.java:228)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: java.lang.IllegalStateException: PWC2789: setAttribute: Session already invalidated
at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1633)
at org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:179)
at br.com.caelum.vraptor.interceptor.FlashInterceptor$1.beforeRedirect(FlashInterceptor.java:48)
at br.com.caelum.vraptor.http.VRaptorResponse.sendRedirect(VRaptorResponse.java:27)
at br.com.caelum.vraptor.view.DefaultPageResult.redirect(DefaultPageResult.java:86)
Analisando o código achei:
response.addRedirectListener(new RedirectListener() {
public void beforeRedirect() {
session.setAttribute(FLASH_INCLUDED_PARAMETERS, result.included());
}
});
No meu caso, como eu invalido a http-session, esse método está tentando adicionar elementos dentro da sessão, porém a mesma está “morta”, e segundo a documentação, uma exception é lançada. Esse método pode ser alterado para fazer um catch ou eu estou fazendo algo errado?
response.addRedirectListener(new RedirectListener() {
public void beforeRedirect() {
try {
session.setAttribute(FLASH_INCLUDED_PARAMETERS, result.included());
} catch(IllegalStateException e) {
// ignore this exception
}
}
});