Hi
On Wed, Apr 13, 2011 at 3:20 PM, vinayc <[email protected]> wrote:
> Hi,
> I am using CXF 2.3.3, and I have a custom cxf "in" interceptor attached to
> a REST service.
> When this interceptor throws an exception, xmlfaultoutinterceptor is
> called.
>
> Yes, that will happen if the exception is thrown from a CXF interceptor,
outside of the JAX-RS scope...
> Is there an existing cxf fault out interceptor that can format the message
> based on the "Accept:" header set by the client since right now even if
> the
> caller is setting "application/json" type, it still returns an "text/xml"
> content back (since its XmlFaultOutIntereceptor that sends the fault back)?
>
>
Can you try the following:
- add a custom out fault interceptor which will delegate internally to an
instance of JAXRSOutInterceptor.handleMessage() and abort the current out
fault chain afterwards ? Before delegating, it should probably do the
following:
1. Get the Exception from the message:
Exception ex = ((Fault)message.getContent(Exception.*class*)).getCause();
2. Next you need to wrap it in JAX-RS Response
You can do it manually:
Response r =
Response.status(status).type("application/json").entity(exceptionObject).build();
or if you have ExceptionMappers then you can use this call:
Response r = JAXRSUtils.convertFaultToResponse(ex,
message.getExchange().getInMessage());
3. Set Response on the message:
message.setContent(List.class, new MessageContentList(r));
4. new JAXRSOutInterceptor.handleMessage(message);
5. message.getInterceptorChain().abort();
that may work
Cheers, Sergey
> Thanks
>
> Regards,
> Vinay
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Handling-exceptions-thrown-by-interceptors-for-rest-calls-tp4300713p4300713.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>