<<As far as I can tell, I can't set the status code if I just return a java
object. What is the best strategy for returning an object AND setting the
status code? >>
David,
Here is what works for me. I return my custom java object (as code supports
REST and SOAP too), and set the Response code like here:
//JAX-RS and JAX-WS context
@javax.ws.rs.core.Context
MessageContext resp;
private void setHTTPResponseCode(int statusCode) {
// HttpServletResponse.SC_CREATED--> Status code (201)
// HttpServletResponse.SC_NO_CONTENT --> Status code (204)
// HttpServletResponse.SC_BAD_REQUEST --> Status code (400)
// HttpServletResponse.SC_UNAUTHORIZED --> Status code (401)
// HttpServletResponse.SC_NOT_FOUND --> Status code (404)
// HttpServletResponse.SC_CONFLICT --> Status code (409)
HttpServletResponse r1 = resp.getHttpServletResponse();
r1.setStatus(statusCode);
}
Then, I call this method in my methods and set the appropriate Status Code,
this overrides the default 200 (always) when we return our own java object.
Works great for me.
Hope this helps.
Sergey, if you see any issues with this, do let us know :)
Thanks!
--
View this message in context:
http://cxf.547215.n5.nabble.com/JAX-RS-send-a-specific-object-in-response-set-status-code-tp5086867p5095044.html
Sent from the cxf-user mailing list archive at Nabble.com.