You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "dineshviswanath@gmail.com" <di...@gmail.com> on 2011/02/05 06:48:27 UTC

ExceptionMapper vs Interceptor

Hi All,
I wanted to know the pros and cons of using Exception Mapper and Interceptor
in CXF REST service. Below I have listed some of the pros and cons with my
limited knowledge on CXF Rest API. Please correct me if am wrong. 

Also Please suggest me which is the best way of handling the exception. 


1. Exception mapper:
Pros:
ExceptionMapper can map the exception to the certain response without
acknowledging the JAXRSInvoker that exception occurred.
Cons:
We cannot map the all runtime (un-checked) exception to the response.
i.e, ExceptionMapper is not able to map the all runtime exception. I tried
this :-)

2. Interceptor:
Pros: 
Cons:
JAXRSInvoker will know that exception occurred and it will try to construct
the response.




-- 
View this message in context: http://cxf.547215.n5.nabble.com/ExceptionMapper-vs-Interceptor-tp3372231p3372231.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: ExceptionMapper vs Interceptor

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

If I were a user and found CXF interceptors were doing exactly what I wanted
then I would worry the least about the lost of total portability which is a
bit unrealistic IMHO any way. It's open source and developers having enough
experience to migrate will spend 30 mins on rewriting the interceptors to
exception mappers.

ExceptionMappers must be able to catch all the exceptions generated
immediately after JAXRSInInterceptor has been invoked, whether generated by
the JAX-RS runtime or by the application filters and code, readers/writers.

If it's not the case then it is a bug - please report it.

Custom CXF out fault interceptors will also catch all the exceptions. When
having a JAX-WS & JAX-RS combined, having CXF fault interceptors can be a
better option, same for custom in/out CXF interceptors vs CXF JAX-RS
filters.
By the way, I believe all the JAX-RS stacks offer the filter support - which
is unlikely to be standardized in the short term.

Sergey

On Sat, Feb 5, 2011 at 10:00 AM, Glen Mazza <gm...@talend.com> wrote:

> ExceptionMapper is also portable across different REST implementations.
>  Usage of interceptors for exception handling may lead to nonstandard,
> project-specific methods of handling exceptions (may need to document more
> for other developers to understand).
>
> Glen
>
>
> On 05.02.2011 00:48, dineshviswanath@gmail.com wrote:
>
>> Hi All,
>> I wanted to know the pros and cons of using Exception Mapper and
>> Interceptor
>> in CXF REST service. Below I have listed some of the pros and cons with my
>> limited knowledge on CXF Rest API. Please correct me if am wrong.
>>
>> Also Please suggest me which is the best way of handling the exception.
>>
>>
>> 1. Exception mapper:
>> Pros:
>> ExceptionMapper can map the exception to the certain response without
>> acknowledging the JAXRSInvoker that exception occurred.
>> Cons:
>> We cannot map the all runtime (un-checked) exception to the response.
>> i.e, ExceptionMapper is not able to map the all runtime exception. I tried
>> this :-)
>>
>> 2. Interceptor:
>> Pros:
>> Cons:
>> JAXRSInvoker will know that exception occurred and it will try to
>> construct
>> the response.
>>
>>
>>
>>
>>
>
> --
> Glen Mazza
> Software Engineer, Talend (http://www.talend.com)
> blog: http://www.jroller.com/gmazza
>
>
>

Re: ExceptionMapper vs Interceptor

Posted by Glen Mazza <gm...@talend.com>.
ExceptionMapper is also portable across different REST implementations.  
Usage of interceptors for exception handling may lead to nonstandard, 
project-specific methods of handling exceptions (may need to document 
more for other developers to understand).

Glen

On 05.02.2011 00:48, dineshviswanath@gmail.com wrote:
> Hi All,
> I wanted to know the pros and cons of using Exception Mapper and Interceptor
> in CXF REST service. Below I have listed some of the pros and cons with my
> limited knowledge on CXF Rest API. Please correct me if am wrong.
>
> Also Please suggest me which is the best way of handling the exception.
>
>
> 1. Exception mapper:
> Pros:
> ExceptionMapper can map the exception to the certain response without
> acknowledging the JAXRSInvoker that exception occurred.
> Cons:
> We cannot map the all runtime (un-checked) exception to the response.
> i.e, ExceptionMapper is not able to map the all runtime exception. I tried
> this :-)
>
> 2. Interceptor:
> Pros:
> Cons:
> JAXRSInvoker will know that exception occurred and it will try to construct
> the response.
>
>
>
>


-- 
Glen Mazza
Software Engineer, Talend (http://www.talend.com)
blog: http://www.jroller.com/gmazza