You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Jeff Dever <jd...@nortelnetworks.com> on 2002/09/18 18:15:06 UTC

RE: [HttpClient] Automatic reconnect in case of closed connection .

This seems reasonable to me.

> -----Original Message-----
> From: Elwin, Martin [mailto:melwin@rsasecurity.com]
> Sent: Wednesday, September 18, 2002 6:55 AM
> To: Jakarta Commons Developers List
> Subject: [HttpClient] Automatic reconnect in case of closed 
> connection.
> 
> 
> Hi all,
> 
> Please let me run this by you and let me know what you think 
> (like if I'm
> completely out of line, or not...)...
> 
> When using a web server (or proxy server) that closes the http (1.1)
> connections after a certain timeout (almost all do - for instance, the
> Apache Httpd does it after 15 seconds by default) a write to the
> HttpConnection will fail with an IOException (or 
> SocketException rather). I
> believe that the correct thing for the HttpClient to do is to 
> reconnect the
> closed socket (_once_) and try to do the request again. The 
> reason being, a
> by the server closed socket should not be a problem when 
> doing a request,
> and therefore the HttpClient should try to establish the 
> socket again and
> try to make the request. BUT, if something goes wrong, like 
> with the opening
> of the connection or similar, a retry should not be made but rather an
> exception should be thrown (the way it is now) to signal the 
> problem to the
> application using the HttpClient library.
> 
> ---
> 
> Example code modification to HttpMethodBase.java:
> 
> in the execute(..) method, change the line:
> 
>       processRequest(state, conn);
> 
> 
> to:
> 
> 	try {
>             processRequest(state, conn);
> 	}
> 	catch(IOException ioe) {
>             if (log.isDebugEnabled()) {
>                 log.debug("Socket closed? Trying to reestablish
> connection");
>             }
> 		conn.close();
>             processRequest(state, conn);
> 	}
> 
> ---
> 
> Do you think this is bad, and if that's the case, why? I've 
> been using the
> above change in my application to handle sockets closed by 
> the Apache Httpd
> configured as a forward proxy. Internally it might be wise to 
> subclass (or
> wrap) IOException so that the above case can be detected with better
> certainty, instead of catching the, when it comes to streams, 
> pretty generic
> IOException...
> 
> Regards,
> 
> /M
> 
> ------------
> Martin Elwin
> @N59.29606 E18.08052 (WGS-84)
> 
> 
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
> 
> 

Re: [HttpClient] Automatic reconnect in case of closed connection .

Posted by Ortwin Glück <or...@nose.ch>.
But only for HTTP/1.1

Jeff Dever wrote:
> This seems reasonable to me.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>