1 Reply Latest reply on Sep 27, 2007 7:41 AM by madman1

    How to catch exceptions on ajax4jsf filter?

    Steven De Groote Newbie

      Hi all,

      we have a JSF 1.1 application on Tomcat 6.0.13 and have a problem with exceptions. In fact when an uncaught exception occurs, it is logged but then afterwards tomcat gets stuck in 100% CPU for garbage collection.

      Here is an example error:

      java.io.IOException: FileUtils.WriteToFile failed, got: java.io.FileNotFoundException: C:\test\GEARO\UPLOAD\C:\Documents and Settings\Sede\Desktop\apache-tomcat-6.0.14.zip (The filename, directory name, or volume label syntax is incorrect)
       at be.sofico.web.framework.FileUtil.writeFile(FileUtil.java:73)
       at be.sofico.web.extranet.dynamic.files.CustomerUpload.process(CustomerUpload.java:64)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146)
       at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92)
       at javax.faces.component.UICommand.broadcast(UICommand.java:332)
       at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:186)
       at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:164)
       at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:352)
       at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:595)
      


      You can see we use an ajax4jsf filter. The problem is then that the exception happens but the user is not redirected to an error page. After that, the Tomcat problem occurs until we restart tomcat manually.

      Is there any possibility to catch these exceptions and prevent tomcat from blocking the whole application?

      Thanks

        • 1. Re: How to catch exceptions on ajax4jsf filter?
          madman1 Newbie

          Maybe with something like this.

          public class MyFilter implements Filter{
          
          
           public MyFilter() {
           }
          
           public void destroy() {
           }
          
           public void init(FilterConfig arg0) throws ServletException {
           }
          
           public void doFilter(ServletRequest request, ServletResponse response,
           FilterChain chain) throws IOException, ServletException {
           try {
           chain.doFilter(request, response);
           } catch(Exception e){
           // make log..... or anything
           }
           }
          }


          In your web.xml you should mapped this filter before ajax4jsf filter, and for the
          same url pattern.

          And if you only want to show a best error page, in place of printstack trace.
          There are a proporty in web.xml to do it. I don't remember wich one.

          Sorry for my english.