users@jersey.java.net

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

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Fri, 25 Jul 2014 13:31:59 +0200

Hi Phil,

Please kindly file a bug/enhancement request for Jersey 2.x.

Thank you,
Marek

On 16 Jul 2014, at 00:16, phil swenson <phil.swenson_at_gmail.com> wrote:

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