users@jersey.java.net

Does Jersey set content-length header field automatically ?

From: James Weir <James.Weir_at_Sun.COM>
Date: Tue, 16 Oct 2007 10:11:17 +0200

Hi,

Just created some client code using HttpURLConnection. I do the
following check on the "content-length" header ....

HttpURLConnection uc = null;

....// i do the request here

if (uc.getContentLength()<=0) {
    logger.error("Reply from the the Web Service has " +
uc.getContentLength() + " bytes");
    // Some sort of error has occurred
    super.setErrorCode(-1);
    super.setErrorMessage("Unable to get the user "+userName);
               
    // Depending upon the Http Response set the correct
    // response message
    super.setResponseMsg("User not found");
    return(null);
}

The server correctly returns JAXB information in the body, however it
seems that the "content-length" header field is not set. Is this
something I need to do explicitly when building the message on the
server side ?. I was hoping that the REST API would set this for me, or
am I being too lazy here :)

Kind Regards
James