Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Handling exceptions in a JAX-RS fault interceptor when using Local Transport

$
0
0
Hi,

I am trying to write a Fault Interceptor to handle exceptions both from my
application code from other interceptors. The Interceptor needs to change
the HTTP status code to something appropriate and set the message body with
info that explains the error in more detail (either in JSON or XML
depending on the request mime type).

Many of the examples I have seen modify the HttpResponse using code such as:

HttpServletResponse response = (HttpServletResponse) message
.getExchange().getInMessage()
.get(AbstractHTTPDestination.HTTP_RESPONSE);

however because we have integration tests which use the CXF local transport
rather than HTTP this code doesn't seem to work.

I need a solution which works for both HTTP Local Transport.

Here's the code I have so far but I get a null pointer thrown as the
OutMessage seems to be null..

public class MyFaultInterceptor extends AbstractPhaseInterceptor<Message> {

// outMessage seems to be null!

message.getExchange().getOutMessage().put(Response.class,
response);

message.getInterceptorChain().abort(); // not sure if I need this!

Any help would be much appreciated!

Many thanks

Mandy

Viewing all articles
Browse latest Browse all 5648

Trending Articles