You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Jan Bracker <ja...@googlemail.com> on 2008/04/17 11:40:33 UTC

HttpEntity.consumeContent() needs to much time. (HC 4.0 beta)

Hello,

i'm using the DefaultHttpClient for downloading bigger files. When i
want to abort a download i call response.getEntity().consumeContent()
(I assume that is what i should do if i want to close connections of
HttpClient). But the longer content downloaded on that connections get
the more time it takes to close the given connection.

I allready looked at source and found the problem within
ChunkedInputStream. consumeContent() calls close() to the InputStream
and that close results in a call of exhaustInputStream() and that
reads the complete rest of content sent by the host.

Why is this implemented like that? Why not just close the
connection/stream? This behaviour is very annoying when wanting to
stop a request that leads to a response entity of severel megabytes,
especially on connections that are volume payed or have a slow
bandwidth.

Is there a way to close the connection (consumeContent) of my current
response without having to read the complete content? How do i solve
my problem of closing connections quick and abrupt?

Greetings, Jan Bracker

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


Re: HttpEntity.consumeContent() needs to much time. (HC 4.0 beta)

Posted by Jan Bracker <ja...@googlemail.com>.
Thank you, that solved my problem.

2008/4/17, Sebastiaan van Erk <se...@sebster.com>:
> Jan Bracker wrote:
>
> >
> > >  > (I assume that is what i should do if i want to close connections of
> > >  > HttpClient). But the longer content downloaded on that connections
> get
> > >  > the more time it takes to close the given connection.
> > >  >
> > >
> > >
> > > Please use #abort method instead.
> > >
> >
> > I can't find any #abort methode within DefaultHttpClient, HttpResponse
> > or HttpEntity and InputStream does not support such a method either.
> > Are you sure you are talking about version 4.0? As said in the subject
> > i am using HttpComponents 4.0 beta. As looking through 3.1 javadoc i
> > found the requested method but it does not seem to be available within
> > 4.0. Or am i looking at the wrong places?
> >
> > I have found the
> ClientConnectionManager.releaseConnection method (if
> > that is the way a connection is closed abrupt within 4.0), but i can't
> > find a possibility to get the HttpRoute of my HttpResponse that i need
> > to identify the connection i want to close.
> >
>
>  It's on the method, i.e., HttpPost, HttpGet, etc...
>
>  Regards,
>  Sebastiaan
>
>
>
>
> > 2008/4/17, Oleg Kalnichevski <ol...@apache.org>:
> >
> > >  On Thu, 2008-04-17 at 11:40 +0200, Jan Bracker wrote:
> > >  > Hello,
> > >  >
> > >  > i'm using the DefaultHttpClient for downloading bigger files. When i
> > >  > want to abort a download i call
> response.getEntity().consumeContent()
> > >
> > >
> > > Why? The purpose of HttpEntity#consumeContent() method is to ensure the
> > >  underlying connection is re-usable for subsequent requests, not to
> abort
> > >  the actual request
> > >
> > >
> > >
> > >  > (I assume that is what i should do if i want to close connections of
> > >  > HttpClient). But the longer content downloaded on that connections
> get
> > >  > the more time it takes to close the given connection.
> > >  >
> > >
> > >
> > > Please use #abort method instead.
> > >
> > >
> > >
> > >  > I allready looked at source and found the problem within
> > >  > ChunkedInputStream. consumeContent() calls close() to the InputStream
> > >  > and that close results in a call of exhaustInputStream() and that
> > >  > reads the complete rest of content sent by the host.
> > >  >
> > >  > Why is this implemented like that? Why not just close the
> > >  > connection/stream?
> > >
> > >
> > > To be able to use persistent connection reliably.
> > >
> > >
> > >
> > >  >  This behaviour is very annoying when wanting to
> > >  > stop a request that leads to a response entity of severel megabytes,
> > >  > especially on connections that are volume payed or have a slow
> > >  > bandwidth.
> > >  >
> > >  > Is there a way to close the connection (consumeContent) of my current
> > >  > response without having to read the complete content? How do i solve
> > >  > my problem of closing connections quick and abrupt?
> > >  >
> > >
> > >
> > > See above.
> > >
> > >  Oleg
> > >
> > >  > Greetings, Jan Bracker
> > >  >
> > >  >
> ---------------------------------------------------------------------
> > >  > To unsubscribe, e-mail:
> httpclient-users-unsubscribe@hc.apache.org
> > >  > For additional commands, e-mail:
> httpclient-users-help@hc.apache.org
> > >  >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > >  To unsubscribe, e-mail:
> httpclient-users-unsubscribe@hc.apache.org
> > >  For additional commands, e-mail:
> httpclient-users-help@hc.apache.org
> > >
> > >
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail:
> httpclient-users-help@hc.apache.org
> >
> >
>
>

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


