commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient NoHostHttpConnectionManager.java TestIdleConnectionTimeout.java
Date Mon, 05 Jul 2004 22:46:59 GMT
olegk       2004/07/05 15:46:59

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        ConnectTimeoutException.java
                        DefaultMethodRetryHandler.java HttpConnection.java
                        HttpConnectionManager.java HttpMethod.java
                        HttpMethodBase.java HttpMethodDirector.java
                        HttpRecoverableException.java
                        MethodRetryHandler.java
                        MultiThreadedHttpConnectionManager.java
               httpclient/src/java/org/apache/commons/httpclient/auth
                        CredentialsProvider.java
               httpclient/src/java/org/apache/commons/httpclient/params
                        DefaultHttpParamsFactory.java
               httpclient/src/test/org/apache/commons/httpclient
                        NoHostHttpConnectionManager.java
                        TestIdleConnectionTimeout.java
  Added:       httpclient/src/java/org/apache/commons/httpclient
                        ConnectionPoolTimeoutException.java
                        DefaultHttpMethodRetryHandler.java
                        HttpMethodRetryHandler.java
                        NoHttpResponseException.java
  Removed:     httpclient/src/java/org/apache/commons/httpclient
                        HttpTimeoutException.java IOTimeoutException.java
  Log:
  PR #29874 (Auto method retrial broken)
  
  Changelog:
  * fixes broken 'request sent' logic, albeit at the expense of adding (yet another) method to the HttpMethod interface
  * deprecates HttpRecoverableException, MethodRetryHandler, DefaultMethodRetryHandler classes, HttpMethodBase#setMethodRetryHandler and HttpMethodBase#getMethodRetryHandler methods
  * adds new HttpMethodRetryHandler interface that acts on plain IOExceptions
  * eliminates superfluous HttpTimeoutException & IOTimeoutException classes
  * ConnectTimeoutException now subclasses the standard InterruptedIOException, which is more consistent with the overall Java exception handling framework
  * HttpConnectionManager classes now throw a more specific ConnectionPoolTimeoutException derived from ConnectTimeoutException. There can be cases when socket connect timeout needs to be differentiated from that of the connection pool
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.5       +11 -5     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectTimeoutException.java
  
  Index: ConnectTimeoutException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectTimeoutException.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConnectTimeoutException.java	13 May 2004 04:03:25 -0000	1.4
  +++ ConnectTimeoutException.java	5 Jul 2004 22:46:58 -0000	1.5
  @@ -29,6 +29,10 @@
   
   package org.apache.commons.httpclient;
   
  +import java.io.InterruptedIOException;
  +
  +import org.apache.commons.httpclient.util.ExceptionUtil;
  +
   /**
    * A timeout while connecting to an HTTP server or waiting for an
    * available connection from an HttpConnectionManager.
  @@ -37,7 +41,7 @@
    * 
    * @since 3.0
    */
  -public class ConnectTimeoutException extends HttpTimeoutException {
  +public class ConnectTimeoutException extends InterruptedIOException {
   
       /**
        * Creates a ConnectTimeoutException with a <tt>null</tt> detail message.
  @@ -63,7 +67,9 @@
        * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
        */
       public ConnectTimeoutException(String message, Throwable cause) {
  -        super(message, cause);
  +        super(message);
  +        // If we're running on JDK 1.4 or later, tell Throwable what the cause was
  +        ExceptionUtil.initCause(this, cause);
       }
   
   }
  
  
  
  1.4       +5 -3      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java
  
  Index: DefaultMethodRetryHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultMethodRetryHandler.java	18 Apr 2004 23:51:34 -0000	1.3
  +++ DefaultMethodRetryHandler.java	5 Jul 2004 22:46:58 -0000	1.4
  @@ -35,6 +35,8 @@
    * @author Michael Becke
    * 
    * @see HttpMethodBase#setMethodRetryHandler(MethodRetryHandler)
  + * 
  + * @deprecated use {@link org.apache.commons.httpclient.DefaultHttpMethodRetryHandler}
    */
   public class DefaultMethodRetryHandler implements MethodRetryHandler {
   
  
  
  
  1.96      +10 -169   jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- HttpConnection.java	25 Jun 2004 03:34:56 -0000	1.95
  +++ HttpConnection.java	5 Jul 2004 22:46:58 -0000	1.96
  @@ -484,7 +484,7 @@
                           socket.setSoTimeout(this.params.getSoTimeout());
                       }
                   }
  -            } catch (IOTimeoutException e) {
  +            } catch (InterruptedIOException e) {
                   // aha - the connection is NOT stale - continue on!
               } catch (IOException e) {
                   // oops - the connection is stale, the read or soTimeout failed.
  @@ -687,16 +687,11 @@
                   socket.setReceiveBufferSize(rcvBufSize);
               }        
               inputStream = new PushbackInputStream(
  -                new WrappedInputStream(socket.getInputStream()));
  +                socket.getInputStream());
               outputStream = new BufferedOutputStream(
  -                new WrappedOutputStream(socket.getOutputStream()),
  -                socket.getSendBufferSize()
  -            );
  +                socket.getOutputStream(), socket.getSendBufferSize());
               isOpen = true;
               used = false;
  -        } catch (InterruptedIOException e) {
  -            closeSocketAndStreams();
  -            throw new ConnectTimeoutException("Open connection interrupted", e);
           } catch (IOException e) {
               // Connection wasn't opened properly
               // so close everything out
  @@ -741,11 +736,9 @@
               socket.setReceiveBufferSize(rcvBufSize);
           }        
           inputStream = new PushbackInputStream(
  -            new WrappedInputStream(socket.getInputStream()));
  +            socket.getInputStream());
           outputStream = new BufferedOutputStream(
  -            new WrappedOutputStream(socket.getOutputStream()),
  -            socket.getSendBufferSize()
  -        );
  +            socket.getOutputStream(), socket.getSendBufferSize());
           usingSecureSocket = true;
           tunnelEstablished = true;
           LOG.debug("Secure tunnel created");
  @@ -849,7 +842,7 @@
                   } else {
                       LOG.debug("Input data not available");
                   }
  -            } catch (IOTimeoutException e) {
  +            } catch (InterruptedIOException e) {
                   if (LOG.isDebugEnabled()) {
                       LOG.debug("Input data not available after " + timeout + " ms");
                   }
  @@ -1238,158 +1231,6 @@
        */
       public void setSendBufferSize(int sendBufferSize) throws SocketException {
           this.params.setSendBufferSize(sendBufferSize);
  -    }
  -
  -    /**
  -     * A wrapper for output streams that closes the connection and converts 
  -     * to HttpClient specific exceptions as appropriable when an IOException occurs.
  -     */
  -    private class WrappedOutputStream extends OutputStream {
  -
  -        /** the actual output stream */
  -        private OutputStream out;
  -
  -        /**
  -         * @param out the output stream to wrap
  -         */
  -        public WrappedOutputStream(OutputStream out) {
  -            this.out = out;
  -        }
  -
  -        /**
  -         * Closes the connection and conditionally converts exception to recoverable.
  -         * @param ioe the exception that occurred
  -         * @return the exception to be thrown
  -         */
  -        private IOException handleException(final IOException ioe) {
  -            // keep the original value of used, as it will be set to false by close().
  -            boolean isRecoverable = HttpConnection.this.used;
  -            HttpConnection.this.close();
  -            if (ioe instanceof InterruptedIOException) {
  -                return new IOTimeoutException(ioe.getMessage(), ioe); 
  -            } else if (isRecoverable) {
  -                LOG.debug(
  -                    "Output exception occurred on a used connection.  Will treat as recoverable.", 
  -                    ioe
  -                );
  -                return new HttpRecoverableException(ioe.getMessage(), ioe);                
  -            } else {
  -                return ioe;
  -            }            
  -        }
  -
  -        public void write(int b) throws IOException {
  -            try {
  -                out.write(b);
  -                HttpConnection.this.used = true;            
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -        
  -        public void flush() throws IOException {
  -            try {
  -                out.flush();            
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -
  -        public void close() throws IOException {
  -            try {
  -                out.close();            
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -
  -        public void write(byte[] b, int off, int len) throws IOException {
  -            try {
  -                out.write(b, off, len);
  -                HttpConnection.this.used = true;            
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -
  -        public void write(byte[] b) throws IOException {
  -            try {
  -                out.write(b);            
  -                HttpConnection.this.used = true;            
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -
  -    }
  -
  -    /**
  -     * A wrapper for input streams that converts to HTTPClient
  -     * specific exceptions as appropriable when an IOException occurs.
  -     */
  -    private class WrappedInputStream extends InputStream {
  -
  -        /** the actual inpuit stream */
  -        private InputStream in;
  -
  -        /**
  -         * @param in the input stream to wrap
  -         */
  -        public WrappedInputStream(InputStream in) {
  -            this.in = in;
  -        }
  -
  -        /**
  -         * Conditionally converts exception to HttpClient specific 
  -         * exception.
  -         * @param ioe the exception that occurred
  -         * @return the exception to be thrown
  -         */
  -        private IOException handleException(final IOException ioe) {
  -            if (ioe instanceof InterruptedIOException) {
  -                return new IOTimeoutException(ioe.getMessage(), ioe); 
  -            } else {
  -                return ioe;
  -            }            
  -        }
  -
  -        public int read() throws IOException {
  -            try {
  -                return in.read();
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -        
  -        public void close() throws IOException {
  -            in.close();            
  -        }
  -
  -        public int read(byte[] b, int off, int len) throws IOException {
  -            try {
  -                return in.read(b, off, len);
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -
  -        public int read(byte[] b) throws IOException {
  -            try {
  -                return in.read(b);            
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -
  -        public int available() throws IOException
  -        {
  -            try {
  -                return in.available();
  -            } catch (IOException ioe) {
  -                throw handleException(ioe);
  -            }
  -        }
  -
       }
   
       // ------------------------------------------------------- Static Variable
  
  
  
  1.24      +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java
  
  Index: HttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- HttpConnectionManager.java	17 May 2004 21:46:03 -0000	1.23
  +++ HttpConnectionManager.java	5 Jul 2004 22:46:58 -0000	1.24
  @@ -101,7 +101,7 @@
   	 * 
   	 * @return an HttpConnection for the given configuraiton
   	 * 
  -	 * @throws ConnectTimeoutException if no connection becomes available before the
  +	 * @throws ConnectionPoolTimeoutException if no connection becomes available before the
   	 * timeout expires
   	 * 
   	 * @see HttpConnection#setHttpConnectionManager(HttpConnectionManager)
  @@ -109,7 +109,7 @@
        * @since 3.0
   	 */
   	HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout)
  -		throws ConnectTimeoutException;
  +		throws ConnectionPoolTimeoutException;
   
       /**
        * Releases the given HttpConnection for use by other requests.
  
  
  
  1.41      +14 -22    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java
  
  Index: HttpMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- HttpMethod.java	13 Jun 2004 20:22:18 -0000	1.40
  +++ HttpMethod.java	5 Jul 2004 22:46:58 -0000	1.41
  @@ -544,24 +544,6 @@
       public void setParams(final HttpMethodParams params);
   
       /**
  -     * Returns the {@link MethodRetryHandler retry handler} for this HTTP method
  -     * 
  -     * @return the methodRetryHandler
  -     * 
  -     * @since 3.0
  -     */
  -    public MethodRetryHandler getMethodRetryHandler();
  -
  -    /**
  -     * Sets the {@link MethodRetryHandler retry handler} for this HTTP method
  -     * 
  -     * @param handler the methodRetryHandler to use when this method executed
  -     * 
  -     * @since 3.0
  -     */
  -    public void setMethodRetryHandler(MethodRetryHandler handler);
  -
  -    /**
        * Returns the target host {@link AuthState authentication state}
        * 
        * @return host authentication state
  @@ -578,5 +560,15 @@
        * @since 3.0
        */
       public AuthState getProxyAuthState();
  +
  +    /**
  +     * Returns <tt>true</tt> if the HTTP has been transmitted to the target
  +     * server in its entirety, <tt>false</tt> otherwise. This flag can be useful 
  +     * for recovery logic. If the request has not been transmitted in its entirety,
  +     * it is safe to retry the failed method.
  +     * 
  +     * @return <tt>true</tt> if the request has been sent, <tt>false</tt> otherwise
  +     */
  +    boolean isRequestSent();
   
   }
  
  
  
  1.210     +38 -16    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.209
  retrieving revision 1.210
  diff -u -r1.209 -r1.210
  --- HttpMethodBase.java	24 Jun 2004 21:39:52 -0000	1.209
  +++ HttpMethodBase.java	5 Jul 2004 22:46:58 -0000	1.210
  @@ -33,6 +33,7 @@
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.InterruptedIOException;
   
   import org.apache.commons.httpclient.auth.AuthState;
   import org.apache.commons.httpclient.cookie.CookiePolicy;
  @@ -156,6 +157,8 @@
   
       /**
        * Handles method retries
  +     * 
  +     * @deprecated no loner used
        */
       private MethodRetryHandler methodRetryHandler;
   
  @@ -171,6 +174,9 @@
       /** Whether the execution of this method has been aborted */
       private transient boolean aborted = false;
   
  +    /** Whether the HTTP request has been transmitted to the target
  +     * server it its entirety */
  +    private boolean requestSent = false;
       // ----------------------------------------------------------- Constructors
   
       /**
  @@ -971,9 +977,8 @@
               this.effectiveVersion = this.params.getVersion(); 
           }
   
  -        boolean requestSent = false;
           writeRequest(state, conn);
  -        requestSent = true;
  +        this.requestSent = true;
           readResponse(state, conn);
           // the method has successfully executed
           used = true; 
  @@ -1040,6 +1045,7 @@
           connectionCloseForced = false;
           hostAuthState.invalidate();
           proxyAuthState.invalidate();
  +        requestSent = false;
       }
   
       /**
  @@ -1783,6 +1789,11 @@
           String s;
           do {
               s = conn.readLine(getParams().getHttpElementCharset());
  +            if (s == null && count == 0) {
  +                // The server just dropped connection on us
  +                throw new NoHttpResponseException("The server " + conn.getHost() + 
  +                    " failed to respond");
  +            }
               if (Wire.HEADER_WIRE.enabled()) {
                   Wire.HEADER_WIRE.input(s + "\r\n");
               }
  @@ -1791,9 +1802,8 @@
                   break;
               } else if (s == null || count >= maxGarbageLines) {
                   // Giving up
  -                throw new HttpRecoverableException("Error in parsing the status "
  -                    + " line from the response: unable to find line starting with"
  -                    + " \"HTTP\"");
  +                throw new ProtocolException("The server " + conn.getHost() + 
  +                        " failed to respond with a valid HTTP response");
               }
               count++;
           } while(true);
  @@ -1897,7 +1907,7 @@
                       } else {
                           return;
                       }
  -                } catch (IOTimeoutException e) {
  +                } catch (InterruptedIOException e) {
                       // Most probably Expect header is not recongnized
                       // Remove the header to signal the method 
                       // that it's okay to go ahead with sending data
  @@ -2256,13 +2266,10 @@
        * Returns the {@link MethodRetryHandler retry handler} for this HTTP method
        * 
        * @return the methodRetryHandler
  +     * 
  +     * @deprecated use {@link HttpMethodParams}
        */
       public MethodRetryHandler getMethodRetryHandler() {
  -        
  -        if (methodRetryHandler == null) {
  -            methodRetryHandler = new DefaultMethodRetryHandler();
  -        }
  -
           return methodRetryHandler;
       }
   
  @@ -2270,6 +2277,8 @@
        * Sets the {@link MethodRetryHandler retry handler} for this HTTP method
        * 
        * @param handler the methodRetryHandler to use when this method executed
  +     * 
  +     * @deprecated use {@link HttpMethodParams}
        */
       public void setMethodRetryHandler(MethodRetryHandler handler) {
           methodRetryHandler = handler;
  @@ -2328,5 +2337,18 @@
        */
       public boolean isAborted() {
           return this.aborted;
  -    }    
  +    }
  +    
  +    /**
  +     * Returns <tt>true</tt> if the HTTP has been transmitted to the target
  +     * server in its entirety, <tt>false</tt> otherwise. This flag can be useful 
  +     * for recovery logic. If the request has not been transmitted in its entirety,
  +     * it is safe to retry the failed method.
  +     * 
  +     * @return <tt>true</tt> if the request has been sent, <tt>false</tt> otherwise
  +     */
  +    public boolean isRequestSent() {
  +        return this.requestSent;
  +    }
  +    
   }
  
  
  
  1.28      +44 -28    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
  
  Index: HttpMethodDirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- HttpMethodDirector.java	25 Jun 2004 03:34:56 -0000	1.27
  +++ HttpMethodDirector.java	5 Jul 2004 22:46:58 -0000	1.28
  @@ -336,17 +336,12 @@
           throws IOException, HttpException {
           
           /** How many times did this transparently handle a recoverable exception? */
  -        int recoverableExceptionCount = 0;
           int execCount = 0;
  -        // TODO: how do we get requestSent?
  -        boolean requestSent = false;
  -        
           // loop until the method is successfully processed, the retryHandler 
           // returns false or a non-recoverable exception is thrown
           try {
               while (true) {
                   execCount++;
  -                requestSent = false;
   
                   if (LOG.isTraceEnabled()) {
                       LOG.trace("Attempt number " + execCount + " to process request");
  @@ -382,31 +377,52 @@
                   try {
                       method.execute(state, this.conn);
                       break;
  -                } catch (HttpRecoverableException httpre) {
  +                } catch (HttpException e) {
  +                    // filter out protocol exceptions which cannot be recovered from
  +                    throw e;
  +                } catch (IOException e) {
                       LOG.debug("Closing the connection.");
                       this.conn.close();
  -                    LOG.info("Recoverable exception caught when processing request");
  -                    // update the recoverable exception count.
  -                    recoverableExceptionCount++;
  -                
  -                    // test if this method should be retried                
  -                    MethodRetryHandler handler = method.getMethodRetryHandler();
  +                    // test if this method should be retried
  +                    // ========================================
  +                    // this code is provided for backward compatibility with 2.0
  +                    // will be removed in the next major release
  +                    if (method instanceof HttpMethodBase) {
  +                        MethodRetryHandler handler = 
  +                            ((HttpMethodBase)method).getMethodRetryHandler();
  +                        if (handler != null) {
  +                            if (!handler.retryMethod(
  +                                    method,
  +                                    this.conn, 
  +                                    new HttpRecoverableException(e.getMessage()),
  +                                    execCount, 
  +                                    method.isRequestSent())) {
  +                                LOG.debug("Method retry handler returned false. "
  +                                        + "Automatic recovery will not be attempted");
  +                                throw e;
  +                            }
  +                        }
  +                    }
  +                    // ========================================
  +                    HttpMethodRetryHandler handler = 
  +                        (HttpMethodRetryHandler)method.getParams().getParameter(
  +                                HttpMethodRetryHandler.HANDLER);
                       if (handler == null) {
  -                        handler = new DefaultMethodRetryHandler();
  +                        handler = new DefaultHttpMethodRetryHandler();
  +                    }
  +                    if (!handler.retryMethod(method, e, execCount)) {
  +                        LOG.debug("Method retry handler returned false. "
  +                                + "Automatic recovery will not be attempted");
  +                        throw e;
  +                    }
  +                    if (LOG.isInfoEnabled()) {
  +                        LOG.info("I/O exception caught when processing request: "
  +                                + e.getMessage());
                       }
  -                    if (!handler.retryMethod(
  -                            method, 
  -                            this.conn, 
  -                            httpre, 
  -                            execCount, 
  -                            requestSent)
  -                    ) {
  -                        LOG.warn(
  -                            "Recoverable exception caught but MethodRetryHandler.retryMethod() "
  -                            + "returned false, rethrowing exception"
  -                        );
  -                        throw httpre;
  +                    if (LOG.isDebugEnabled()) {
  +                        LOG.debug(e.getMessage(), e);
                       }
  +                    LOG.info("Retrying request");
                   }
               }
           } catch (IOException e) {
  
  
  
  1.15      +8 -23     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java
  
  Index: HttpRecoverableException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- HttpRecoverableException.java	13 May 2004 04:03:25 -0000	1.14
  +++ HttpRecoverableException.java	5 Jul 2004 22:46:58 -0000	1.15
  @@ -29,10 +29,6 @@
   
   package org.apache.commons.httpclient;
   
  -import java.io.IOException;
  -
  -import org.apache.commons.httpclient.util.ExceptionUtil;
  -
   /**
    * <p>
    * Signals that an HTTP or HttpClient exception has occurred.  This
  @@ -40,10 +36,13 @@
    * may be retried.  It may be possible to retrieve the underlying transient
    * error via the inherited {@link HttpException#getCause()} method.
    * </p>
  + * 
  + * @deprecated no longer used
  + * 
    * @author Unascribed
    * @version $Revision$ $Date$
    */
  -public class HttpRecoverableException extends IOException {
  +public class HttpRecoverableException extends HttpException {
   
       /**
        * Creates a new HttpRecoverableException with a <tt>null</tt> detail message.
  @@ -61,18 +60,4 @@
           super(message);
       }
   
  -    /**
  -     * Creates a new HttpRecoverableException with the specified detail message and cause.
  -     *
  -     * @param message the exception detail message
  -     * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
  -     * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
  -     * 
  -     * @since 3.0
  -     */
  -    public HttpRecoverableException(String message, Throwable cause) {
  -        super(message);
  -        // If we're running on JDK 1.4 or later, tell Throwable what the cause was
  -        ExceptionUtil.initCause(this, cause);
  -    }
   }
  
  
  
  1.5       +7 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MethodRetryHandler.java
  
  Index: MethodRetryHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MethodRetryHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MethodRetryHandler.java	18 Apr 2004 23:51:35 -0000	1.4
  +++ MethodRetryHandler.java	5 Jul 2004 22:46:58 -0000	1.5
  @@ -36,6 +36,8 @@
    * @see HttpMethod#execute(HttpState, HttpConnection)
    * @see HttpRecoverableException
    * 
  + * @deprecated use {@link HttpMethodRetryHandler}
  + * 
    * @author Michael Becke
    */
   public interface MethodRetryHandler {
  @@ -49,7 +51,8 @@
        * @param recoverableException the exception that occurred
        * @param executionCount the number of times this method has been 
        * unsuccessfully executed
  -     * @param requestSent a flag indicating if the request has been fully sent or not
  +     * @param requestSent this argument is unused and will be removed in the future. 
  +     *   {@link HttpMethod#isRequestSent()} should be used instead
        * 
        * @return <code>true</code> if the method should be retried, <code>false</code>
        * otherwise
  
  
  
  1.41      +8 -8      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java
  
  Index: MultiThreadedHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- MultiThreadedHttpConnectionManager.java	25 Jun 2004 03:34:56 -0000	1.40
  +++ MultiThreadedHttpConnectionManager.java	5 Jul 2004 22:46:58 -0000	1.41
  @@ -356,7 +356,7 @@
           while (true) {
               try {
                   return getConnectionWithTimeout(hostConfiguration, 0);
  -            } catch (ConnectTimeoutException e) {
  +            } catch (ConnectionPoolTimeoutException e) {
                   // we'll go ahead and log this, but it should never happen. HttpExceptions
                   // are only thrown when the timeout occurs and since we have no timeout
                   // it should never happen.
  @@ -374,7 +374,7 @@
        * @since 3.0
        */
       public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, 
  -        long timeout) throws ConnectTimeoutException {
  +        long timeout) throws ConnectionPoolTimeoutException {
   
           LOG.trace("enter HttpConnectionManager.getConnectionWithTimeout(HostConfiguration, long)");
   
  @@ -405,7 +405,7 @@
   		LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)");
   		try {
   			return getConnectionWithTimeout(hostConfiguration, timeout);
  -		} catch(ConnectTimeoutException e) {
  +		} catch(ConnectionPoolTimeoutException e) {
   			throw new HttpException(e.getMessage());
   		}
   	}
  @@ -426,7 +426,7 @@
        * 'timeout' milliseconds
        */
       private HttpConnection doGetConnection(HostConfiguration hostConfiguration, 
  -        long timeout) throws ConnectTimeoutException {
  +        long timeout) throws ConnectionPoolTimeoutException {
   
           HttpConnection connection = null;
   
  @@ -487,7 +487,7 @@
                       try {
                           
                           if (useTimeout && timeToWait <= 0) {
  -                            throw new ConnectTimeoutException("Timeout waiting for connection");
  +                            throw new ConnectionPoolTimeoutException("Timeout waiting for connection");
                           }
                           
                           if (LOG.isDebugEnabled()) {
  
  
  
  1.1                  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectionPoolTimeoutException.java
  
  Index: ConnectionPoolTimeoutException.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectionPoolTimeoutException.java,v 1.1 2004/07/05 22:46:58 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/07/05 22:46:58 $
   *
   * ====================================================================
   *
   *  Copyright 1999-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.httpclient;
  
  /**
   * A timeout while connecting waiting for an available connection 
   * from an HttpConnectionManager.
   * 
   * @author <a href="mailto:laura@lwerner.org">Laura Werner</a>
   * 
   * @since 3.0
   */
  public class ConnectionPoolTimeoutException extends ConnectTimeoutException {
  
      /**
       * Creates a ConnectTimeoutException with a <tt>null</tt> detail message.
       */
      public ConnectionPoolTimeoutException() {
          super();
      }
  
      /**
       * Creates a ConnectTimeoutException with the specified detail message.
       * 
       * @param message The exception detail message 
       */
      public ConnectionPoolTimeoutException(String message) {
          super(message);
      }
  
      /**
       * Creates a new ConnectTimeoutException with the specified detail message and cause.
       * 
       * @param message the exception detail message
       * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
       * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
       */
      public ConnectionPoolTimeoutException(String message, Throwable cause) {
          super(message, cause);
      }
  
  }
  
  
  
  1.1                  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java
  
  Index: DefaultHttpMethodRetryHandler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java,v 1.1 2004/07/05 22:46:58 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/07/05 22:46:58 $
   *
   * ====================================================================
   *
   *  Copyright 1999-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.httpclient;
  
  import java.io.IOException;
  
  /**
   * The default {@link HttpMethodRetryHandler} used by {@link HttpMethod}s.
   * 
   * @author Michael Becke
   * @author <a href="mailto:oleg -at- ural.ru">Oleg Kalnichevski</a>
   */
  public class DefaultHttpMethodRetryHandler implements HttpMethodRetryHandler {
  
      /** the number of times a method will be retried */
      private int retryCount;
      
      /** Whether or not methods that have successfully sent their request will be retried */
      private boolean requestSentRetryEnabled;
      
      /**
       * Default constructor
       */
      public DefaultHttpMethodRetryHandler(int retryCount, boolean requestSentRetryEnabled) {
          super();
          this.retryCount = retryCount;
          this.requestSentRetryEnabled = requestSentRetryEnabled;
      }
      
      /**
       * Default constructor
       */
      public DefaultHttpMethodRetryHandler() {
          this(3, false);
      }
      /** 
       * Used <code>retryCount</code> and <code>requestSentRetryEnabled</code> to determine
       * if the given method should be retried.
       * 
       * @see HttpMethodRetryHandler#retryMethod(HttpMethod, IOException, int)
       */
      public boolean retryMethod(
          final HttpMethod method, 
          final IOException exception, 
          int executionCount) {
          if (method == null) {
              throw new IllegalArgumentException("HTTP method may not be null");
          }
          if (exception == null) {
              throw new IllegalArgumentException("Exception parameter may not be null");
          }
          if (executionCount >= this.retryCount) {
              // Do not retry if over max retry count
              return false;
          }
          if (exception instanceof NoHttpResponseException) {
              // Retry if the server dropped connection on us
              return true;
          }
          if (!method.isRequestSent() || this.requestSentRetryEnabled) {
              // Retry if the request has not been sent fully or
              // if it's OK to retry methods that have been sent
              return true;
          }
          // otherwise do not retry
          return false;
      }
      
      /**
       * @return <code>true</code> if this handler will retry methods that have 
       * successfully sent their request, <code>false</code> otherwise
       */
      public boolean isRequestSentRetryEnabled() {
          return requestSentRetryEnabled;
      }
  
      /**
       * @return the maximum number of times a method will be retried
       */
      public int getRetryCount() {
          return retryCount;
      }
  }
  
  
  
  1.1                  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodRetryHandler.java
  
  Index: HttpMethodRetryHandler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodRetryHandler.java,v 1.1 2004/07/05 22:46:58 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/07/05 22:46:58 $
   *
   * ====================================================================
   *
   *  Copyright 1999-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.httpclient;
  
  import java.io.IOException;
  
  /**
   * A handler for determining if an HttpMethod should be retried after a 
   * recoverable exception during execution.
   * 
   * <p>
   * Classes implementing this interface must synchronize access to shared
   * data as methods of this interfrace may be executed from multiple threads 
   * </p>
   * 
   * @see HttpMethod#execute(HttpState, HttpConnection)
   * @see HttpRecoverableException
   * 
   * @author Michael Becke
   * @author <a href="mailto:oleg -at- ural.ru">Oleg Kalnichevski</a>
   */
  public interface HttpMethodRetryHandler {
  
      /**
       * Sets the method retry handler parameter.
       * <p>
       * This parameter expects a value of type {@link HttpMethodRetryHandler}.
       * </p>
       */ 
      public static final String HANDLER = "http.method.retry-handler";
      
      /**
       * Determines if a method should be retried after an HttpRecoverableException
       * occurs during execution.
       * 
       * @param method the method being executed
       * @param exception the exception that occurred
       * @param executionCount the number of times this method has been 
       * unsuccessfully executed
       * 
       * @return <code>true</code> if the method should be retried, <code>false</code>
       * otherwise
       */
      boolean retryMethod(HttpMethod method, IOException exception, int executionCount);
  
  }
  
  
  
  1.1                  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NoHttpResponseException.java
  
  Index: NoHttpResponseException.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NoHttpResponseException.java,v 1.1 2004/07/05 22:46:58 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/07/05 22:46:58 $
   *
   * ====================================================================
   *
   *  Copyright 1999-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.httpclient;
  
  import java.io.IOException;
  
  import org.apache.commons.httpclient.util.ExceptionUtil;
  
  /**
   * <p>
   * Signals that the target server failed to respond with a valid HTTP response.
   * </p>
   * 
   * @author <a href="mailto:oleg -at- ural.ru">Oleg Kalnichevski</a>
   * 
   * @version $Revision: 1.1 $
   */
  public class NoHttpResponseException extends IOException {
  
      /**
       * Creates a new NoHttpResponseException with a <tt>null</tt> detail message.
       */
      public NoHttpResponseException() {
          super();
      }
  
      /**
       * Creates a new NoHttpResponseException with the specified detail message.
       *
       * @param message exception message
       */
      public NoHttpResponseException(String message) {
          super(message);
      }
  
      /**
       * Creates a new NoHttpResponseException with the specified detail message and cause.
       *
       * @param message the exception detail message
       * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
       * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
       * 
       * @since 3.0
       */
      public NoHttpResponseException(String message, Throwable cause) {
          super(message);
          // If we're running on JDK 1.4 or later, tell Throwable what the cause was
          ExceptionUtil.initCause(this, cause);
      }
  }
  
  
  
  1.6       +6 -3      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/CredentialsProvider.java
  
  Index: CredentialsProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/CredentialsProvider.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CredentialsProvider.java	13 May 2004 04:02:00 -0000	1.5
  +++ CredentialsProvider.java	5 Jul 2004 22:46:59 -0000	1.6
  @@ -39,6 +39,9 @@
    * or given credentials are incorrect. 
    * </p>
    * 
  + * Classes implementing this interface must synchronize access to shared
  + * data as methods of this interfrace may be executed from multiple threads 
  + * 
    * @author Ortwin Glueck
    * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
    * 
  
  
  
  1.11      +7 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java
  
  Index: DefaultHttpParamsFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DefaultHttpParamsFactory.java	17 May 2004 03:46:44 -0000	1.10
  +++ DefaultHttpParamsFactory.java	5 Jul 2004 22:46:59 -0000	1.11
  @@ -32,6 +32,8 @@
   import java.util.ArrayList;
   import java.util.Arrays;
   
  +import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
  +import org.apache.commons.httpclient.HttpMethodRetryHandler;
   import org.apache.commons.httpclient.HttpVersion;
   import org.apache.commons.httpclient.SimpleHttpConnectionManager;
   import org.apache.commons.httpclient.cookie.CookiePolicy;
  @@ -73,7 +75,8 @@
           params.setCookiePolicy(CookiePolicy.RFC_2109);
           params.setHttpElementCharset("US-ASCII");
           params.setContentCharset("ISO-8859-1");
  -
  +        params.setParameter(HttpMethodRetryHandler.HANDLER, new DefaultHttpMethodRetryHandler());
  +        
           ArrayList datePatterns = new ArrayList();
           datePatterns.addAll(
               Arrays.asList(
  
  
  
  1.7       +4 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java
  
  Index: NoHostHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NoHostHttpConnectionManager.java	25 Apr 2004 21:49:35 -0000	1.6
  +++ NoHostHttpConnectionManager.java	5 Jul 2004 22:46:59 -0000	1.7
  @@ -110,7 +110,7 @@
       public HttpConnection getConnectionWithTimeout(
           HostConfiguration hostConfiguration,
           long timeout)
  -        throws ConnectTimeoutException {
  +        throws ConnectionPoolTimeoutException {
           return getConnection(hostConfiguration);
       }
   
  
  
  
  1.3       +4 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestIdleConnectionTimeout.java
  
  Index: TestIdleConnectionTimeout.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestIdleConnectionTimeout.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestIdleConnectionTimeout.java	4 May 2004 21:24:51 -0000	1.2
  +++ TestIdleConnectionTimeout.java	5 Jul 2004 22:46:59 -0000	1.3
  @@ -147,7 +147,7 @@
           }
   
           public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration,
  -            long timeout) throws ConnectTimeoutException {
  +            long timeout) throws ConnectionPoolTimeoutException {
               return null;
           }
   
  
  
  

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


Mime
View raw message