We use a javax.ws.rs.ext.ExceptionMapper<Exception>
annotated as @javax.ws.rs.ext.Provider
to handle all exceptions. Internally this ExceptionMapper
is distinguishing between different types of exceptions to determine what information to reveal to the client.
In the case of the javax.validation.ConstraintViolationException
, we return additional information about which field was invalid and why.
We just switched from TomEE 1.7.2 JAX-RS
to TomEE 7.0.0-SNAPSHOT webprofile
.
With TomEE 1.7.2 JAX-RS
we used the openejb.jaxrs.providers.auto=true
system property, our ExceptionMapper
was automatically found and used.
With TomEE 7.0.0-SNAPSHOT webprofile
the property is no longer necessary to benefit from auto discovery.
However the org.apache.cxf.jaxrs.validation.ValidationExceptionMapper
is also discovered and now acts as the preferred ExceptionMapper
for the javax.validation.ConstraintViolationException
. Our own ExceptionMapper
does not run, and the client therefore gets no information about what went wrong during validation.
Our own ExceptionMapper<Exception>
still handles all other exceptions.
ExceptionMapper
I placed my own javax.ws.rs.ext.ExceptionMapper<javax.validation.ConstraintViolationException>
next to my resources, hoping that it takes precedence over the CXF one.
Still the org.apache.cxf.jaxrs.validation.ValidationExceptionMapper
takes precedence.
Update: it turned out that this indeed does the trick. I don't know why my initial test didn't work.
ValidationExceptionMapper
via system.properties
In the changelog of TomEE 7.0.0-SNAPSHOT
I noticed
TOMEE-1336 Support classname.activated = true/false for auto discovered providers
Looking at the corresponding changeset I was hopeful that I could just disable the org.apache.cxf.jaxrs.validation.ValidationExceptionMapper
by adding
org.apache.cxf.jaxrs.validation.ValidationExceptionMapper.activated=false
to our system.properties
.
This remained without effect.
ExceptionMapper
takes precedence?Makes some time now but think it is needed by spec but you can disable it by setting cxf.jaxrs.skip-provider-scanning=true
.
It completely disables auto providers including the scanned ones but then you can control the one you want in openejb-jar.xml
- surely the best and safer solution IMHO cause otherwise you depend a lot of the libs and container setup you use.
There is no priority afaik cause the exception hierarchy is used.
edit: missed a part: you need to impl ExceptionMapper{ValidationException}
otherwise CXF one has higher priority than your own one (Exception is less specific)
edit 2: https://issues.apache.org/jira/browse/TOMEE-1656 for the activated support
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With