users@jersey.java.net

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

From: Gili <cowwoc_at_bbs.darktech.org>
Date: Fri, 3 Oct 2008 05:55:08 -0700 (PDT)

This is definitely problematic. I posted this RFE on the jsr311 mailing
list. Hopefully they'll add it in before their final release.

Gili


Paul Sandoz wrote:
>
> Hi Gili,
>
> It is currently not possible to limit trapping of exceptions to
> certain packages.
>
> On Oct 3, 2008, at 5:07 AM, Gili wrote:
>
>>
>> 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.
>
> WebApplicationException is only mapped if there is no entity present
> (i need to check if this matches the specified behaviour).
>
> Jersey also throws ContainerException that is for the HTTP containers
> to catch, for example the Servlet container will re-throw that as a
> wrapped ServletException. But in your case you still might want to
> trap this.
>
> The set of RuntimeException classes that may be thrown is
> implementation specific.
>
> Paul.
>
>> 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.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>

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