Index: java/org/apache/commons/httpclient/ConnectTimeoutException.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectTimeoutException.java,v retrieving revision 1.4 diff -u -r1.4 ConnectTimeoutException.java --- java/org/apache/commons/httpclient/ConnectTimeoutException.java 13 May 2004 04:03:25 -0000 1.4 +++ java/org/apache/commons/httpclient/ConnectTimeoutException.java 4 Jul 2004 18:06:46 -0000 @@ -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 null detail message. @@ -63,7 +67,9 @@ * if the cause is unavailable, unknown, or not a Throwable */ 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); } } Index: java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java,v retrieving revision 1.3 diff -u -r1.3 DefaultMethodRetryHandler.java --- java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java 18 Apr 2004 23:51:34 -0000 1.3 +++ java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java 4 Jul 2004 18:06:46 -0000 @@ -35,6 +35,8 @@ * @author Michael Becke * * @see HttpMethodBase#setMethodRetryHandler(MethodRetryHandler) + * + * @deprecated use {@link org.apache.commons.httpclient.DefaultHttpMethodRetryHandler} */ public class DefaultMethodRetryHandler implements MethodRetryHandler { Index: java/org/apache/commons/httpclient/HttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v retrieving revision 1.95 diff -u -r1.95 HttpConnection.java --- java/org/apache/commons/httpclient/HttpConnection.java 25 Jun 2004 03:34:56 -0000 1.95 +++ java/org/apache/commons/httpclient/HttpConnection.java 4 Jul 2004 18:06:50 -0000 @@ -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 Index: java/org/apache/commons/httpclient/HttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java,v retrieving revision 1.23 diff -u -r1.23 HttpConnectionManager.java --- java/org/apache/commons/httpclient/HttpConnectionManager.java 17 May 2004 21:46:03 -0000 1.23 +++ java/org/apache/commons/httpclient/HttpConnectionManager.java 4 Jul 2004 18:06:50 -0000 @@ -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. Index: java/org/apache/commons/httpclient/HttpMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v retrieving revision 1.40 diff -u -r1.40 HttpMethod.java --- java/org/apache/commons/httpclient/HttpMethod.java 13 Jun 2004 20:22:18 -0000 1.40 +++ java/org/apache/commons/httpclient/HttpMethod.java 4 Jul 2004 18:06:52 -0000 @@ -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 true if the HTTP has been transmitted to the target + * server in its entirety, false 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 true if the request has been sent, false otherwise + */ + boolean isRequestSent(); } Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.209 diff -u -r1.209 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 24 Jun 2004 21:39:52 -0000 1.209 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 4 Jul 2004 18:06:58 -0000 @@ -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 true if the HTTP has been transmitted to the target + * server in its entirety, false 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 true if the request has been sent, false otherwise + */ + public boolean isRequestSent() { + return this.requestSent; + } + } Index: java/org/apache/commons/httpclient/HttpMethodDirector.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v retrieving revision 1.27 diff -u -r1.27 HttpMethodDirector.java --- java/org/apache/commons/httpclient/HttpMethodDirector.java 25 Jun 2004 03:34:56 -0000 1.27 +++ java/org/apache/commons/httpclient/HttpMethodDirector.java 4 Jul 2004 18:07:01 -0000 @@ -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) { Index: java/org/apache/commons/httpclient/HttpRecoverableException.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java,v retrieving revision 1.14 diff -u -r1.14 HttpRecoverableException.java --- java/org/apache/commons/httpclient/HttpRecoverableException.java 13 May 2004 04:03:25 -0000 1.14 +++ java/org/apache/commons/httpclient/HttpRecoverableException.java 4 Jul 2004 18:07:01 -0000 @@ -29,10 +29,6 @@ package org.apache.commons.httpclient; -import java.io.IOException; - -import org.apache.commons.httpclient.util.ExceptionUtil; - /** *

* 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. *

