users@jersey.java.net

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

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

I’m guessing something changed from jersey 1 to 2… I see lots of examples
of ExceptionMapper implements ExceptionMapper<Throwable>… but in Jersey 2.0
Throwable doesn’t compile.

So is there a way to implement an exception mapper for a descendent of
WebApplicaitonException?

thanks
phil


On Tue, Jul 15, 2014 at 3:39 PM, phil swenson <phil.swenson_at_gmail.com>
wrote:

> 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
>