I am trying to handle errors coming from my backend. handleMessage() is called if an error occurs, but the content is an instance of XmlMessage. I would like to change it to my own answer - just set the response code and add a message.
I did not find any suitable documentation that could tell me how to do this ...
These axometers are designed for REST, but I would also like to handle this in SOAP.
interceptor
public class ErrorHandlerInterceptor extends AbstractPhaseInterceptor<Message> { public ErrorHandlerInterceptor() { super(Phase.POST_LOGICAL); } @Override public void handleMessage(Message message) throws Fault { Response response = Response .status(Response.Status.BAD_REQUEST) .entity("HOW TO GET A MESSAGE FROM AN EXCEPTION IN HERE???") .build(); message.getExchange().put(Response.class, response); } }
context.xml
<bean id="errorHandlerInterceptor" class="cz.cvut.fit.wst.server.interceptor.ErrorHandlerInterceptor" /> <jaxrs:server address="/rest/"> <jaxrs:serviceBeans> <ref bean="restService" /> </jaxrs:serviceBeans> <jaxrs:outFaultInterceptors> <ref bean="errorHandlerInterceptor" /> </jaxrs:outFaultInterceptors> </jaxrs:server>
user219882
source share