users@jersey.java.net

[Jersey] Re: ExceptionMapper not being invoked?

From: Mike Summers <msummers57_at_gmail.com>
Date: Thu, 24 May 2012 18:21:02 -0500

Ignore this if you haven't already, this was some Maven/Eclipse issue that
I resolved by deleting the project in Eclipse (without removing sources),
going into the file system and removing all of Eclipse's data in the
project's directories, and re-importing into Eclipse.

They don't call them "tools" for nothing :-(

Sorry for the noise.

On Thu, May 24, 2012 at 12:52 PM, Mike Summers <msummers57_at_gmail.com> wrote:

> I've fought this all morning and I'm stumped, my ExceptionMapper is not
> being invoked and it sure seems like it should be.
>
> Here's the startup log showing the Mapper:
> INFO: Provider classes found:
> class adapter.exceptions.ExceptionMapper
> class adapter.exceptions.WebApplicationExceptionMapper
>
> This is the WebApplicationExceptionMapper... pretty basic:
> import javax.ws.rs.core.Response;
> import javax.ws.rs.ext.ExceptionMapper;
> import javax.ws.rs.ext.Provider;
>
> import org.apache.log4j.Logger;
>
> @Provider
> public class WebApplicationExceptionMapper implements
> ExceptionMapper<javax.ws.rs.WebApplicationException> {
> private static final Logger logger =
> Logger.getLogger(WebApplicationExceptionMapper.class);
>
> @Override
> public Response toResponse(javax.ws.rs.WebApplicationException e) {
> logger.debug("Mapping");
> e.printStackTrace();
> return e.getResponse();
> }
> }
>
> Throw the WebApplicationException:
> throw new
> WebApplicationException(Response.status(response.getStatus()).entity(new
> ErrorResponse(response)).type(MediaType.APPLICATION_XML).build());
>
> See it come back:
> May 24, 2012 12:41:06 PM
> com.sun.jersey.api.container.filter.LoggingFilter$Adapter finish
> INFO: 1 * Server out-bound response
> 1 < 400
> 1 < Content-Type: application/xml
> 1 <
> <?xml version="1.0" encoding="UTF-8"
> standalone="yes"?><error><error_code>CO:400</error_code><error_detail>{error:invalid_grant}</error_detail><error_message>Bad
> Request</error_message></error>
>
> The return is exactly as it should be, but no log4j message or stack trace
> in the server's log. Suggestions?
>
> Thanks-- Mike
>
>