-
1. Re: cxf:rsServer - to respond with custom http code
vrlgohel May 29, 2016 11:49 PM (in response to sonyjop)Did you try setting the Exchange headers as,
exchange.getOut.setHeader.(Exchange.HTTP_RESPONSE_CODE, 1001) ?
-
2. Re: cxf:rsServer - to respond with custom http code
sonyjop May 30, 2016 12:10 AM (in response to vrlgohel)Yes I tried. I think that does not work. Instead, there is another approach that worked.
I wrote a custom processor as below: Improvements are required which I am yet to do
public class RSResponseProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
Response response = convertToJaxRs(message);
exchange.getIn().setBody(response);
exchange.getIn().setHeader("Test", "Won't work unless DefaultCxfRsBinding is not replaced with a custom one");
}
private Response convertToJaxRs(Message message)
{
// ResponseBuilder jaxrsResponseBuilder = Response.ok(message.getBody(), MediaType.APPLICATION_JSON);
ResponseBuilder jaxrsResponseBuilder = Response.status(400);
jaxrsResponseBuilder.entity(" { \"message\" : \"There was a problem with the incoming message\" }");
jaxrsResponseBuilder.type(MediaType.APPLICATION_JSON);
//Response.
//jaxrsResponseBuilder.
// jaxrsResponseBuilder.header("header1", "you'll see this");
Response response = jaxrsResponseBuilder.build();
return response;
}
}