users@jersey.java.net

Re: [Jersey] Problem: Jersey swallows all JAXP exceptions silently !

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 24 Jul 2009 08:55:42 +0200

On Jul 24, 2009, at 7:37 AM, Tatu Saloranta wrote:

> On Thu, Jul 23, 2009 at 5:42 PM, Morten<mortench2004_at_yahoo.dk> wrote:
>> Jersey calls into JAXP to marshall returned objects automatically.
>> When it works, this is very nice as it allows clean code like the
>> code below:
>
> I think you mean JAXB, not JAXP?
>
>> HOWEVER, if SomeObject marshalling fails due to a some problem
>> inside SomeObject (f.x. a wrong annotation) then Jersey silently
>> ignores the exception and simply returns an empty result. Even if I
>> install an ExceptionMapper for java.lang.Throwable.
>>
>> This is VERY, VERY annoying as it takes a LOT of time to diagnose
>> and debug such cases. Jersey should not swallow (JAXP) exceptions.
>> At least a valid registered ExceptionMapper should know of them so
>> I can see it, log it and act on it!
> ...
>
> Yes, this can be annoying. Sometimes it is beneficial to just handle
> unmarshalling

marshalling in this case :-)

Note that for JAXB unmarshalling if there is an error a
WebApplicationException(400) will be thrown, with the underlying
JAXBException as the cause.


> part yourself; it's just a line or two more code, but
> you can customize error handling in much more detail.
>

Serializing can be trickier because if an error occurs after some
bytes have been written directly (not buffered) your options are
limited in terms of customizing the error handling.

Paul.


> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>