users@jersey.java.net

Re: [Jersey] How to tell ExceptionMapper to exclude exceptions?

From: Gili <cowwoc_at_bbs.darktech.org>
Date: Thu, 2 Oct 2008 21:07:07 -0700 (PDT)

I've found a solution that works for now:

@Provider
public class RuntimeExceptionMapper implements
ExceptionMapper<RuntimeException>
{
        @Inject
        private static Exceptions exceptions;

        @Override
        public Response toResponse(RuntimeException exception)
        {
                if (exception instanceof WebApplicationException)
                {
                        WebApplicationException internalException = (WebApplicationException)
exception;
                        return internalException.getResponse();
                }
                ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR);
                builder.type(MediaType.TEXT_PLAIN_TYPE);
                builder.entity(exceptions.getStackTrace(exception));
                return builder.build();
        }
}

This assumes that all internal exceptions (whether thrown by Jersey,
Resteasy or any other implementation) will extend WebApplicationException. I
don't think the specification requires this to be true (any thoughts on
this?), but it seems to at least be the case for Jersey.

Thanks,
Gili



Gili wrote:
>
> Hi,
>
> I want to provide a ExceptionMapper<RuntimeException> that catches all
> RuntimeExceptions except those in packages javax.ws.rs.** or
> com.sun.jersey.**. How do I implement this?
>
> I'm worried this isn't covered by the JSR311 design :(
>
> Thank you,
> Gili
>

-- 
View this message in context: http://n2.nabble.com/How-to-tell-ExceptionMapper-to-exclude-exceptions--tp1140399p1140805.html
Sent from the Jersey mailing list archive at Nabble.com.