Re: HttpEntity.consumeContent() needs to much time. (HC 4.0 beta)

Posted by Sebastiaan van Erk <se...@sebster.com>.
Jan Bracker wrote:
>>  > (I assume that is what i should do if i want to close connections of
>>  > HttpClient). But the longer content downloaded on that connections get
>>  > the more time it takes to close the given connection.
>>  >
>>
>>
>> Please use #abort method instead.
> 
> I can't find any #abort methode within DefaultHttpClient, HttpResponse
> or HttpEntity and InputStream does not support such a method either.
> Are you sure you are talking about version 4.0? As said in the subject
> i am using HttpComponents 4.0 beta. As looking through 3.1 javadoc i
> found the requested method but it does not seem to be available within
> 4.0. Or am i looking at the wrong places?
> 
> I have found the ClientConnectionManager.releaseConnection method (if
> that is the way a connection is closed abrupt within 4.0), but i can't
> find a possibility to get the HttpRoute of my HttpResponse that i need
> to identify the connection i want to close.

It's on the method, i.e., HttpPost, HttpGet, etc...

Regards,
Sebastiaan


> 2008/4/17, Oleg Kalnichevski <ol...@apache.org>:
>>  On Thu, 2008-04-17 at 11:40 +0200, Jan Bracker wrote:
>>  > Hello,
>>  >
>>  > i'm using the DefaultHttpClient for downloading bigger files. When i
>>  > want to abort a download i call response.getEntity().consumeContent()
>>
>>
>> Why? The purpose of HttpEntity#consumeContent() method is to ensure the
>>  underlying connection is re-usable for subsequent requests, not to abort
>>  the actual request
>>
>>
>>
>>  > (I assume that is what i should do if i want to close connections of
>>  > HttpClient). But the longer content downloaded on that connections get
>>  > the more time it takes to close the given connection.
>>  >
>>
>>
>> Please use #abort method instead.
>>
>>
>>
>>  > I allready looked at source and found the problem within
>>  > ChunkedInputStream. consumeContent() calls close() to the InputStream
>>  > and that close results in a call of exhaustInputStream() and that
>>  > reads the complete rest of content sent by the host.
>>  >
>>  > Why is this implemented like that? Why not just close the
>>  > connection/stream?
>>
>>
>> To be able to use persistent connection reliably.
>>
>>
>>
>>  >  This behaviour is very annoying when wanting to
>>  > stop a request that leads to a response entity of severel megabytes,
>>  > especially on connections that are volume payed or have a slow
>>  > bandwidth.
>>  >
>>  > Is there a way to close the connection (consumeContent) of my current
>>  > response without having to read the complete content? How do i solve
>>  > my problem of closing connections quick and abrupt?
>>  >
>>
>>
>> See above.
>>
>>  Oleg
>>
>>  > Greetings, Jan Bracker
>>  >
>>  > ---------------------------------------------------------------------
>>  > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>  > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>  >
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>  For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 

