users@jersey.java.net

[Jersey] Jersey Client should deem 2XX as normal response without an exception

From: Daniel Woo <daniel.y.woo_at_gmail.com>
Date: Wed, 20 Apr 2011 11:42:29 +0800

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