+ * + * @deprecated no longer used + * * @author Unascribed * @version $Revision: 1.14 $ $Date: 2004/05/13 04:03:25 $ */ -public class HttpRecoverableException extends IOException { +public class HttpRecoverableException extends HttpException { /** * Creates a new HttpRecoverableException with a null 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 Throwable that caused this exception, or null - * if the cause is unavailable, unknown, or not a Throwable - * - * @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); - } } Index: java/org/apache/commons/httpclient/HttpTimeoutException.java =================================================================== RCS file: java/org/apache/commons/httpclient/HttpTimeoutException.java diff -N java/org/apache/commons/httpclient/HttpTimeoutException.java --- java/org/apache/commons/httpclient/HttpTimeoutException.java 13 May 2004 04:03:25 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,70 +0,0 @@ -/* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpTimeoutException.java,v 1.5 2004/05/13 04:03:25 mbecke Exp $ - * $Revision: 1.5 $ - * $Date: 2004/05/13 04:03:25 $ - * - * ==================================================================== - * - * 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 - * . - * - */ - -package org.apache.commons.httpclient; - -/** - * A timeout while processing an HTTP request: for example a network - * timeout or a timeout while waiting for an HttpConnection to become - * available. - * - * @author Laura Werner - * - * @since 3.0 - */ -public class HttpTimeoutException extends HttpRecoverableException { - - /** - * Creates a new HttpTimeoutException with a null detail message. - */ - public HttpTimeoutException() { - super(); - } - - /** - * Creates a new HttpTimeoutException with the specified detail message. - * - * @param message The exception detail message - */ - public HttpTimeoutException(String message) { - super(message); - } - - /** - * Creates a new HttpTimeoutException with the specified detail message and cause. - * - * @param message the exception detail message - * @param cause the Throwable that caused this exception, or null - * if the cause is unavailable, unknown, or not a Throwable - */ - public HttpTimeoutException(String message, Throwable cause) { - super(message, cause); - } - -} Index: java/org/apache/commons/httpclient/IOTimeoutException.java =================================================================== RCS file: java/org/apache/commons/httpclient/IOTimeoutException.java diff -N java/org/apache/commons/httpclient/IOTimeoutException.java --- java/org/apache/commons/httpclient/IOTimeoutException.java 13 May 2004 04:03:25 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,68 +0,0 @@ -/* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/IOTimeoutException.java,v 1.4 2004/05/13 04:03:25 mbecke Exp $ - * $Revision: 1.4 $ - * $Date: 2004/05/13 04:03:25 $ - * - * ==================================================================== - * - * 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 - * . - * - */ - -package org.apache.commons.httpclient; - -/** - * A I/O or network timeout while communicating with an HTTP server. - * - * @author Laura Werner - * - * @since 3.0 - */ -public class IOTimeoutException extends HttpTimeoutException { - - /** - * Creates a IOTimeoutException with a null detail message. - */ - public IOTimeoutException() { - super(); - } - - /** - * Creates a IOTimeoutException with a specified message. - * - * @param message The exception detail message - */ - public IOTimeoutException(String message) { - super(message); - } - - /** - * Creates a new IOTimeoutException with the specified detail message and cause. - * - * @param message the exception detail message - * @param cause the Throwable that caused this exception, or null - * if the cause is unavailable, unknown, or not a Throwable - */ - public IOTimeoutException(String message, Throwable cause) { - super(message, cause); - } - -} Index: java/org/apache/commons/httpclient/MethodRetryHandler.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MethodRetryHandler.java,v retrieving revision 1.4 diff -u -r1.4 MethodRetryHandler.java --- java/org/apache/commons/httpclient/MethodRetryHandler.java 18 Apr 2004 23:51:35 -0000 1.4 +++ java/org/apache/commons/httpclient/MethodRetryHandler.java 4 Jul 2004 18:07:01 -0000 @@ -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 true if the method should be retried, false * otherwise Index: java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v retrieving revision 1.40 diff -u -r1.40 MultiThreadedHttpConnectionManager.java --- java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 25 Jun 2004 03:34:56 -0000 1.40 +++ java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 4 Jul 2004 18:07:05 -0000 @@ -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()) { Index: java/org/apache/commons/httpclient/auth/CredentialsProvider.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/CredentialsProvider.java,v retrieving revision 1.5 diff -u -r1.5 CredentialsProvider.java --- java/org/apache/commons/httpclient/auth/CredentialsProvider.java 13 May 2004 04:02:00 -0000 1.5 +++ java/org/apache/commons/httpclient/auth/CredentialsProvider.java 4 Jul 2004 18:07:06 -0000 @@ -39,6 +39,9 @@ * or given credentials are incorrect. *

* + * 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 Oleg Kalnichevski * Index: java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java,v retrieving revision 1.10 diff -u -r1.10 DefaultHttpParamsFactory.java --- java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 17 May 2004 03:46:44 -0000 1.10 +++ java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 4 Jul 2004 18:07:06 -0000 @@ -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( Index: test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java,v retrieving revision 1.6 diff -u -r1.6 NoHostHttpConnectionManager.java --- test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 25 Apr 2004 21:49:35 -0000 1.6 +++ test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 4 Jul 2004 18:07:07 -0000 @@ -110,7 +110,7 @@ public HttpConnection getConnectionWithTimeout( HostConfiguration hostConfiguration, long timeout) - throws ConnectTimeoutException { + throws ConnectionPoolTimeoutException { return getConnection(hostConfiguration); } Index: test/org/apache/commons/httpclient/TestIdleConnectionTimeout.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestIdleConnectionTimeout.java,v retrieving revision 1.2 diff -u -r1.2 TestIdleConnectionTimeout.java --- test/org/apache/commons/httpclient/TestIdleConnectionTimeout.java 4 May 2004 21:24:51 -0000 1.2 +++ test/org/apache/commons/httpclient/TestIdleConnectionTimeout.java 4 Jul 2004 18:07:07 -0000 @@ -147,7 +147,7 @@ } public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, - long timeout) throws ConnectTimeoutException { + long timeout) throws ConnectionPoolTimeoutException { return null; } Index: java/org/apache/commons/httpclient/ConnectionPoolTimeoutException.java =================================================================== RCS file: java/org/apache/commons/httpclient/ConnectionPoolTimeoutException.java diff -N java/org/apache/commons/httpclient/ConnectionPoolTimeoutException.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/ConnectionPoolTimeoutException.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,69 @@ +/* + * $Header$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * 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 + * . + * + */ + +package org.apache.commons.httpclient; + +/** + * A timeout while connecting waiting for an available connection + * from an HttpConnectionManager. + * + * @author Laura Werner + * + * @since 3.0 + */ +public class ConnectionPoolTimeoutException extends ConnectTimeoutException { + + /** + * Creates a ConnectTimeoutException with a null 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 Throwable that caused this exception, or null + * if the cause is unavailable, unknown, or not a Throwable + */ + public ConnectionPoolTimeoutException(String message, Throwable cause) { + super(message, cause); + } + +} Index: java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java =================================================================== RCS file: java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java diff -N java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,110 @@ +/* + * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java,v 1.3 2004/04/18 23:51:34 jsdever Exp $ + * $Revision: 1.3 $ + * $Date: 2004/04/18 23:51:34 $ + * + * ==================================================================== + * + * 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 + * . + * + */ + +package org.apache.commons.httpclient; + +import java.io.IOException; + +/** + * The default {@link HttpMethodRetryHandler} used by {@link HttpMethod}s. + * + * @author Michael Becke + * @author Oleg Kalnichevski + */ +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 retryCount and requestSentRetryEnabled 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 true if this handler will retry methods that have + * successfully sent their request, false otherwise + */ + public boolean isRequestSentRetryEnabled() { + return requestSentRetryEnabled; + } + + /** + * @return the maximum number of times a method will be retried + */ + public int getRetryCount() { + return retryCount; + } +} Index: java/org/apache/commons/httpclient/HttpMethodRetryHandler.java =================================================================== RCS file: java/org/apache/commons/httpclient/HttpMethodRetryHandler.java diff -N java/org/apache/commons/httpclient/HttpMethodRetryHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/HttpMethodRetryHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,73 @@ +/* + * $Header$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * 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 + * . + * + */ + +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. + * + *

+ * Classes implementing this interface must synchronize access to shared + * data as methods of this interfrace may be executed from multiple threads + *

+ * + * @see HttpMethod#execute(HttpState, HttpConnection) + * @see HttpRecoverableException + * + * @author Michael Becke + * @author Oleg Kalnichevski + */ +public interface HttpMethodRetryHandler { + + /** + * Sets the method retry handler parameter. + *

+ * This parameter expects a value of type {@link HttpMethodRetryHandler}. + *

+ */ + 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 true if the method should be retried, false + * otherwise + */ + boolean retryMethod(HttpMethod method, IOException exception, int executionCount); + +} Index: java/org/apache/commons/httpclient/NoHttpResponseException.java =================================================================== RCS file: java/org/apache/commons/httpclient/NoHttpResponseException.java diff -N java/org/apache/commons/httpclient/NoHttpResponseException.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/NoHttpResponseException.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,77 @@ +/* + * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java,v 1.14 2004/05/13 04:03:25 mbecke Exp $ + * $Revision: 1.14 $ + * $Date: 2004/05/13 04:03:25 $ + * + * ==================================================================== + * + * 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 + * . + * + */ + +package org.apache.commons.httpclient; + +import java.io.IOException; + +import org.apache.commons.httpclient.util.ExceptionUtil; + +/** + *

+ * Signals that the target server failed to respond with a valid HTTP response. + *

+ * + * @author Oleg Kalnichevski + * + * @version $Revision$ + */ +public class NoHttpResponseException extends IOException { + + /** + * Creates a new NoHttpResponseException with a null 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 Throwable that caused this exception, or null + * if the cause is unavailable, unknown, or not a Throwable + * + * @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); + } +}