You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Peter Lynch <pe...@Tangoe.com> on 2005/10/18 16:19:37 UTC

IOException: Chunked stream ended unexpectedly

I am using HTTPClient and I am getting the following exception:

 

2005-10-18 10:13:34,738 ERROR HttpMethodBase - I/O failure reading response
body

java.io.IOException: chunked stream ended unexpectedly

        at
org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream
(ChunkedInputStream.java:234)

        at
org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStrea
m.java:205)

        at
org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.jav
a:160)

        at java.io.FilterInputStream.read(FilterInputStream.java:109)

        at
org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream
.java:110)

        at java.io.FilterInputStream.read(FilterInputStream.java:88)

        at
org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream
.java:129)

        at
org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMethodBase.
java:702)

 

I can see most of the page in the wire trace log.  I am not interested in
either displaying the page or in making sure I get everything on the page.
I am only interested in pulling a single bit of information from the page.
The wire trace log seems to display the information I need 100% of the time
but I seem unable to get any of the response body.  Any ideas?

 

Thanks,

Peter


Re: IOException: Chunked stream ended unexpectedly

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2005-10-18 at 10:19 -0400, Peter Lynch wrote: 
> I am using HTTPClient and I am getting the following exception:
> 
>  
> 
> 2005-10-18 10:13:34,738 ERROR HttpMethodBase - I/O failure reading response
> body
> 
> java.io.IOException: chunked stream ended unexpectedly
> 
>         at
> org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream
> (ChunkedInputStream.java:234)
> 
>         at
> org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStrea
> m.java:205)
> 
>         at
> org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.jav
> a:160)
> 
>         at java.io.FilterInputStream.read(FilterInputStream.java:109)
> 
>         at
> org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream
> .java:110)
> 
>         at java.io.FilterInputStream.read(FilterInputStream.java:88)
> 
>         at
> org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream
> .java:129)
> 
>         at
> org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMethodBase.
> java:702)
> 
>  
> 
> I can see most of the page in the wire trace log.  I am not interested in
> either displaying the page or in making sure I get everything on the page.
> I am only interested in pulling a single bit of information from the page.
> The wire trace log seems to display the information I need 100% of the time
> but I seem unable to get any of the response body.  Any ideas?
> 

Peter,
You are not able to get the response body because the content sent by
the server appears malformed (incorrectly chunk-encoded). HttpClient
always attempts to read responses in their entirety in order to be able
to reuse the connection. If a response is not fully consumed the
connection used to transmit it cannot be reused for obvious reasons. 

In this particular situation you may want to consume the response as
InputStream (by using HttpMethod#getResponseBodyAsSteam instead of
HttpMethod#getResponseBody that buffers the entire response body in
memory and returns it as array of bytes), read as much of it as you see
fit, and than call HttpMethod#abort() to abnormally terminate the
connection

Hope this helps

Oleg

>  
> 
> Thanks,
> 
> Peter
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org