users@jsr311.java.net

Re: Telling ExceptionMapper to exclude exceptions

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Tue, 14 Oct 2008 12:43:08 -0400

Paul Sandoz wrote:
>
> On Oct 14, 2008, at 9:09 AM, Paul Sandoz wrote:
>
>>
>> On Oct 14, 2008, at 2:37 AM, cowwoc wrote:
>>
>>> On Oct 13, 2008, at 7:46 PM, Paul Sandoz wrote:
>>>
>>>> On Oct 13, 2008, at 7:15 PM, Marc Hadley wrote:
>>>>
>>>>> On Oct 13, 2008, at 12:07 PM, cowwoc wrote:
>>>>>>
>>>>>> Under Jersey, ExceptionMapper<RuntimeException> gets called even
>>>>>> for Jersey internal exceptions, such as
>>>>>> *com.sun.jersey.api.container.ContainerException.
>>>>>
>>>>> Does the stack trace include a resource or provider method ? I'm
>>>>> wondering about the origin of the exception. You should only be
>>>>> seeing exceptions that originate in the context of a resource or
>>>>> provider method or in the creation of a resource method
>>>>> parameter, field or property value.
>>>>>
>>>>
>>>> I think there is a bug in Jersey it does not differentiate based
>>>> on where the exception originates.
>>>>
>>>> Paul.
>>>
>>>
>>> Section 4.4 of the specification reads:
>>>
>>> When a resource class or provider method throws an exception, the
>>> JAX-RS runtime will attempt to map the
>>> exception to a suitable HTTP response[...]
>>>
>>> so my interpretation is the same as yours, that Jersey should
>>> not be passing these exceptions to ExceptionMapper. Is there a TCK
>>> for JSR311 to ensure that other implementations do not make this
>>> mistake?
>>>
>>
>> There is, but currently it is not covering this aspect. The scope of
>> the TCK will be improved.
>>
>
> BTW i am not sure it is possible to test in the negative, namely to
> induce an exception in the JAX-RS implementation that does not
> originate from a resource class or provider in a platform independent
> manner.
>
> Paul.

    I dont' know how the internal work, but in theory you should be able
to do the following:

1) Configure some static variable "exceptionCaught" to false
2) Throw a Jersey internal exception
3) The ExceptionMapper body should set "exceptionCaught" to true if it
is called
4) Eventually the container should receive either an exception or a
Response. When this happens it should assert(!exceptionCaught);

Gili