commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Elwin, Martin" <>
Subject RE: [HttpClient] Automatic reconnect in case of closed connection .
Date Mon, 23 Sep 2002 11:22:57 GMT
Better might be to move the readResponse(...) call done in
processRequest(...) into the retry mechanism used for the writeRequest(...)
call instead of adding a retry on another (in this case higher) level, which
was my first suggestion. Currently it looks like the HttpClient is supposed
to handle a closed socket - a HttpRecoverableException is thrown in the
readStatusLine(...) method - but since no retry is done for the reading it
will never handle that problem automatically.

So, modified version might look like:

 private void processRequest(HttpState state, HttpConnection connection)
    throws HttpException, IOException {
            "enter HttpMethodBase.processRequest(HttpState,

        //try to do the request
        int retryCount = 0;
        do {
            if (log.isTraceEnabled()) {
                log.trace("Attempt number " + retryCount + " to write
            try {
                if (!connection.isOpen()) {
                    log.debug("Opening the connection.");
                writeRequest(state, connection);
	          readResponse(state, connection);
                used = true; //request worked, mark this method as used
                break; //all done
            } catch (HttpRecoverableException httpre) {
      "Recoverable exception caught when doing request");
                if (log.isDebugEnabled()) {
                    log.debug("Closing the connection.");
                if (retryCount == maxRetries) {
                        "Attempt to do request has reached max retries: "
                        + maxRetries);
                    throw httpre;
        } while (retryCount <= maxRetries);

        //everything should be OK at this point

... or similar...

Ortwin, not sure if I understand why a retry only should be done for 1.1.
Would you mind elaborating on the reasons for that? The current retry logic
is valid for both 1.0 and 1.1, as far as I can tell.

Thanks a lot!



Ortwin Gl├╝ck wrote:
> But only for HTTP/1.1
> Jeff Dever wrote:
> > This seems reasonable to me.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message