Hi,
At the moment if you throw a Fault like this then it will escape the JAXRS runtime. I'll have to add JAXRS in/out fault interceptors
to handle cases like this one which will check if the cause of a given Fault is a WebApplicationException.
The easiest way at the moment is to write a blocking CXF JAXRS RequestFilter and return a Response instance for the request to be
blocked. This filter instance can be registered as a provider from Spring, please see [1] for more info
Cheers, Sergey
[1] http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-Filters
I am using interceptor to check for existence of particular headers. If
headers are not there, then I want to the HTTP response to be a specific
HTTP resonse. But it seems that if I throw a fault, it always it always
returns 500 response. How can I send custom response codes in interceptor?
Here is my sample interceptor:
public class AuthCxfInterceptor extends AbstractPhaseInterceptor<Message>
{
public AuthCxfInterceptor()
{
super(Phase.READ);
}
@Override
public void handleMessage(Message message) throws Fault
{
HashMap pheaders = (HashMap) message.get(Message.PROTOCOL_HEADERS);
Exception unauthException = new
WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
List<?> hdrValues = (List<?>) pheaders.get("myheaderkey");
if (hdrValues.size() < 1)
{
log.info("Missing myheaderkey");
throw new Fault(unauthException);
}
}
--
View this message in context:
http://www.nabble.com/Set-HTTP-Response-in-Interceptor-tp22589098p22589098.html
Sent from the cxf-user mailing list archive at Nabble.com.