1 Reply Latest reply on May 18, 2011 4:45 AM by asiandub

    Graceful handling of expired conversation

    robertgary1

      I'm assuming there must be some graceful way to handle expired conversations that doesn't require an exception to be displayed on the browser. The only answer I've seen so far is to use an error-page in the web.xml. In JBoss AS 6 this doesn't work because the cdi parameter is included in the error page itself, which additionally generates an exception...


      1) Is there a more graceful way to handle conversation timeouts?
      2) Must the conversation ID be passed in the page URL? I'm concerned someone will bookmark the page and then get the exception.


      Like most projects we have a requirement that the customer never see an exception, that we redirect them to an error handling page or put them back where they were.


      -Robert

        • 1. Re: Graceful handling of expired conversation
          asiandub

          Option 1:


          Write your own ExceptionHandlerFactory / ExceptionHandler (and register it in faces-config.xml). Have a look at Seam-Catch how they did it...


          public class MyExceptionHandlerFactory extends ExceptionHandlerFactory {
          ...
          
          public class MyExceptionHandler extends ExceptionHandlerWrapper {
          ...
               private HandledException handleException(Throwable t, FacesContext facesContext) {
                    ResourceBundle messages = this.getMessageBundle(facesContext);
                    List<Throwable> exceptionStack = this.createExceptionStack(t);
                    for (Throwable cause : exceptionStack) {
                         if (cause instanceof NonexistentConversationException) {
                              this.log.debugv(t, "Handling conversation timeout exception {0}", cause.getClass().getName());
                              return new HandledException(messages.getString("error.sessionTimeout"), cause);
                         } else if (cause instanceof ViewExpiredException) {
                              this.log.debugv(t, "Handling session timeout exception {0}", cause.getClass().getName());
                              return new HandledException(messages.getString("error.sessionTimeout"), cause);
                            }
          ...
                    }
                    this.log.errorv(t, "Handling exception {0}", t.getClass().getName());
                    return new HandledException(messages.getString("error.general"), t);
               }
          ...
          }
          




          Option 2:


          Use Seam-Catch :-)


          I used both options (Seam-Catch wasn't released back then), both workes...


          Cheers,


          Jan