3
votes

I want my ExceptionMapper to catch all exceptions and log them... I'm using Jersey 2.0 right now.

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.

How do I make one global exception mapper catch all the exceptions so I can log them. Is there another way I should approach this?

Thanks

1
I am using similar logging mapper with Jersey 2.16 and it receives subclasses of WebApplicationException. Seems it was fixed somewhere between 2.0 and 2.16 and this question is no longer relevant.Oleg Estekhin
I have the same problem with jersey 2.24Shibashis

1 Answers

1
votes

Judging from the source code of Jersey where this is handled there is no way to do this with an ExceptionMapper. WebApplicationExceptions get a special treatment are never mapped.

A way to log all exceptions is to set the logger org.glassfish.jersey.server.ServerRuntime to FINER.