Hey all,
I've a question for you.
Imagine a resource class which uses Bean Validation annotations for
defining constraints. See this example:
https://github.com/chkal/jaxrs-bv/blob/master/src/main/java/de/chkal/jaxrs/MyResource.java#L12
Does the spec require that a user should be able to define a custom
ExceptionMapper for ConstraintViolationExceptions to handle validation
failures? See this ExceptionMapper as an example:
https://github.com/chkal/jaxrs-bv/blob/master/src/main/java/de/chkal/jaxrs/MyExceptionMapper.java#L9
I'm asking this because the scenario described above doesn't work in
RESTEasy. It looks like RESTEasy throws some custom exception type instead
of the raw ConstraintViolationException which basically means that the
ExceptionMapper isn't applied.
The relevant sentences from the spec are:
- Section 7.6: JAX-RS implementations MUST provide a default exception
mapper [...] for javax.validation.ValidationException [...]
- Section 7.6: [...] applications can provide their own exception
mappers and, consequently, customize the default mapper described above.
- Section 4.4: When choosing an exception mapping provider to map an
exception, an implementation MUST use the provider whose generic type is
the nearest superclass of the exception.
However, there is IMO nothing in the spec requiring that the JAX-RS
implementation throws the raw Bean Validation exception type.
Any thoughts on this?
Christian
PS: You will find the example application which is deployable to any
JavaEE7 compatible container here:
https://github.com/chkal/jaxrs-bv
--
Christian Kaltepoth
Blog: http://blog.kaltepoth.de/
Twitter: http://twitter.com/chkal
GitHub: https://github.com/chkal