Re: HttpEntity.consumeContent() needs to much time. (HC 4.0 beta)

Posted by Jan Bracker <ja...@googlemail.com>.
>  > (I assume that is what i should do if i want to close connections of
>  > HttpClient). But the longer content downloaded on that connections get
>  > the more time it takes to close the given connection.
>  >
>
>
> Please use #abort method instead.

I can't find any #abort methode within DefaultHttpClient, HttpResponse
or HttpEntity and InputStream does not support such a method either.
Are you sure you are talking about version 4.0? As said in the subject
i am using HttpComponents 4.0 beta. As looking through 3.1 javadoc i
found the requested method but it does not seem to be available within
4.0. Or am i looking at the wrong places?

I have found the ClientConnectionManager.releaseConnection method (if
that is the way a connection is closed abrupt within 4.0), but i can't
find a possibility to get the HttpRoute of my HttpResponse that i need
to identify the connection i want to close.

2008/4/17, Oleg Kalnichevski <ol...@apache.org>:
>
>  On Thu, 2008-04-17 at 11:40 +0200, Jan Bracker wrote:
>  > Hello,
>  >
>  > i'm using the DefaultHttpClient for downloading bigger files. When i
>  > want to abort a download i call response.getEntity().consumeContent()
>
>
> Why? The purpose of HttpEntity#consumeContent() method is to ensure the
>  underlying connection is re-usable for subsequent requests, not to abort
>  the actual request
>
>
>
>  > (I assume that is what i should do if i want to close connections of
>  > HttpClient). But the longer content downloaded on that connections get
>  > the more time it takes to close the given connection.
>  >
>
>
> Please use #abort method instead.
>
>
>
>  > I allready looked at source and found the problem within
>  > ChunkedInputStream. consumeContent() calls close() to the InputStream
>  > and that close results in a call of exhaustInputStream() and that
>  > reads the complete rest of content sent by the host.
>  >
>  > Why is this implemented like that? Why not just close the
>  > connection/stream?
>
>
> To be able to use persistent connection reliably.
>
>
>
>  >  This behaviour is very annoying when wanting to
>  > stop a request that leads to a response entity of severel megabytes,
>  > especially on connections that are volume payed or have a slow
>  > bandwidth.
>  >
>  > Is there a way to close the connection (consumeContent) of my current
>  > response without having to read the complete content? How do i solve
>  > my problem of closing connections quick and abrupt?
>  >
>
>
> See above.
>
>  Oleg
>
>  > Greetings, Jan Bracker
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>  > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>  >
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>  For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

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


Re: HttpEntity.consumeContent() needs to much time. (HC 4.0 beta)

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2008-04-17 at 11:40 +0200, Jan Bracker wrote:
> Hello,
> 
> i'm using the DefaultHttpClient for downloading bigger files. When i
> want to abort a download i call response.getEntity().consumeContent()

Why? The purpose of HttpEntity#consumeContent() method is to ensure the
underlying connection is re-usable for subsequent requests, not to abort
the actual request 


> (I assume that is what i should do if i want to close connections of
> HttpClient). But the longer content downloaded on that connections get
> the more time it takes to close the given connection.
> 

Please use #abort method instead. 


> I allready looked at source and found the problem within
> ChunkedInputStream. consumeContent() calls close() to the InputStream
> and that close results in a call of exhaustInputStream() and that
> reads the complete rest of content sent by the host.
> 
> Why is this implemented like that? Why not just close the
> connection/stream?

To be able to use persistent connection reliably.


>  This behaviour is very annoying when wanting to
> stop a request that leads to a response entity of severel megabytes,
> especially on connections that are volume payed or have a slow
> bandwidth.
> 
> Is there a way to close the connection (consumeContent) of my current
> response without having to read the complete content? How do i solve
> my problem of closing connections quick and abrupt?
> 

See above.

Oleg

> Greetings, Jan Bracker
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


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