Hello Christian,
As you correctly noticed, the section 7.6 of the JAX-RS 2.0 spec mandates that each JAX-RS implementation MUST provide a default handler for BV exception hierarchy AND it MUST let the JAX-RS applications to define their own custom exception mapper for the BV exceptions. IOW, if an application defines it’s own exception mapper for CVE, it MUST be invoked in case of CVE occurs during validation of the resource class, field, property as well as resource method parameter and return type.
To my best knowledge, Jersey that provides JAX-RS RI conforms to the above. If RESTEasy does not conform to the above, it is as a JAX-RS spec compatibility issue that you may want to report to them.
Cheers,
Marek
> On 15 Apr 2015, at 07:21, Christian Kaltepoth <christian_at_kaltepoth.de> wrote:
>
> 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 <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 <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 <https://github.com/chkal/jaxrs-bv>
>
>
> --
> Christian Kaltepoth
> Blog: http://blog.kaltepoth.de/ <http://blog.kaltepoth.de/>
> Twitter: http://twitter.com/chkal <http://twitter.com/chkal>
> GitHub: https://github.com/chkal <https://github.com/chkal>
>