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 George Ludwig <sf...@yahoo.com> on 2008/03/11 19:25:04 UTC
properly aborting a GET method?
I am doing some web harvesting, and I'm trying to
better handle the situation where a hostile website
has my connection and then sends a few packets of
garbage data every couple of minutes.
In the loop where I read data off the input stream, I
check the duration of the entire read process, and if
it has taken longer than a preset number of
milliseconds, I want to terminate the get method.
Initially, I simply threw an exception, then called
method.releaseConnection() in the finally block.
However, I have since realized that
releaseConnection() tries to read the entire response
before releasing the connection. This does me no good,
since I want to stop consuming the response.
So now I call method.abort(), then throw the
exception, and then method.releaseConnection() is
called in the finally block.
Is this the best way to terminate a hostile
connection?
TIA,
George
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: properly aborting a GET method?
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-03-11 at 11:25 -0700, George Ludwig wrote:
> I am doing some web harvesting, and I'm trying to
> better handle the situation where a hostile website
> has my connection and then sends a few packets of
> garbage data every couple of minutes.
>
> In the loop where I read data off the input stream, I
> check the duration of the entire read process, and if
> it has taken longer than a preset number of
> milliseconds, I want to terminate the get method.
>
> Initially, I simply threw an exception, then called
> method.releaseConnection() in the finally block.
> However, I have since realized that
> releaseConnection() tries to read the entire response
> before releasing the connection. This does me no good,
> since I want to stop consuming the response.
>
> So now I call method.abort(), then throw the
> exception, and then method.releaseConnection() is
> called in the finally block.
>
> Is this the best way to terminate a hostile
> connection?
>
George,
HttpMethod#abort is the way to go
Oleg
> TIA,
>
> George
>
>
> ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>
> ---------------------------------------------------------------------
> 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