Apache CXF: how to return an interceptor reject response

I wrote a special interceptor that does some parameter checking. I want to be able to return the error code and serialize the JAXB-annotated class as the response body.

If I throw a WebApplicationException, it has no special handling to serialize the Response object inside (which makes sense, I assume this is done by another interceptor).

How should I stop the chain of interceptors, but still JAXB serializes the response object?

+5
source share
1 answer

Well, at least in the JXX-CXF interceptor thread, if you installed:

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

... , . CXF, , .

, :

Response response = Response
    .status(Response.Status.FORBIDDEN)
    .entity(new ErrorEntity("This is a JAXB object with an error string"))
    .build();

, CXF JAX-RS-, , , PRE_INVOKE.

+3

All Articles