title: Apache HTTP Java Client causing Premature end of Content-Length delimited message body
body: <p>I am trying to solve a very puzzling error. I have the following code executing an HTTP Post to a remove server.</p>
  
  <pre><code>      httpPost.setEntity(new StringEntity(requestAsString));
        HttpResponse httpResponse = httpClient.execute(httpHost, httpPost);
        Arrays.asList(httpResponse.getAllHeaders()).stream().forEach(header -&gt; System.out.println(header.getName() + " : " + header.getValue()));
  
        Thread.sleep(10_000);
  
        List&lt;DataRecord&gt; value = Arrays.asList(objectMapper.readValue(httpResponse.getEntity().getContent(), DataRecord[].class));
  </code></pre>
  
  <p>The response is ~63Mb and this only happens with large responses. When I run this code I get the following error:</p>
  
  <pre><code>com.fasterxml.jackson.databind.JsonMappingException: Premature end of Content-Length delimited message body (expected: 63476765; received: 404420 (through reference chain: java.lang.Object[][1189])
      at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:391)
      at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:363)
      at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:206)
      at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:21)
      at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
      at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3058)
      at com.company.Class1.queryData(Class1.java:74)
      ... 5 more
  Caused by: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 63476765; received: 404420
      at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
      at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:135)
      at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._loadMore(UTF8StreamJsonParser.java:205)
      at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._parseFloat(UTF8StreamJsonParser.java:1524)
      at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._parsePosNumber(UTF8StreamJsonParser.java:1363)
      at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextFieldName(UTF8StreamJsonParser.java:1025)
      at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBind(MapDeserializer.java:448)
      at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:367)
      at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29)
      at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
      at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
      at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
      at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:195)
  </code></pre>
  
  <p>However, this error does not happen if I remove</p>
  
  <pre><code>Thread.sleep(10_000);
  </code></pre>
  
  <p>If the issue was that the client was not getting the full response from the server, I would expect to see the problem exist even if I did not have the Thread sleep in there. The issue also will go away if I shorten the <code>Thread.sleep(...)</code> to only 5 seconds. It seems as though it's a time problem, but since I already have the <code>HttpResponse</code> object before I call <code>Thread.sleep(...)</code>, I can't find anything that could be timing out. Any help with this issue is appreciated.</p>