views:

398

answers:

2

Hi all,

I want to intercept all method invocations to all seam components to see if that would help in logging exceptions. I was thinking that I could do this by getting the list of all components and registered interceptors and simply adding the one I want to that list.

Walter

A: 

Try to override the default ExceptionFilter with your own at a higher precedence.


@Name("org.jboss.seam.web.exceptionFilter")
@Install(precedence = MOCK, classDependencies="javax.faces.context.FacesContext")
@BypassInterceptors
@Filter(within="org.jboss.seam.web.ajax4jsfFilter")
public class ExceptionFilter extends org.jboss.seam.web.ExceptionFilter

  @Override
  protected endWebRequestAfterException(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Exception e)  {
  // here you log exceptions
  }
}
cetnar
Thanks for your response, but I would like to intercept all components even ones that are from asynchronous jobs running in the background. Is it possible to have access to the method, arguments and the result as well?
A: 

Its better to use Seam's Exception handler. This is how you can do it:

@Name("org.jboss.seam.exception.exceptions")
@Scope(ScopeType.APPLICATION)
@Install(precedence = Install.APPLICATION)
@BypassInterceptors
public class ExceptionHandler extends org.jboss.seam.exception.Exceptions {

    public void handle(Exception e) throws Exception {
            //Log your exception here if you want 
            Events.instance().raiseAsynchronousEvent("SomeListener",e.getMessage());
    super.handle(e);
}
Shervin