juergen 01/09/01 09:43:42
Modified: src/webdav/client/src/org/apache/commons/httpclient
HttpClient.java
Log:
try to add some robustness code
1) retry to open the connection 5 times in case of an error
2) if the body could not be sent (e.g. the server was already finished) try to read
the response and if available do not throw an error.
anyway this did not really help with our sporadic connect problems. The client gurus
could take a look at the changes.
Revision Changes Path
1.3 +55 -18
jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java
Index: HttpClient.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpClient.java 2001/08/13 17:02:55 1.2
+++ HttpClient.java 2001/09/01 16:43:42 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java,v
1.2 2001/08/13 17:02:55 dirkv Exp $
- * $Revision: 1.2 $
- * $Date: 2001/08/13 17:02:55 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java,v
1.3 2001/09/01 16:43:42 juergen Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/09/01 16:43:42 $
*
* ====================================================================
*
@@ -89,7 +89,7 @@
* in your JRE's <tt>java.security</tt> file) and with the
* VM that is running the HttpClient (e.g., set the
* system property <tt>java.protocol.handler.pkgs</tt>
- * to include your provider, such as
+ * to include your provider, such as
* <tt>com.sun.net.ssl.internal.www.protocol</tt>
* for the reference implementation of JSSE).
*
@@ -419,21 +419,46 @@
boolean methodProcessed = false;
boolean sentRequestBody = false;
- openConnection();
+ while ((retries < 5) && (!methodProcessed)) {
+ try {
+ openConnection();
+ methodProcessed = true;
+
+ }
+ catch (java.net.ConnectException e) {
+// System.out.println("##################11111 =" + retries);
+// e.printStackTrace();
+// System.out.println("##################11111 =" + retries);
+ retries++;
+ if (retries == 5) {
+// System.out.println("######### ERROR #########11111 =" + retries);
+ throw e;
+ }
+ }
+ }
+
+ retries = 0;
+ methodProcessed = false;
while ((retries < 5) && (!methodProcessed)) {
try {
responseHeaders = null;
sentRequestBody = false;
+ IOException requestException = null;
// Send the request header except if the
byte[] query = sendRequestHeader(method);
if ((!http11) || (!method.needExpectation())) {
- sendRequestBody(method, query);
- sentRequestBody = true;
+ try {
+ sendRequestBody(method, query);
+ sentRequestBody = true;
+ }
+ catch (IOException e) {
+ requestException = e;
+ }
}
if (connectionInterceptor != null) {
@@ -457,8 +482,10 @@
// Parse status line
String statusLine = readLine(input);
- if (statusLine == null)
- throw new IOException("Couldn't parse status line");
+ if (statusLine == null) { // we can't read the status
+ if (requestException != null) throw requestException; //
incomplete body
+ throw new IOException("Couldn't parse status line"); // other
problem
+ }
parseStatusLine(statusLine, method);
// Parse headers
@@ -475,9 +502,15 @@
if (!sentRequestBody) {
if (connectionInterceptor != null) {
connectionInterceptor.receivedExpectation();
+ }
+ try {
+ sendRequestBody(method, query);
+ sentRequestBody = true;
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ throw e;
}
- sendRequestBody(method, query);
- sentRequestBody = true;
}
}
@@ -557,7 +590,7 @@
// Consume bytes returned (if any)
method.processResponseHeaders(responseHeaders);
ResponseInputStream responseInputStream =
- new ResponseInputStream(input, method,
+ new ResponseInputStream(input, method,
responseHeaders);
// FIXME : Really set the interceptors here ?
// The content is meant to be discarded
@@ -607,6 +640,10 @@
openConnection();
}
+// if (!methodProcessed) {
+// new Exception("do not care").printStackTrace();
+// methodProcessed = methodProcessed;
+// }
retries++;
}
@@ -689,7 +726,7 @@
/**
* Start a session.
*/
- public void startSession(String host, int port, Credentials creds,
+ public void startSession(String host, int port, Credentials creds,
boolean https) {
if (debug > 0)
System.out.println("Start session : Host:" + host
@@ -716,13 +753,13 @@
*/
public void startSession(URL url) {
if("https".equalsIgnoreCase(url.getProtocol())) {
- startSession(url.getHost(), url.getPort() == -1 ? 443
+ startSession(url.getHost(), url.getPort() == -1 ? 443
: url.getPort(),true);
} else if("http".equalsIgnoreCase(url.getProtocol())) {
- startSession(url.getHost(), url.getPort() == -1 ? 80
+ startSession(url.getHost(), url.getPort() == -1 ? 80
: url.getPort(),false);
} else {
- throw new IllegalArgumentException("Protocol " + url.getProtocol()
+ throw new IllegalArgumentException("Protocol " + url.getProtocol()
+ " not supported in URL " + url);
}
}
@@ -745,7 +782,7 @@
/**
* Start a session with a proxy server.
*/
- public void startSession(String host, int port,
+ public void startSession(String host, int port,
String proxyhost, int proxyport) {
this.proxyHost = proxyhost;
this.proxyPort = proxyport;
@@ -1190,7 +1227,7 @@
*/
protected boolean needToCloseOutput(HttpMethod method) {
if (!http11) {
- if ((method.isStreamedQuery())
+ if ((method.isStreamedQuery())
&& (method.getHeader("Content-Length") == null)
&& (method.needContentLength())) {
return true;