Hi, For CXF 2.7.8: If your interceptor is called after JAXRSInInterceptor (Phase.UNMARSHAL) for inbound chain and before JAXRSOutInterceptor (Phase.MARSHAL) for outbound chain, you can use normal exception mapper to map exception thrown form interceptor to response (http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-MappingexceptionsthrownfromCXFinterceptors). It is necessary to set "map.cxf.interceptor.fault" contextual property to true.
For CXF 3.0.0 exceptions from all interceptors will go through exception mapper by default. In exeption mapper you will be able to build custom response for the exception. Regards, Andrei. > -----Original Message----- > From: nikosdim [mailto:[email protected]] > Sent: Donnerstag, 16. Januar 2014 15:54 > To: [email protected] > Subject: Custom Response from handleFault [JAX-RS] > > Hi > > I have an inbound interceptor were in a case of an exception I throw a new > Fault(e) exception. > What I want to achieve is to return a custom Response to the client from the > handleFault method of my interceptor. > > I ve tried this but with no luck: > > public class ESMAPISecurityInterceptor extends > AbstractPhaseInterceptor<Message> { > > public ESMAPISecurityInterceptor(String phase) { > super(phase); > } > > @Override > public void handleMessage(Message message) throws Fault { > try { > Class<?> c = Class.forName("an.invalid.class.name"); > } catch (ClassNotFoundException e) { > throw new Fault(e); > } > } > > @Override > public void handleFault(Message message) { > Response response = Response > .status(Status.INTERNAL_SERVER_ERROR) > .type(MediaType.APPLICATION_JSON) > .entity("error message").build(); > message.setContent(Response.class, response); > message.getExchange().put(Response.class, response); > } > } > > Is this possible? Is there any other way that I could return a custom message > back to the client from the handleFault() method? > > Thanks > > > > -- > View this message in context: http://cxf.547215.n5.nabble.com/Custom- > Response-from-handleFault-JAX-RS-tp5738651.html > Sent from the cxf-user mailing list archive at Nabble.com.
