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...@apache.org on 2001/07/22 18:55:45 UTC
cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib WebdavResource.java WebdavSession.java
remm 01/07/22 09:55:45
Modified: src/webdav/client/src/org/apache/webdav/lib
WebdavResource.java WebdavSession.java
Log:
- Fix major thread safety issues due to the use of static fields.
- The options method was static. It's not static anymore. This introduces a
(very simple) change in the command line client.
- Removed some public static calls from WebdavSession. Looking at what
they did, I don't believe they were destined to be used by the end user. If
they were actually used in some other place than WebdavResource, I can
add them back, although the implementation will be empty.
Revision Changes Path
1.19 +19 -18 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- WebdavResource.java 2001/07/22 03:10:26 1.18
+++ WebdavResource.java 2001/07/22 16:55:45 1.19
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v 1.18 2001/07/22 03:10:26 remm Exp $
- * $Revision: 1.18 $
- * $Date: 2001/07/22 03:10:26 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v 1.19 2001/07/22 16:55:45 remm Exp $
+ * $Revision: 1.19 $
+ * $Date: 2001/07/22 16:55:45 $
*
* ====================================================================
*
@@ -198,6 +198,7 @@
*
* @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
* @author Dirk Verbeeck
+ * @author Remy Maucherat
*/
public class WebdavResource extends WebdavSession {
@@ -208,7 +209,9 @@
/**
* Default constructor.
*/
- private WebdavResource() {
+ private WebdavResource(HttpClient client) {
+ super();
+ this.client = client;
}
@@ -702,7 +705,7 @@
}
// Get to know each resource.
- WebdavResource workingResource = new WebdavResource();
+ WebdavResource workingResource = new WebdavResource(client);
workingResource.setDebug(debug);
String displayName = null;
// Process the resource's properties
@@ -1731,10 +1734,15 @@
* @exception HttpException
* @exception IOException
*/
- public String[] list()
- throws HttpException, IOException {
+ public String[] list() {
- setNameProperties(DepthSupport.DEPTH_1);
+ try {
+ setNameProperties(DepthSupport.DEPTH_1);
+ } catch (IOException e) {
+ return null;
+ } catch (HttpException e) {
+ return null;
+ }
Enumeration hrefs = childResources.getResourceNames();
// To be atomic.
@@ -1825,8 +1833,6 @@
State state = client.getState();
if (state != null) {
state.setEncodeURLs(encodeURLs);
- client.setState(state);
- setSession(client);
}
}
@@ -2362,11 +2368,10 @@
* @exception HttpException
* @exception IOException
*/
- public static Enumeration optionsMethod(HttpURL httpURL)
+ public Enumeration optionsMethod(HttpURL httpURL)
throws HttpException, IOException {
- WebdavSession session = new WebdavSession();
- HttpClient client = session.getSessionInstance(httpURL, true);
+ HttpClient client = getSessionInstance(httpURL, true);
OptionsMethod method = new OptionsMethod(httpURL.getPath());
client.executeMethod(method);
@@ -3035,8 +3040,6 @@
int statusCode = method.getStatusCode();
setStatusCode(statusCode, lock);
if (statusCode >= 200 && statusCode < 300) {
- client.setState(state);
- setSession(client);
return true;
}
@@ -3096,8 +3099,6 @@
if (statusCode >= 200 && statusCode < 300) {
state.removeLocks(path);
- client.setState(state);
- setSession(client);
return true;
}
@@ -3175,7 +3176,7 @@
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof WebdavResource)) {
- return compareTo((WebdavResource) obj) == 0;
+ return compareTo(obj) == 0;
}
return false;
}
1.14 +26 -101 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java
Index: WebdavSession.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- WebdavSession.java 2001/07/22 03:10:27 1.13
+++ WebdavSession.java 2001/07/22 16:55:45 1.14
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v 1.13 2001/07/22 03:10:27 remm Exp $
- * $Revision: 1.13 $
- * $Date: 2001/07/22 03:10:27 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v 1.14 2001/07/22 16:55:45 remm Exp $
+ * $Revision: 1.14 $
+ * $Date: 2001/07/22 16:55:45 $
*
* ====================================================================
*
@@ -63,6 +63,7 @@
package org.apache.webdav.lib;
+import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;
@@ -75,10 +76,14 @@
import org.apache.commons.httpclient.StreamInterceptor;
/**
+ * This WebdavSession class is for the session management of WebDAV clients.
+ * This class saves and restores the requested client.
+ *
+ * Although this class is thread safe, it should only be accessed by one
+ * concurrent thread, since the underlying protocol, HTTP, is not multiplexed.
+ * If simultaneous operations are needed, it is recommended to create
+ * additional threads, each having its own associated WebDAV client.
*
- * This WebdavSession class is for the multi-session management of
- * WebDAV clients. This class saves and restores the requested client.
- *
* Clients that use persistent connections SHOULD limit the number of
* simultaneous connections that they maintain to a given server. A
* single-user client SHOULD NOT maintain more than 2 connections with
@@ -89,17 +94,24 @@
*
* @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
*/
-public class WebdavSession implements ConnectionInterceptor {
+public abstract class WebdavSession extends File
+ implements ConnectionInterceptor {
- // ---------------------------------------------------- Instance Variables
+ // ------------------------------------------------------- Constructors
+
/**
- * Infomation hashtable for WebDAV clients HTTP/1.1 communication.
+ * Default constructor.
*/
- private static Hashtable clientInfo = new Hashtable();
-
-
+ public WebdavSession() {
+ super("");
+ }
+
+
+ // ---------------------------------------------------- Instance Variables
+
+
/**
* The Http client instance.
*/
@@ -161,8 +173,7 @@
String authority = httpURL.getAuthority();
if (reset)
- clientInfo.remove(authority);
- HttpClient client = (HttpClient) clientInfo.get(authority);
+ client = null;
if (client == null) {
client = new HttpClient();
// Set a state which allows lock tracking
@@ -174,7 +185,6 @@
client.setCredentials(new Credentials(userName, password));
}
client.setConnectionInterceptor(this);
- clientInfo.put(authority, client);
}
client.setDebug(debug);
@@ -183,87 +193,6 @@
/**
- * Set the session by the given client.
- * In order to save infomration of the client, it must be used.
- *
- * @param client The Http client instance.
- * @exception IOException
- */
- protected synchronized void setSession(HttpClient client)
- throws IOException {
-
- HttpURL httpURL =
- new HttpURL(client.getUserName(), client.getPassword(),
- client.getHost(), client.getPort());
- clientInfo.put(httpURL.getAuthority(), client);
- }
-
-
- /**
- * Test a session to be connected.
- *
- * @param httpURL The http URL to connect. only used the authority part.
- * @return true if connected aleady.
- * @exception MalformedURLException
- */
- public boolean isSession(HttpURL httpURL)
- throws MalformedURLException {
-
- return isSession(httpURL.getAuthority());
- }
-
-
- /**
- * Test a session to be connected.
- *
- * @param authority The authority string.
- * @return true if connected aleady.
- */
- public synchronized boolean isSession(String authority) {
-
- Enumeration authorities = clientInfo.keys();
- while (authorities.hasMoreElements()) {
- if (authority.equals((String) authorities.nextElement())) {
- return true;
- }
- }
- return false;
- }
-
-
- /**
- * Find the sessions having the part of the authority string.
- * The <code>partOfAuthority</code> can be user or host part.
- *
- * @param partOfAuthority The part of the authority string.
- * @return Authorities to include the given string.
- */
- public synchronized Enumeration findSessions(String partOfAuthority) {
-
- Vector sessions = new Vector();
- Enumeration authorities = clientInfo.keys();
- while (authorities.hasMoreElements()) {
- String authority = (String) authorities.nextElement();
- if (authority.indexOf(partOfAuthority) >= 0) {
- sessions.addElement(authority);
- }
- }
-
- return sessions.elements();
- }
-
-
- /**
- * Get all session information.
- *
- * @return Authorities of all session.
- */
- public synchronized Enumeration getSessions() {
- return clientInfo.keys();
- }
-
-
- /**
* Close an session and delete the connection information.
*
* @param client The HttpClient instance.
@@ -271,14 +200,10 @@
*/
public synchronized void closeSession(HttpClient client)
throws IOException {
-
- HttpURL httpURL =
- new HttpURL(client.getUserName(), client.getPassword(),
- client.getHost(), client.getPort());
client.endSession();
- clientInfo.remove(httpURL.getAuthority());
// Remove the progress listener.
// webdavClient.getProgressUtil().addProgressListener(this);
+ client = null;
}