Hi
On 13/12/13 14:03, Winnebeck, Jason wrote:
In my application I wanted to catch any unhandled exceptions from my JAX-RS methods 
to customize the response. So I created a class UnhandledExceptionMapper implements 
ExceptionMapper<Exception> and register it as a provider. This works fine, even 
my other providers with more specific exceptions are used in preference. However, the 
UnhandledExceptionMapper also is catching WebApplicationExceptions, even those thrown 
by CXF itself (such as what happens with invalid media type). How can I delegate to 
the default behavior in a standard JAX-RS way? Rethrowing the WebApplicationException 
doesn't work (it gets caught by the container)?

Right now my workaround is to instantiate directly a 
org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper in my mapper, and if the exception caught 
is a WebApplicationException, delegate to the CXF. But this is not "portable", and maybe 
I've missed other built-in exception handlers. Is there a way I can catch "all exceptions not 
handled by another exception mapper" so I catch things like NullPointerException, 
IllegalArgumentException, etc. but not catch ones otherwise handled?

I guess the most portable way is to convert this caught WebApplicationException into response, simply return caughtWebApplicationException.getResponse() from your catch-all mapper

Cheers. Sergey
Jason Winnebeck

----------------------------------------------------------------------
This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.


Reply via email to