Index: java/org/apache/commons/httpclient/ConnectMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java,v
retrieving revision 1.11
diff -u -r1.11 ConnectMethod.java
--- java/org/apache/commons/httpclient/ConnectMethod.java 4 Apr 2003 02:37:02 -0000 1.11
+++ java/org/apache/commons/httpclient/ConnectMethod.java 16 Apr 2003 03:04:49 -0000
@@ -200,6 +200,13 @@
protected boolean shouldCloseConnection() {
return (getStatusCode() != HttpStatus.SC_OK);
}
+
+ /**
+ * @return true.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return true;
+ }
/** Log object for this class. */
private static final Log LOG = LogFactory.getLog(ConnectMethod.class);
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.132
diff -u -r1.132 HttpMethodBase.java
--- java/org/apache/commons/httpclient/HttpMethodBase.java 9 Apr 2003 18:37:59 -0000 1.132
+++ java/org/apache/commons/httpclient/HttpMethodBase.java 16 Apr 2003 03:04:55 -0000
@@ -220,6 +220,12 @@
* HttpRecoverableException.
*/
private int maxRetries = 3;
+
+ /**
+ * Whether or not this method is recoverable after the request is successfully
+ * sent, but a recoverable exception occurs when reading the response.
+ */
+ private boolean recoverableAfterReqest;
/** true if we are currently executing */
private boolean inExecute = false;
@@ -236,6 +242,7 @@
* No-arg constructor.
*/
public HttpMethodBase() {
+ this.recoverableAfterReqest = getDefaultRecoverableAfterRequest();
}
/**
@@ -252,6 +259,7 @@
public HttpMethodBase(String uri)
throws IllegalArgumentException, IllegalStateException {
+ this();
try {
// create a URI and allow for null/empty uri values
@@ -2403,6 +2411,7 @@
"enter HttpMethodBase.processRequest(HttpState, HttpConnection)");
//try to do the write
+ boolean requestSent = false;
int retryCount = 0;
do {
retryCount++;
@@ -2414,41 +2423,40 @@
LOG.debug("Opening the connection.");
connection.open();
}
+ requestSent = false;
writeRequest(state, connection);
- used = true; //write worked, mark this method as used
- break; //move onto the write
+ requestSent = true;
+ readResponse(state, connection);
+
+ // the mehod has successfully executed
+ used = true;
+ break;
} catch (HttpRecoverableException httpre) {
if (LOG.isDebugEnabled()) {
LOG.debug("Closing the connection.");
}
+ connection.close();
+
+ if (requestSent && !isRecoverableAfterReqest()) {
+ LOG.warn(
+ "Recoverable exception caught when reading response and "
+ + "recoverableAfterRequest is not set."
+ );
+ throw httpre;
+ }
// update the recoverable exception count.
recoverableExceptionCount++;
- connection.close();
- LOG.info("Recoverable exception caught when writing request");
+ LOG.info("Recoverable exception caught when processing request");
if (retryCount == maxRetries) {
LOG.warn(
- "Attempt to write request has reached max retries: "
+ "Attempt to process request has reached max retries: "
+ maxRetries);
throw httpre;
}
}
} while (retryCount <= maxRetries);
-
- //try to do the read
- try {
- readResponse(state, connection);
- } catch (HttpRecoverableException httpre) {
- LOG.warn("Recoverable exception caught when reading response");
- if (LOG.isDebugEnabled()) {
- LOG.debug("Closing the connection.");
- }
-
- connection.close();
- throw httpre;
- }
- //everything should be OK at this point
}
/**
@@ -2566,5 +2574,42 @@
public void setHostConfiguration(HostConfiguration hostConfiguration) {
this.hostConfiguration = hostConfiguration;
}
+
+ /**
+ * Tests if this method is recoverable in the event an
+ * HttpRecoverableException occurs after the request has been
+ * successfully sent (i.e. when the response is being read). If true
+ * this method will be retried.
+ *
+ * @return the flag
+ *
+ * @see #setRetryAfterReqest(boolean)
+ */
+ public boolean isRecoverableAfterReqest() {
+ return recoverableAfterReqest;
+ }
+
+ /**
+ * Sets a flag indicating if this method is recoverable in the event an
+ * HttpRecoverableException occurs after the request has been
+ * successfully sent (i.e. when the response is being read). If true
+ * this method will be retried.
+ *
+ * @param recoverableAfterReqest the flag to set
+ *
+ * @see #getDefaultRetryAfterRequest()
+ */
+ public void setRecoverableAfterReqest(boolean recoverableAfterReqest) {
+ this.recoverableAfterReqest = recoverableAfterReqest;
+ }
+
+ /**
+ * Gets the default value to set for recoverableAfterReqest.
+ *
+ * @return the default value to use
+ *
+ * @see #setRecoverableAfterReqest(boolean)
+ */
+ protected abstract boolean getDefaultRecoverableAfterRequest();
}
Index: java/org/apache/commons/httpclient/methods/DeleteMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java,v
retrieving revision 1.11
diff -u -r1.11 DeleteMethod.java
--- java/org/apache/commons/httpclient/methods/DeleteMethod.java 2 Feb 2003 04:30:13 -0000 1.11
+++ java/org/apache/commons/httpclient/methods/DeleteMethod.java 16 Apr 2003 03:04:56 -0000
@@ -125,5 +125,11 @@
return "DELETE";
}
-
+ /**
+ * @return true.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return true;
+ }
+
}
Index: java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java,v
retrieving revision 1.5
diff -u -r1.5 ExpectContinueMethod.java
--- java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java 6 Apr 2003 22:31:54 -0000 1.5
+++ java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java 16 Apr 2003 03:04:56 -0000
@@ -154,6 +154,13 @@
return this.useExpectHeader;
}
+ /**
+ * @return false.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return false;
+ }
+
/**
* Sets the useExpectHeader.
*
Index: java/org/apache/commons/httpclient/methods/GetMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v
retrieving revision 1.23
diff -u -r1.23 GetMethod.java
--- java/org/apache/commons/httpclient/methods/GetMethod.java 2 Feb 2003 04:30:13 -0000 1.23
+++ java/org/apache/commons/httpclient/methods/GetMethod.java 16 Apr 2003 03:04:57 -0000
@@ -310,7 +310,13 @@
return super.getResponseBodyAsStream();
}
-
+ /**
+ * @return true.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return true;
+ }
+
/**
* Temporary directory setter.
*
Index: java/org/apache/commons/httpclient/methods/HeadMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v
retrieving revision 1.17
diff -u -r1.17 HeadMethod.java
--- java/org/apache/commons/httpclient/methods/HeadMethod.java 2 Feb 2003 04:30:13 -0000 1.17
+++ java/org/apache/commons/httpclient/methods/HeadMethod.java 16 Apr 2003 03:04:57 -0000
@@ -147,6 +147,13 @@
setFollowRedirects(true);
}
+ /**
+ * @return true.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return true;
+ }
+
/**
* Overrides {@link HttpMethodBase} method to not read a response
* body, despite the presence of a Content-Length or
Index: java/org/apache/commons/httpclient/methods/OptionsMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/OptionsMethod.java,v
retrieving revision 1.12
diff -u -r1.12 OptionsMethod.java
--- java/org/apache/commons/httpclient/methods/OptionsMethod.java 2 Feb 2003 04:30:13 -0000 1.12
+++ java/org/apache/commons/httpclient/methods/OptionsMethod.java 16 Apr 2003 03:04:58 -0000
@@ -178,6 +178,13 @@
// ----------------------------------------------------- HttpMethod Methods
+ /**
+ * @return true.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return true;
+ }
+
/**
* Process the response headers.
* @param state The state.
Index: java/org/apache/commons/httpclient/methods/TraceMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/TraceMethod.java,v
retrieving revision 1.11
diff -u -r1.11 TraceMethod.java
--- java/org/apache/commons/httpclient/methods/TraceMethod.java 2 Feb 2003 04:30:13 -0000 1.11
+++ java/org/apache/commons/httpclient/methods/TraceMethod.java 16 Apr 2003 03:04:58 -0000
@@ -136,6 +136,13 @@
public void recycle() {
super.recycle();
setFollowRedirects(false);
+ }
+
+ /**
+ * @return true.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return true;
}
}
Index: test/org/apache/commons/httpclient/SimpleHttpMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpMethod.java,v
retrieving revision 1.6
diff -u -r1.6 SimpleHttpMethod.java
--- test/org/apache/commons/httpclient/SimpleHttpMethod.java 13 Mar 2003 17:51:28 -0000 1.6
+++ test/org/apache/commons/httpclient/SimpleHttpMethod.java 16 Apr 2003 03:04:59 -0000
@@ -96,6 +96,13 @@
return "Simple";
}
+ /**
+ * @return true.
+ */
+ protected boolean getDefaultRecoverableAfterRequest() {
+ return true;
+ }
+
/**
* Makes sure any respose header that exists has been added to the response
* header group.
Index: test/org/apache/commons/httpclient/TestResponseHeaders.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java,v
retrieving revision 1.6
diff -u -r1.6 TestResponseHeaders.java
--- test/org/apache/commons/httpclient/TestResponseHeaders.java 23 Jan 2003 22:48:27 -0000 1.6
+++ test/org/apache/commons/httpclient/TestResponseHeaders.java 16 Apr 2003 03:05:00 -0000
@@ -91,20 +91,6 @@
return new TestSuite(TestResponseHeaders.class);
}
-
-
- /**
- * Simple extension of HttpMethodBase.
- */
- private class SimpleHttpMethod extends HttpMethodBase {
- public SimpleHttpMethod() {
- super("");
- }
- public String getName() {
- return "simple";
- }
- }
-
// ----------------------------------------------------------- Test Methods
public void testHeaders() throws Exception {
String body = "XXX\r\nYYY\r\nZZZ";