7 Replies Latest reply on Apr 4, 2012 2:57 PM by Jason Porter

    seam 3.1 handle session timeout

    kelly goedert Apprentice

      Hi,

       

      I would like to be able to redirect the user to login page with a message saying "your session expired. please login" when his session times out. I have my session timeout set in my web.xml. I am trying to use @Handles like this

       

      {code}

      @HandlesExceptions

      public class ExceptionHandler {

                @Inject

                private FacesContext facesContext;

       

       

                public void handleAuthorizationException(@Handles final CaughtException<AuthorizationException> evt) {

                          try {

                                    facesContext.getExternalContext().redirect("/sample/denied.sm");

                          } catch (final IOException e) {

                                    e.printStackTrace();

                          }

                          evt.handled();

                }

       

        public void handleSessionTimeoutExceptionExpired(@Handles final CaughtException<ViewExpiredException> evt) {

                          try {

                                    facesContext.getExternalContext().redirect("/sample/login.sm");

                          } catch (final IOException e) {

                                    e.printStackTrace();

                          }

                          evt.handled();

                }

      }

      {code}

       

      The method is called correctly but, on redirect I get this exception:

       

      14:12:11,649 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/sample].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception: java.lang.RuntimeException: java.lang.RuntimeException: Exception invoking method [handleSessionTimeoutExceptionExpired] on object [com.sample.utils.ExceptionHandler@540948a7], using arguments [org.jboss.solder.exception.control.CaughtException@2d80f70b]

                at org.jboss.seam.faces.exception.CatchExceptionHandler.handle(CatchExceptionHandler.java:75) [:3.1.0.Final]

                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [:2.1.7-SNAPSHOT]

                at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [:2.1.7-SNAPSHOT]

                at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [:2.1.7-SNAPSHOT]

                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [:2.1.7-SNAPSHOT]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]

                at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.1.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]

                at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [:3.1.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]

                at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74) [:3.1.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]

                at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]

                at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]

                at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]

                at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]

                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]

                at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]

                at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]

                at java.lang.Thread.run(Thread.java:662) [:1.6.0_31]

      Caused by: java.lang.RuntimeException: Exception invoking method [handleSessionTimeoutExceptionExpired] on object [com.sample.utils.ExceptionHandler@540948a7], using arguments [org.jboss.solder.exception.control.CaughtException@2d80f70b]

                at org.jboss.solder.reflection.Reflections.invokeMethod(Reflections.java:480) [:3.1.0.Final]

                at org.jboss.solder.reflection.Reflections.invokeMethod(Reflections.java:403) [:3.1.0.Final]

                at org.jboss.solder.reflection.annotated.InjectableMethod.invoke(InjectableMethod.java:175) [:3.1.0.Final]

                at org.jboss.solder.exception.control.HandlerMethodImpl.notify(HandlerMethodImpl.java:182) [:3.1.0.Final]

                at org.jboss.solder.exception.control.ExceptionHandlerDispatch.executeHandlers(ExceptionHandlerDispatch.java:135) [:3.1.0.Final]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_31]

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_31]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_31]

                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_31]

                at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305) [:6.1.0.Final]

                at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54) [:6.1.0.Final]

                at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163) [:6.1.0.Final]

                at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299) [:6.1.0.Final]

                at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:188) [:6.1.0.Final]

                at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:59) [:6.1.0.Final]

                at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:198) [:6.1.0.Final]

                at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:282) [:6.1.0.Final]

                at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:265) [:6.1.0.Final]

                at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:234) [:6.1.0.Final]

                at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:635) [:6.1.0.Final]

                at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:622) [:6.1.0.Final]

                at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:616) [:6.1.0.Final]

                at org.jboss.seam.faces.exception.CatchExceptionHandler.handle(CatchExceptionHandler.java:71) [:3.1.0.Final]

                ... 32 more

       

      Is it not possible to handle session timeouts this way? Or am I missing something? It appears to me I dont have a facescontext anymore, so how can I solve this?

       

      Thanks

       

      Kelly