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

Default WebApplicationException mapper vs custom mappers

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Fri, 28 Aug 2015 11:18:38 +0100

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