I am stumped about this, so I thought I'd ask in case any of you have come across it, since HttpClient development is a little bit of an art.
The problem I am facing is this: An application is using the Apache HttpClient Java library to communicate to a server in the same company network. Most of the time it works without a problem, but on occasion we'll see a barrage of exceptions caused by incomplete responses: They're all missing the last three characters of the closing tag, so the parser in the client complains. This lasts for maybe 5 to 10 minutes and then goes away.
I haven't been able to replicate this problem locally, and I have verified the response is written completely by the server. The client is obtaining the response content with the PostMethod's getResponseBodyAsStream() method, but it's called only once. Maybe it needs to loop calling this method until it gets null for the rare occasion when the response is buffered?
I'll appreciate any input.
Edit: The server is writing the content-length header and flushing correctly, and at the client, data is read into a String with:
//method is a PostMethod, client is a HttpClient
client.executeMethod(hostconfig, method);
InputStream is = method.getResponseBodyAsStream();
String response = null;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) > 0) {
bos.write(buf, 0, len);
}
response = new String(bos.toByteArray(), "UTF-8");
} ... // closing try block