jericho 01/05/04 01:16:18
Modified: src/webdav/client/src/org/apache/webdav/lib
WebdavSession.java WebdavResource.java
Log:
- Make sure to be set the client for each methods.
Because the resource might be set with NOACTION.
After the resource of setting NOACTION, some methods could be called.
- For above, Add the checking and setting client methods.
- Change the order to be set the connected information,
after setting the client in the WebdavSession class. (Not important though)
Revision Changes Path
1.5 +12 -15
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebdavSession.java 2001/05/02 23:15:01 1.4
+++ WebdavSession.java 2001/05/04 08:16:11 1.5
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v
1.4 2001/05/02 23:15:01 remm Exp $
- * $Revision: 1.4 $
- * $Date: 2001/05/02 23:15:01 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v
1.5 2001/05/04 08:16:11 jericho Exp $
+ * $Revision: 1.5 $
+ * $Date: 2001/05/04 08:16:11 $
*
* ====================================================================
*
@@ -128,11 +128,6 @@
throws IOException {
synchronized (clientInfo) {
- String authority = httpURL.getAuthority();
- if (!clientInfo.contains(authority)) {
- clientInfo.addElement(authority);
- }
-
HttpClient client = new HttpClient();
client.startSession(httpURL.toURL());
String userName = httpURL.getUserName();
@@ -141,7 +136,11 @@
client.setCredentials(new Credentials(userName, password));
}
//client.getProgressUtil().addProgressListener(this);
-
+ String authority = httpURL.getAuthority();
+ if (!clientInfo.contains(authority)) {
+ clientInfo.addElement(authority);
+ }
+
return client;
}
}
@@ -156,11 +155,9 @@
*/
public boolean isSession(HttpURL httpURL)
throws MalformedURLException {
-
- synchronized (clientInfo) {
- String authority = httpURL.getAuthority();
- return isSession(authority);
- }
+
+ String authority = httpURL.getAuthority();
+ return isSession(authority);
}
@@ -233,7 +230,7 @@
// Remove the progress listener.
//webdavClient.getProgressUtil().addProgressListener(this);
}
-
+
client.endSession();
}
}
1.3 +71 -20
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebdavResource.java 2001/05/01 21:28:18 1.2
+++ WebdavResource.java 2001/05/04 08:16:13 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v
1.2 2001/05/01 21:28:18 remm Exp $
- * $Revision: 1.2 $
- * $Date: 2001/05/01 21:28:18 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v
1.3 2001/05/04 08:16:13 jericho Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/05/04 08:16:13 $
*
* ====================================================================
*
@@ -791,6 +791,49 @@
/**
+ * Test that the httpURL is the same with the client.
+ *
+ * @return true if the given httpURL is the client for this resource.
+ */
+ private synchronized boolean isTheClient() throws MalformedURLException {
+
+ HttpURL clientHttpURL =
+ new HttpURL(client.getUserName(), client.getPassword(),
+ client.getHost(), client.getPort());
+
+ return clientHttpURL.getAuthority().equals(httpURL.getAuthority());
+ }
+
+
+ /**
+ * Set the client for this resource.
+ *
+ * @exception IOException
+ */
+ private void setClient() throws IOException {
+ setClient(httpURL);
+ }
+
+
+ /**
+ * Set the client for this resource and the given http URL.
+ *
+ * @param httpURL The http URL.
+ * @exception IOException
+ */
+ private synchronized void setClient(HttpURL httpURL) throws IOException {
+
+ if ((client == null) || ((client != null) && !isTheClient())) {
+ if (client != null) {
+ closeSession(client);
+ }
+ client = getSessionInstance(httpURL);
+ client.setDebug(debug);
+ }
+ }
+
+
+ /**
* Set the HttpURL for this WebdavResource.
*
* @param httpURL the specified HttpURL.
@@ -806,14 +849,8 @@
public void setHttpURL(HttpURL httpURL, int action, int depth)
throws HttpException, IOException {
- if (!isSession(httpURL)) {
- if (client != null) {
- closeSession(client);
- }
- client = getSessionInstance(httpURL);
- client.setDebug(debug);
- }
this.httpURL = httpURL;
+ setClient(httpURL);
// make its existence false
setExistence(false);
setProperties(action, depth);
@@ -1629,6 +1666,7 @@
public InputStream getMethodData()
throws HttpException, IOException {
+ setClient();
// use disk to save by default
GetMethod method = new GetMethod(httpURL.getPath());
method.setUseDisk(useDiskForGet);
@@ -1651,6 +1689,7 @@
public String getMethodDataAsString()
throws HttpException, IOException {
+ setClient();
GetMethod method = new GetMethod(httpURL.getPath());
method.setUseDisk(useDiskForGet);
if (tempDirForGet != null)
@@ -1689,6 +1728,7 @@
public boolean getMethod(String path, File file)
throws HttpException, IOException {
+ setClient();
// use disk to save by default
GetMethod method = new GetMethod(HttpURL.getPathQuery(path), file);
method.setUseDisk(true);
@@ -1732,6 +1772,7 @@
public boolean putMethod(String path, String data)
throws HttpException, IOException {
+ setClient();
PutMethod method = new PutMethod(HttpURL.getPath(path));
method.sendData(data);
method.setDebug(debug);
@@ -1774,6 +1815,7 @@
public boolean putMethod(String path, File file)
throws HttpException, IOException {
+ setClient();
PutMethod method = new PutMethod(HttpURL.getPath(path));
method.sendData(file);
method.setDebug(debug);
@@ -1819,6 +1861,7 @@
public boolean putMethod(String path, URL url)
throws HttpException, IOException {
+ setClient();
PutMethod method = new PutMethod(HttpURL.getPath(path));
method.sendData(url);
method.setDebug(debug);
@@ -1857,6 +1900,7 @@
public boolean optionsMethod(String path)
throws HttpException, IOException {
+ setClient();
OptionsMethod method;
if (path.trim().equals("*"))
method = new OptionsMethod("*");
@@ -1982,10 +2026,10 @@
public Enumeration propfindMethod(String path, int depth)
throws HttpException, IOException {
- // Check the path alright.
- path = HttpURL.getPath(path);
+ setClient();
// Change the depth for allprop
- PropFindMethod method = new PropFindMethod(path, depth);
+ PropFindMethod method =
+ new PropFindMethod(HttpURL.getPath(path), depth);
method.setDebug(debug);
// Default depth=infinity, type=allprop
client.executeMethod(method);
@@ -2046,11 +2090,11 @@
Vector properties)
throws HttpException, IOException {
- // Check the path alright.
- path = HttpURL.getPath(path);
+ setClient();
// Change the depth for prop
- PropFindMethod method = new PropFindMethod(path, depth,
- properties.elements());
+ PropFindMethod method =
+ new PropFindMethod(HttpURL.getPath(path), depth,
+ properties.elements());
method.setDebug(debug);
client.executeMethod(method);
@@ -2135,11 +2179,10 @@
public Enumeration propfindMethod(String path, Vector properties)
throws HttpException, IOException {
- // Check the path alright.
- path = HttpURL.getPath(path);
+ setClient();
// Default depth=0, type=by_name
PropFindMethod method =
- new PropFindMethod(path, DepthSupport.DEPTH_0,
+ new PropFindMethod(HttpURL.getPath(path), DepthSupport.DEPTH_0,
properties.elements());
method.setDebug(debug);
client.executeMethod(method);
@@ -2246,6 +2289,7 @@
public boolean proppatchMethod(String path, Hashtable property)
throws HttpException, IOException {
+ setClient();
PropPatchMethod method = new PropPatchMethod(HttpURL.getPath(path));
Enumeration names = property.keys();
boolean hasSomething = false;
@@ -2300,6 +2344,7 @@
public boolean headMethod(String path)
throws HttpException, IOException {
+ setClient();
HeadMethod method = new HeadMethod(HttpURL.getPath(path));
method.setDebug(debug);
client.executeMethod(method);
@@ -2339,6 +2384,7 @@
public boolean deleteMethod(String path)
throws HttpException, IOException {
+ setClient();
DeleteMethod method = new DeleteMethod(HttpURL.getPath(path));
method.setDebug(debug);
client.executeMethod(method);
@@ -2381,6 +2427,7 @@
public boolean moveMethod(String source, String destination)
throws HttpException, IOException {
+ setClient();
MoveMethod method = new MoveMethod(source, destination);
method.setDebug(debug);
client.executeMethod(method);
@@ -2426,6 +2473,7 @@
public boolean copyMethod(String source, String destination)
throws HttpException, IOException {
+ setClient();
CopyMethod method = new CopyMethod(source, destination);
method.setDebug(debug);
client.executeMethod(method);
@@ -2468,6 +2516,7 @@
public boolean mkcolMethod(String path)
throws HttpException, IOException {
+ setClient();
MkcolMethod method = new MkcolMethod(HttpURL.getPath(path));
method.setDebug(debug);
client.executeMethod(method);
@@ -2562,6 +2611,7 @@
public boolean lockMethod(String path, String owner, short timeout)
throws HttpException, IOException {
+ setClient();
// default lock type setting
short lockType = LockMethod.SCOPE_EXCLUSIVE;
LockMethod method =
@@ -2616,6 +2666,7 @@
public boolean unlockMethod(String path)
throws HttpException, IOException {
+ setClient();
// Get the lock for the given path.
State state = client.getState();
// Check the given path is alright.