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 Paul King <pa...@asert.com.au> on 2006/06/22 13:52:25 UTC

help creating an aborting client (simulating connection reset)

I created a little httpclient aborting client application
so that we can test how our server handles the equivalent
of the user shutting down their browser in the middle of
an operation or unexpectedly hitting back etc.

Basically a server post (though it wouldn't need to be)
is kicked off and then in another thread a timer kicks
in and aborts the application.

Has anyone else done something similar?
Would using HttpMethod#abort be the preferred way to
do this rather than the current brute force approach
I have taken? I presume it can be fired off in a
separate thread to the original executeMethod()?

Is there some way to ensure that the connection is
definitely canceled? If my timeout value is too large,
sometimes the operation has already finished. If
my timeout value is too small, sometimes the connection
hasn't been established yet. I would prefer to
adopt an approach that was less brittle.

Thanks for any advice,

Paul.


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


Re: help creating an aborting client (simulating connection reset)

Posted by Roland Weber <ht...@dubioso.net>.
Hello Paul,

> Would using HttpMethod#abort be the preferred way to
> do this

Yes.

> rather than the current brute force approach
> I have taken?

What is the brute force approach? HttpMethod#abort
closes the socket used for communication. How much
bruter can it get?

> I presume it can be fired off in a
> separate thread to the original executeMethod()?

Yes. The thread that calls executeMethod is blocked
and couldn't call anything until the execution
completes, fails, or is aborted.

> Is there some way to ensure that the connection is
> definitely canceled?

Are you trying to cancel connections or method executions?

> If my timeout value is too large,
> sometimes the operation has already finished.

There's not much you can do about that. If the operation
is finished, you can't abort it. If the server sends a
response body, your application can simply not read that
body and wait to be aborted. But then you have to do
both, call #abort on the method and interrupt your thread,
in case it isn't blocked in executeMethod anymore.

> If
> my timeout value is too small, sometimes the connection
> hasn't been established yet.

The #abort will make sure it doesn't start in the first
place.

hope that helps,
  Roland

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