I’m using JAX-RS in my web application to return my own object.
I want to keep doing it, but I want to set the HTTP response code (e.g. 401 for unauthorized, etc.).
From the information I’ve found it seems like I have to return the type Response and not my custom object.
Is that correct?
My current code (simplified) – when MyReponse is an object that Jaxb knows how to deal with:
@POST
@Produces({MediaType.APPLICATION_XML , MediaType.APPLICATION_JSON})
public MyResponse RegisterUser (
@FormParam("userName") String userName,
@FormParam("password") String password) {
// add user logic
return new MyResponse(....<params to ctor...);
}
Yes, you are right.
You’ll need to use something like:
see http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e355 (and other chapters) for additional useful information.