[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13657059#comment-13657059
 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1352:
-----------------------------------------------

---
final InputStream instream = entity.getContent();
try {
    final ContentType contentType = ContentType.getOrDefault(entity);
    Charset charset = contentType.getCharset();
    if (charset == null) {
        charset = HTTP.DEF_CONTENT_CHARSET;
    }
    final StringBuilder b = new StringBuilder();
    final char[] tmp = new char[1024];
    final Reader reader = new InputStreamReader(instream, charset);
    try {
        int l;
        while((l = reader.read(tmp)) != -1) {
            b.append(tmp, 0, l);
        }
    } catch (final ConnectionClosedException ignore) {
    }
    return b.toString();
} finally {
    instream.close();
}
---

Oleg
                
> "Premature end of Content-Length delimited message body ..." when reading 
> entity.
> ---------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1352
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1352
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>    Affects Versions: 4.3 Beta1
>            Reporter: Arūnas Bendoraitis
>
> Simplified sample code which still causes the error:
> HttpClient httpclient = new DecompressingHttpClient();
> HttpGet httpget = new HttpGet("http://www.shaanig.com/";);
> HttpResponse response = httpclient.execute(httpget);
> String responseString = EntityUtils.toString(response.getEntity());
> Error:
> Exception in thread "main" org.apache.http.ConnectionClosedException: 
> Premature end of Content-Length delimited message body (expected: 113531; 
> received: 15329
>       at 
> org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:179)
>       at 
> org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:199)
>       at 
> org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:103)
>       at 
> org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:157)
>       at 
> org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:227)
>       at 
> org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:174)
>       at java.util.zip.InflaterInputStream.close(InflaterInputStream.java:210)
>       at java.util.zip.GZIPInputStream.close(GZIPInputStream.java:111)
>       at org.apache.http.util.EntityUtils.toString(EntityUtils.java:249)
>       at org.apache.http.util.EntityUtils.toString(EntityUtils.java:288)
> This only happens with http://www.shaanig.com/ , I'm not the owner the host, 
> but I would like to execute GET requests to it. Seems like it can't close the 
> stream.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to