7 Replies Latest reply on Oct 9, 2006 6:17 AM by Peppe Corsaro

    advice on managing exceptions / session timeouts

    Martin Henderson Newbie

      Hi folks,

      I'm currently using seam for a basic webapp.... but it has contstraints in that any fallovers need to be pretty. i.e. should a nullpointerexception be thrown from the code for any reason, I'd like this to forward to a standard error page that has the usual hand holding stuff... I was wondering if anyone had any thoughts on best practices for this?

      I had toyed with a servlet filter but this is causing problems with the conversation context... next thought was an application wide aspect perhaps?

      Hope you can help,

      Thanks,

      Marty

        • 1. Re: advice on managing exceptions / session timeouts
          Gavin King Master

          A servlet filter is the correct solution. I have no idea why this should cause any problem. Of course, you should not try to access the Seam contexts from the filter.

          • 2. Re: advice on managing exceptions / session timeouts
            Martin Henderson Newbie

            thanks for the response Gavin....
            my filter looks like this:

             public void doFilter(ServletRequest servletrequest,
             ServletResponse servletresponse,
             FilterChain filterchain)
             throws IOException, ServletException
             {
             HttpServletRequest httpservletrequest = (HttpServletRequest)servletrequest;
             HttpSession httpsession = httpservletrequest.getSession(false);
            
             try
             {
             filterchain.doFilter(servletrequest, servletresponse);
             log.info("all ok...");
             }
             catch (Throwable t)
             {
             log.info("throwable caught..");
             StringWriter sw = new StringWriter();
             PrintWriter pw = new PrintWriter(sw, true);
             t.printStackTrace(pw);
             pw.flush();
             sw.flush();
             log.error("throwable=" + t.getMessage());
             log.error("stack=" + sw.toString());
            
             HttpServletResponse httpservletresponse = (HttpServletResponse)servletresponse;
             ServletContext servletcontext = config.getServletContext();
             if (getRedirect(redirect))
             {
             httpservletresponse.sendRedirect(redirect);
             }
             else
             {
             RequestDispatcher requestdispatcher = servletcontext.getRequestDispatcher(redirect);
             requestdispatcher.forward(servletrequest, servletresponse);
             }
             }
             }
            

            and the error looks like this:
            java.lang.IllegalStateException: Could not start transaction
             at org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener.beforePhase(Unknown Source)
             at org.apache.myfaces.lifecycle.LifecycleImpl.informPhaseListenersBefore(LifecycleImpl.java:520)
             at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:342)
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
             at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
             at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
             at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
             at org.mhenderson.turnaround.servlets.filter.GenericExceptionServletFilter.doFilter(GenericExceptionServletFilter.java:118)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.mhenderson.turnaround.servlets.filter.SessionExpiryServletFilter.doFilter(SessionExpiryServletFilter.java:99)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(Unknown Source)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
             at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
             at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:157)
             at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
             at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
             at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: javax.transaction.NotSupportedException: Transaction already active, cannot nest transactions.
             at org.jboss.tm.TxManager.begin(TxManager.java:193)
             at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.begin(ServerVMClientUserTransaction.java:110)
             ... 39 more
            


            I'm a bit confused to be honest...

            • 3. Re: advice on managing exceptions / session timeouts
              Gavin King Master

              Looks like you forgot to rollback the txn in your filter. Or something like that.

              • 4. Re: advice on managing exceptions / session timeouts
                Martin Henderson Newbie

                ok... this may be a stupid question... (so apologies in advance)... how do I do that? Or what should I use to do that?

                • 5. Re: advice on managing exceptions / session timeouts
                  Gavin King Master

                  Have you tried/looked at SeamExceptionFilter?

                  • 6. Re: advice on managing exceptions / session timeouts
                    Martin Henderson Newbie

                    just did. Star man.
                    thanks very much for the pointers in the right direction! Really appreciate it.

                    • 7. Re: advice on managing exceptions / session timeouts
                      Peppe Corsaro Newbie

                       

                      "gavin.king@jboss.com" wrote:
                      A servlet filter is the correct solution. I have no idea why this should cause any problem. Of course, you should not try to access the Seam contexts from the filter.


                      Hi Gavin, I took this good example to redirect erros to my custom page. Now I need to know how can I keep the exception object to show it in the error page. Of course, how you said, I cannot use seam contexts. What I have to do?