There is nothing wrong at all.
204 means "no content", but you are asking to get content as you invoke getEntity. The exception tells your code that your code seems to make a mistake: You first must check whether there actually is content, and only ask the client to give the content when this is possible.
Regards
Markus
From: Daniel Woo [mailto:daniel.y.woo_at_gmail.com]
Sent: Mittwoch, 20. April 2011 05:42
To: users_at_jersey.java.net
Subject: [Jersey] Jersey Client should deem 2XX as normal response without an exception
Hi guys,
In com.sun.jersey.api.client.ClientResponse, why do we throw an exception for 204? Most of the Rest web services will return a 204 if you don't expect anything. e.g. Do a heart beat with a server with HEAD request, expect 204 response. 204 is exactly a normal case and should not throw an exception. I am calling a lot of Rest service URLs returning 204 and I have to patch the jersey client to make it work. Actually according to HTTP spec, all 2XX are success response, if you violate this rule what makes 204 so special? Should you throw an exception for 201~299? :-)
See the line 527 below
526 private <T> T getEntity(Class<T> c, Type type) {
527 if (getStatus() == 204) {
528 throw new UniformInterfaceException(this);
529 }
530
531 MediaType mediaType = getType();
532 if (mediaType == null) {
533 mediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
534 }
--
Thanks & Regards,
Daniel