views:

29

answers:

0

I have code similar to the following:

try {
    HttpPost post = new HttpPost(httpsUrl);
    setHeaders(post);

    HttpEntity entity = new StringEntity(request, "UTF-8");

    post.setEntity(entity);

    HttpResponse response = httpclient.execute(post);
    String result = EntityReader.readContent(response.getEntity());
    checkAnswer(result);
    return result;

} catch (Exception e) {
    throw new ZapException("Error executing the http post request: "+e.getMessage(), e);
}

It sends the content of request to a server via POST using a httpclient instance that might have already been used before (it has persistent connections turned on, since we're sending quite some requests to the same server...).

This sometimes fails with a SocketTimeoutException with "Read timed out" as the message. It's not clear to us, why it only fails at some times, when most times it doesn't. What gives?