users@jersey.java.net

Setting Response Status

From: Charles Overbeck <coverbec_at_pacbell.net>
Date: Tue, 16 Mar 2010 10:24:30 -0700 (PDT)

Hello,

I have code like this:

@POST
@Produces("text/xml")
@Consumes("text/xml")
public JAXBElement<CurrencyType> addCurrency(CurrencyType newCurrency) {
...
  return <JAXBElement<newlyCreatedCurrency>, where newlyCreatedCurrency may not be exactly the same as newCurrency>
}

Because I am doing a create, I want the HTTP status response code to be 201, but it is 200.

Is there any way I can set the response code to 201, preserving the above method signature?

I know that I can change the method to return a Response, and use ResponseBuilder.status() to explicitly set the status. Previously I was doing that, and all my method signatures returned Reponses. I've since been changing my resource methods to not return Reponses, but the actual type of the entity. The code reads better, and there are tools that can generate better documentation for my REST API.

Are there just some cases, like this one, where I'm going to have to return a Reponse, or is there a way to set the status code here?

Digression: I haven't actually tried any of the documentation tools, and maybe Jersey itself offers something, but briefly looked at the enunciate web page, which looks like it could generate good doc. Does anybody have any experience/recommendations for generating docs for their REST API?

Thanks,

Charles