jsr370-experts@jax-rs-spec.java.net

Re: [jax-rs-spec users] Default WebApplicationException mapper vs custom mappers

From: Santiago Pericasgeertsen <santiago.pericasgeertsen_at_oracle.com>
Date: Fri, 28 Aug 2015 09:34:40 -0400

Hi Sergey,

 I believe what you’re describing it’s the expected behavior. There are a number of extension points that applications can tap into that can impact the runtime (filters, reader/writers, etc.). The spec talks about throwing exceptions, how exceptions are handled depends on how the application is configured.

 In your example, it may be that a certain application wants to catch that exception and return a redirect status code to maintain backward compatibility with some old clients.

— Santiago

> On Aug 28, 2015, at 6:18 AM, Sergey Beryozkin <sberyozkin_at_talend.com> wrote:
>
> Hi
>
> The spec talks about returning HTTP error statuses in a number of cases.
>
> In CXF this is realized by the runtime throwing WebApplicationException (or its subclasses) and having a default WebApplicationExceptionMapper<WebApplicationException> which converts the exception.
>
> What occurred to me right now is that well, if a user registers its own custom WebApplicationExceptionMapper, then this custom mapper may in principle may get the runtime becoming non-compliant.
>
> For example, if the resource has no method matching a given path then NotFoundException is thrown (by CXF at least) and the default mapper which CXF ships handles it and converts to 404. What if a custom NotFoundException mapper is available and it sets 400 ? This example is probably a bit unrealistic because it mapping NotFoundException is unlikely to be treated differently by different mappers, but with other exceptions it is possible in principle.
>
> My question is:
> - Can the runtime allow custom exception mappers deal with exception such as NotFoundException that are thrown by the runtime itself ?
>
> I.e, has the runtime make sure that when it enforces all the spec related error conditions *it does not throw the exceptions* because if it does then the custom mapper can always catch it first; or if it does throw the exception in such cases it make sure the code which maps exceptions to exception mappers is bypassed ?
>
>
> Thanks, Sergey