You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@locus.apache.org on 2000/11/28 04:09:16 UTC
cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib WebdavClient.java
remm 00/11/27 19:09:16
Modified: src/webdav/client/src/org/apache/webdav/lib
WebdavClient.java
Log:
- Handles reconnecting with HTTP/1.0 servers.
- Also cleans up a bit the method processing logic.
Revision Changes Path
1.3 +71 -48 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java
Index: WebdavClient.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebdavClient.java 2000/11/27 22:55:51 1.2
+++ WebdavClient.java 2000/11/28 03:09:15 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v 1.2 2000/11/27 22:55:51 remm Exp $
- * $Revision: 1.2 $
- * $Date: 2000/11/27 22:55:51 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v 1.3 2000/11/28 03:09:15 remm Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/11/28 03:09:15 $
*
* ====================================================================
*
@@ -185,63 +185,84 @@
Hashtable responseHeaders = null;
+ boolean methodProcessed = false;
+
openConnection();
- while ( (retries == 0)
- || ((method.getStatusCode() == WebdavStatus.SC_UNAUTHORIZED)
- && (retries < 3))
- || ((method.getStatusCode()
- == WebdavStatus.SC_MOVED_TEMPORARILY)
- && (retries < 3)) ) {
-
- sendRequest(method);
-
- // Parsing response
+ while ((retries < 4) && (!methodProcessed)) {
- // Parse status line
- parseStatusLine(readLine(input), method);
-
- // Parse headers
- responseHeaders = parseHeaders(input);
-
- if (method.getStatusCode() == WebdavStatus.SC_UNAUTHORIZED) {
- // Retrieve the authenticate challenge, if any
- // (needed in case of a digest challenge, for which the header
- // is not constant)
- Header authenticateChallenge =
- (Header) responseHeaders.get("www-authenticate");
- if (authenticateChallenge != null) {
- state.setAuthenticateToken
- (authenticateChallenge.getValue());
- }
- } else if ((method.getStatusCode()
- == WebdavStatus.SC_MOVED_TEMPORARILY)
- && (method.followRedirects())) {
- // Retrieve the location header
- // NOTE : Redirects across servers are not supported yet
- Header location =
- (Header) responseHeaders.get("location");
- if (location != null) {
- String absolutePath = location.getValue();
- if (absolutePath.startsWith("http://")) {
- absolutePath = absolutePath.substring(7);
+ try {
+
+ sendRequest(method);
+
+ // Parsing response
+
+ // Parse status line
+ parseStatusLine(readLine(input), method);
+
+ // Parse headers
+ responseHeaders = parseHeaders(input);
+
+ if (method.getStatusCode() == WebdavStatus.SC_UNAUTHORIZED) {
+ // Retrieve the authenticate challenge, if any
+ // (needed in case of a digest challenge, for which the
+ // header is not constant)
+ Header authenticateChallenge =
+ (Header) responseHeaders.get("www-authenticate");
+ if (authenticateChallenge != null) {
+ state.setAuthenticateToken
+ (authenticateChallenge.getValue());
}
- int slash = absolutePath.indexOf('/');
- if (slash != -1) {
- absolutePath = absolutePath.substring(slash);
+ } else if ((method.getStatusCode()
+ == WebdavStatus.SC_MOVED_TEMPORARILY)
+ && (method.followRedirects())) {
+ // Retrieve the location header
+ // NOTE : Redirects across servers are not supported yet
+ Header location =
+ (Header) responseHeaders.get("location");
+ if (location != null) {
+ String absolutePath = location.getValue();
+ if (absolutePath.startsWith("http://")) {
+ absolutePath = absolutePath.substring(7);
+ }
+ int slash = absolutePath.indexOf('/');
+ if (slash != -1) {
+ absolutePath = absolutePath.substring(slash);
+ }
+ if (absolutePath.equals("")) {
+ absolutePath = "/";
+ }
+ method.setPath(absolutePath);
}
- if (absolutePath.equals("")) {
- absolutePath = "/";
- }
- method.setPath(absolutePath);
}
+
+ if ( (method.getStatusCode() != WebdavStatus.SC_UNAUTHORIZED)
+ && (method.getStatusCode()
+ != WebdavStatus.SC_MOVED_TEMPORARILY) ) {
+ methodProcessed = true;
+ } else {
+ // Consume bytes returned (if any)
+ method.processResponseHeaders(responseHeaders);
+ ResponseInputStream responseInputStream =
+ new ResponseInputStream(input, responseHeaders);
+ responseInputStream.close();
+ }
+
+ } catch (IOException e) {
+ // If something goes wrong, disconnect, then reconnect
+ try {
+ closeConnection();
+ } catch (IOException ex) {
+ // Silent catch
+ }
+ openConnection();
}
retries++;
}
- if (retries == 3) {
+ if (retries == 4) {
throw new WebdavException("Unable to process request");
}
@@ -430,6 +451,8 @@
}
sb.append((char) ch);
}
+ System.out.println("Read Line:" + sb.toString());
+
return (sb.toString());
}