users@jersey.java.net

[Jersey] ExceptionMapper for *all* exceptions (used to log the exceptions)

From: phil swenson <phil.swenson_at_gmail.com>
Date: Tue, 15 Jul 2014 15:39:04 -0600

I want my ExceptionMapper to catch all exceptions and log them...

I have an exception mapper like so:

@Provider
public class RestExceptionMapper implements ExceptionMapper<Exception> {
    @Override
    public Response toResponse(Exception e) {
        log(e);
        if (e instanceof WebApplicationException) {
            return ((WebApplicationException) e).getResponse();
        } else {
            return buildResponse(e);
        }


This exception mapper only gets called for non-WebApplication application
exceptions. I would guess that jersey already has a WebApplication
exception mapper which is overriding this one which is causing the problem??

Anyway, how do I make one global exception mapper catch all the exceptions
so I can log them. Or is there another way I should approach this?

Thanks
phil