Hi
On 23/06/13 18:57, VirtuallyReal wrote:
I am writing a jaxrs app, which uses interceptors to validate the input, as
well as check authentication and authorization of the calling user.
Essentially, my API is annotated such that some arguments can't be null, or
must be within certain range etc, which is enforced by an in-interceptor at
PRE_INVOKE phase. Then I also have the auth checker (subclass of
org.apache.cxf.interceptor.security.AbstractAuthorizingInInterceptor, which
again runs at the same phase). Both of those throw exceptions when they see
something that they do not like. My app also throws exceptions, when
anything goes wrong. My interceptors work just fine. Both authentication
issues as well as input issues are handled properly, by throwing an
exception.My exception mapper is capable of handling exception types thrown
by interceptors as well as from the app. When the App throws the exception,
the exception mapper is called just fine, and I can see a response with a
proper error code and message returned. However, when any of the
interceptors throw an exception, the mapper is not called, and I get an ugly
backtrace with error code of 500.What am I missing? I did find a few similar
questions, though each had a different take, and I did not think any of them
apply. The question boils down to is it possible to map exceptions thrown in
phases other than invoke.Thanks.

The explanation is that CXF interceptors are nor technically part of the JAX-RS model, so the exceptions escaping from CXF intereceptors can be handled by CXF specific fault handlers, and specifically, out fault interceptors, example:

http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutFaultInterceptor.java

what you may want to do is to get the input validation logic handled inside JAX-RS filters, for example:

http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/security/SimpleAuthorizingFilter.java

It simply delegates to CXF interceptor, but manages the exceptions itself, though in other cases exceptions can be thrown out of it and then mapped by exception mappers

HTH, Sergey



--
View this message in context: 
http://cxf.547215.n5.nabble.com/ExceptionMapper-is-not-called-for-exceptions-thrown-from-an-interceptor-tp5729698.html
Sent from the cxf-user mailing list archive at Nabble.com.



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to