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 3 Jul 2004 21:50:03 -0000
@@ -37,7 +37,7 @@
*
* @since 3.0
*/
-public class ConnectTimeoutException extends HttpTimeoutException {
+public class ConnectTimeoutException extends HttpRecoverableException {
/**
* Creates a ConnectTimeoutException with a null detail message.
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 3 Jul 2004 21:50:05 -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,13 @@
socket.setReceiveBufferSize(rcvBufSize);
}
inputStream = new PushbackInputStream(
- new WrappedInputStream(socket.getInputStream()));
+ socket.getInputStream());
outputStream = new BufferedOutputStream(
new WrappedOutputStream(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,7 +738,7 @@
socket.setReceiveBufferSize(rcvBufSize);
}
inputStream = new PushbackInputStream(
- new WrappedInputStream(socket.getInputStream()));
+ socket.getInputStream());
outputStream = new BufferedOutputStream(
new WrappedOutputStream(socket.getOutputStream()),
socket.getSendBufferSize()
@@ -849,7 +846,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");
}
@@ -1265,9 +1262,7 @@
// 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) {
+ if (!(ioe instanceof InterruptedIOException) && isRecoverable) {
LOG.debug(
"Output exception occurred on a used connection. Will treat as recoverable.",
ioe
@@ -1316,75 +1311,6 @@
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);
}
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 3 Jul 2004 21:50:05 -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 3 Jul 2004 21:50:06 -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 3 Jul 2004 21:50:09 -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;
@@ -171,6 +172,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 +975,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 +1043,7 @@
connectionCloseForced = false;
hostAuthState.invalidate();
proxyAuthState.invalidate();
+ requestSent = false;
}
/**
@@ -1897,7 +1901,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,6 +2260,8 @@
* Returns the {@link MethodRetryHandler retry handler} for this HTTP method
*
* @return the methodRetryHandler
+ *
+ * @deprecated use HttpMethodParams
*/
public MethodRetryHandler getMethodRetryHandler() {
@@ -2270,6 +2276,8 @@
* Sets the {@link MethodRetryHandler retry handler} for this HTTP method
*
* @param handler the methodRetryHandler to use when this method executed
+ *
+ * @deprecated use HttpMethodParams
*/
public void setMethodRetryHandler(MethodRetryHandler handler) {
methodRetryHandler = handler;
@@ -2328,5 +2336,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 3 Jul 2004 21:50:10 -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");
@@ -386,21 +381,20 @@
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
+ MethodRetryHandler handler = null;
+ if (method instanceof HttpMethodBase) {
+ handler = ((HttpMethodBase)method).getMethodRetryHandler();
+ }
+ if (handler == null) {
+ handler = (MethodRetryHandler)method.getParams().getParameter(
+ MethodRetryHandler.HANDLER);
+ }
if (handler == null) {
handler = new DefaultMethodRetryHandler();
}
if (!handler.retryMethod(
- method,
- this.conn,
- httpre,
- execCount,
- requestSent)
- ) {
+ method, this.conn, httpre, execCount, method.isRequestSent())) {
LOG.warn(
"Recoverable exception caught but MethodRetryHandler.retryMethod() "
+ "returned false, rethrowing exception"
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
- *
+ * This parameter expects a value of type {@link MethodRetryHandler}. + *
+ */ + public static final String HANDLER = "http.method.retry-handler"; + + /** * Determines if a method should be retried after an HttpRecoverableException * occurs during execution. * @@ -49,7 +60,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 * * @returntrue 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 3 Jul 2004 21:50:13 -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 3 Jul 2004 21:50:13 -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 3 Jul 2004 21:50:13 -0000
@@ -32,7 +32,9 @@
import java.util.ArrayList;
import java.util.Arrays;
+import org.apache.commons.httpclient.DefaultMethodRetryHandler;
import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.MethodRetryHandler;
import org.apache.commons.httpclient.SimpleHttpConnectionManager;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.util.DateParser;
@@ -73,7 +75,8 @@
params.setCookiePolicy(CookiePolicy.RFC_2109);
params.setHttpElementCharset("US-ASCII");
params.setContentCharset("ISO-8859-1");
-
+ params.setParameter(MethodRetryHandler.HANDLER, new DefaultMethodRetryHandler());
+
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 3 Jul 2004 21:50:14 -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 3 Jul 2004 21:50:14 -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
+ *