users@jersey.java.net

[Jersey] Re: Jersey client errors out on a 204 HTTP status code

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 18 Oct 2011 09:41:43 +0200

Hi Jonathan,

The output message suggests you try to get an entity out of the response,
where no entity should be present for 204. You may want to consume
the response with something like follows to avoid the getEntity call
when not neccessary:

ClientResponse response = webResource/*param setting comes
here*/.post(ClientResponse.class);

if (response.getStatus() == 204) {
   // no need to call response.getEntity here
} else {
   // maybe you want to deal with some more status codes?
}

HTH,

~Jakub


On 17.10.2011 16:51, Jonathan Taub wrote:
>
> The 204 status code indicates a successful response with no body (void
> "return type").
>
> The service I consumed with my client so far all returned a 200 upon
> success.
>
> For whatever reason, the Jersey client throws an error when getting
> the 204 (see below stack trace).
>
> I searched online but couldn't really find anything. Does anyone has
> any clue?
>
> _com.sun.jersey.api.client.UniformInterfaceException_: POST
> http://devserver.com:8080/RecommendationService/setProductViewed?customerid=000bC3gOo0n4ECK2&ean=9781741798050
> returned a response status of 204
>
> at
> com.sun.jersey.api.client.ClientResponse.getEntity(_ClientResponse.java:527_)
> ~[jersey-client-1.4.jar:1.4]
>
> at
> com.sun.jersey.api.client.ClientResponse.getEntity(_ClientResponse.java:505_)
> ~[jersey-client-1.4.jar:1.4]
>
> This electronic mail message contains information that (a) is or
> may be CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE
> PROTECTED
> BY LAW FROM DISCLOSURE, and (b) is intended only for the use of
> the addressee(s) named herein. If you are not an intended
> recipient, please contact the sender immediately and take the
> steps necessary to delete the message completely from your
> computer system.
>
> Not Intended as a Substitute for a Writing: Notwithstanding the
> Uniform Electronic Transaction Act or any other law of similar
> effect, absent an express statement to the contrary, this e-mail
> message, its contents, and any attachments hereto are not
> intended
> to represent an offer or acceptance to enter into a contract and
> are not otherwise intended to bind this sender,
> barnesandnoble.com
> llc, barnesandnoble.com inc. or any other person or entity.
>