10 Replies Latest reply on Oct 4, 2007 9:51 PM by Shane Bryzak

    can't get it working: exception redirection

    Jonas Erma Newbie

      Hi all,

      I'm trying to redirect a FileUploadException to an error page. I turned off both seam debug mode and facelets development mode. Login redirection to the login page and back to the original page works without any problem.

      I added this to the pages.xml:

      <exception class="org.jboss.seam.web.FileUploadException">
       <end-conversation/>
       <redirect view-id="/errors/fue.seam">
       <message severity="error">File size is above allowable maximum</message>
       </redirect>
      </exception>


      However, I'm still seeing the exception both in the console and browser (as part of HTTP Status 500), and there is no redirection to my error page.

      My application runs on jboss 4.2 with seam cvs.

      What am I missing?

      tazman

        • 1. Re: can't get it working: exception redirection
          Fernando Montaño Expert

          If you are using Facelets (.xhtml as default)

          <exception class="org.jboss.seam.web.FileUploadException">
           <end-conversation/>
           <redirect view-id="/errors/fue.xhtml">
           <message severity="error">File size is above allowable maximum</message>
           </redirect>
          </exception>
          


          if you are using another view technology than Facelets then write the corresponding view-id.



          • 2. Re: can't get it working: exception redirection
            Jonas Erma Newbie

            Hi fernando,

            thanks for your reply. You were right about the view-id. However, it didn't make any difference. The exception is still thrown, and shown by tomcat, instead of being redirected to the error page.

            tazman

            • 3. Re: can't get it working: exception redirection
              Filippo Newbie

              Did you remember to include seam filters in web.xml?

              It works for me. My use case is quite similar to your case even if I run it in a SE environment.

              • 4. Re: can't get it working: exception redirection
                Jonas Erma Newbie

                I have this in my web.xml:

                <!-- Seam -->
                 <listener>
                 <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
                 </listener>
                
                 <filter>
                 <filter-name>Seam Filter</filter-name>
                 <filter-class>org.jboss.seam.web.SeamFilter</filter-class>
                 </filter>
                
                 <filter-mapping>
                 <filter-name>Seam Filter</filter-name>
                 <url-pattern>*.seam</url-pattern>
                 </filter-mapping>


                I thought, all other filters are installed by the main filter. Do I have to include some more filters in my web.xml?

                tazman


                • 5. Re: can't get it working: exception redirection
                  Filippo Newbie

                  Here is my web.xml


                  <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>



                  <listener-class>
                  org.apache.myfaces.webapp.StartupServletContextListener
                  </listener-class>


                  <context-param>
                  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                  <param-value>client</param-value>
                  </context-param>

                  <context-param>
                  <param-name>facelets.DEVELOPMENT</param-name>
                  <param-value>false</param-value>
                  </context-param>

                  <context-param>
                  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                  <param-value>.xhtml</param-value>
                  </context-param>



                  <filter-name>Seam Exception Filter</filter-name>
                  <filter-class>org.jboss.seam.servlet.SeamExceptionFilter</filter-class>



                  <filter-name>Seam Redirect Filter</filter-name>
                  <filter-class>org.jboss.seam.servlet.SeamRedirectFilter</filter-class>


                  <filter-mapping>
                  <filter-name>Seam Exception Filter</filter-name>
                  <url-pattern>/*</url-pattern>
                  </filter-mapping>

                  <filter-mapping>
                  <filter-name>Seam Redirect Filter</filter-name>
                  <url-pattern>*.seam</url-pattern>
                  </filter-mapping>





                  <servlet-name>Faces Servlet</servlet-name>
                  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                  <load-on-startup>1</load-on-startup>

                  <servlet-mapping>
                  <servlet-name>Faces Servlet</servlet-name>
                  <url-pattern>*.seam</url-pattern>
                  </servlet-mapping>


                  <servlet-name>Seam Resource Servlet</servlet-name>
                  <servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet-class>

                  <servlet-mapping>
                  <servlet-name>Seam Resource Servlet</servlet-name>
                  <url-pattern>/seam/resource/*</url-pattern>
                  </servlet-mapping>




                  Hope it helps!

                  • 6. Re: can't get it working: exception redirection
                    Jonas Erma Newbie

                    I think we have quite different configurations. You seem to be using pre jboss 4.2 with myfaces. I ported my application to jboss 4.2 (jsf ri) and am using seam cvs latest.

                    The Seam reference document says (chapter 21.1.3 "Seam servlet filters"):

                    The Seam master filter must be the first filter specified in web.xml. This ensures it is run first.
                    Adding the master filter enables the following built-in filters.


                    and it lists the following filters (including the exception-filter):
                    exception-filter, redirect-filter, multipart-filter, character-encoding-filter, and ajax4jsf-filter

                    Nevertheless, I'll give it a try and explicitly configure the filters in web.xml.

                    tazman

                    • 7. Re: can't get it working: exception redirection
                      Piotr Walczyszyn Newbie

                      Did you manage to solve this problem. I'm facing same thing. It looks like Seam doesn't intercept the exception and I also get Tomcat web page with following stacktrace:


                      java.lang.NullPointerException
                      org.jboss.seam.web.ExceptionFilter.endWebRequestAfterException(ExceptionFilter.java:93)
                      org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:70)
                      org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
                      org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
                      org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
                      org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                      org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                      org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                      org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                      org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
                      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


                      But when I look into log the full staktrace looks like this:

                      09:49:41,937 ERROR [ExceptionFilter] handling uncaught exception
                      org.jboss.seam.web.FileUploadException: Multipart request is larger than allowed
                      size
                      at org.jboss.seam.web.MultipartRequest.<init>(MultipartRequest.java:280)

                      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:80)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:73)
                      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)

                      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.jav
                      a:68)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                      icationFilterChain.java:235)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                      ilterChain.java:206)
                      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
                      lter.java:96)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                      icationFilterChain.java:235)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                      ilterChain.java:206)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                      alve.java:230)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                      alve.java:175)
                      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                      yAssociationValve.java:179)
                      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
                      torBase.java:433)
                      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                      e.java:84)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                      ava:128)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                      ava:104)
                      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
                      onnectionValve.java:157)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                      ve.java:109)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                      a:241)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                      :844)
                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
                      ss(Http11Protocol.java:580)
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
                      7)
                      at java.lang.Thread.run(Thread.java:619)
                      09:49:42,046 ERROR [ExceptionFilter] exception root cause
                      09:49:42,062 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet
                      threw exception
                      java.lang.NullPointerException
                      at org.jboss.seam.web.ExceptionFilter.endWebRequestAfterException(Except
                      ionFilter.java:93)
                      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:70)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:73)
                      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)

                      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.jav
                      a:68)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
                      .java:69)
                      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                      icationFilterChain.java:235)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                      ilterChain.java:206)
                      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
                      lter.java:96)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                      icationFilterChain.java:235)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                      ilterChain.java:206)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                      alve.java:230)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                      alve.java:175)
                      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                      yAssociationValve.java:179)
                      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
                      torBase.java:433)
                      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                      e.java:84)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                      ava:128)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                      ava:104)
                      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
                      onnectionValve.java:157)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                      ve.java:109)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                      a:241)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                      :844)
                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
                      ss(Http11Protocol.java:580)
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
                      7)
                      at java.lang.Thread.run(Thread.java:619)


                      • 8. Re: can't get it working: exception redirection
                        Pete Muir Master

                        Shane fixed this in CVS very recently.

                        • 9. Re: can't get it working: exception redirection
                          Piotr Walczyszyn Newbie

                          I don't think this is fixed, I still get Tomcat error page. I'm running recent CVS version. It looks like org.jboss.seam.web.FileUploadException exception is not intercepted properly. In my pages.xml I have proper handling to redirect me to my own error page.

                          • 10. Re: can't get it working: exception redirection
                            Shane Bryzak Master

                            I've just fixed the following JIRA issue which I believe should address this:

                            http://jira.jboss.com/jira/browse/JBSEAM-1995