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 "Kumar, Ashok" <ak...@metatomix.com> on 2001/08/23 18:57:17 UTC

WebDav Client Implementation

Hi

Can U throw some light on this implementation 

Is it right ??

   HttpClient client=new HttpClient();
   client.startSession("localhost",8080,new Credentials("mtx","mtx02"));
   client.setDebug(9);
   MkcolMethod mc=new MkcolMethod();
   mc.setPath("/slide/files/test4");
   client.executeMethod(mc);
   PutMethod pm = new PutMethod(HttpURL.getPathQuery("files/test4"));
   pm.sendData("Testing hello YES OK");
   client.executeMethod(pm);
   client.endSession();

The collection is made properly
But the Put method seems to be not working...

Regards Ashok@metatomix

-----Original Message-----
From: Robert Owen [mailto:eurrow@sas.com]
Sent: Thursday, August 23, 2001 11:36 AM
To: 'slide-dev@jakarta.apache.org'
Subject: Status for properties in multistatus


In the Slide webdav client, I am getting -1 for the status for
properties
returned in a PROPFIND or PROPPATCH (getStatus on
org.apache.webdav.lib.Property). The problem is that the multistatus can
have a status element at the same level as href[Rob]  (as per RFC2518),
but
for these methods usually has the status value in a propstat element (a
combined status for a number of properties). The code in
ResponseWithinMultiStatus in XMLResponseMethodBase only looks for a
status
element on the same level as href with getFirstElement[Rob] , doesn't
find
it and returns -1. 

This may not be the best way of fixing this (using XPath might also be
an
option), and I'm not sure what impact changing the interface in
BaseProperty
will have on things that I am not using, but this is now working for me.

XMLResponseMethodBase.java
--- XMLResponseMethodBase_1.19.java	Tue Jul 24 18:05:52 2001
+++ XMLResponseMethodBase.java	Tue Jul 24 17:15:53 2001
@@ -395,7 +395,37 @@
             }
         }
 
-        public String getHref() {
+         public int getStatusCode(Element property)
+        {
+           try
+           {
+              // We should be able to go up to find the <D:prop>
element
and once more to find the
+              // <D:propstat> element and this shoud have a <D:status>
element which gives us the
+              // status for this property
+              org.w3c.dom.Element propElement =
(org.w3c.dom.Element)property.getParentNode();
+              // ASSERT (propElement.getLocalName().equals("prop"))
+              org.w3c.dom.Element propstatElement =
(org.w3c.dom.Element)propElement.getParentNode();
+              // ASSERT
(propstatElement.getLocalName().equals("propstat"));
+              NodeList list = propstatElement.getChildNodes();
+              org.w3c.dom.Element statusElement = null;
+              for (int i=0; i<list.getLength(); i++)
+              {
+                 if (list.item(i) instanceof org.w3c.dom.Element)
+                 {
+                    statusElement = (org.w3c.dom.Element)list.item(i);
+                    if (statusElement.getLocalName().equals("status")
&&
statusElement.getNamespaceURI().equals("DAV:"))
+                    {
+                       Node statusNode = statusElement.getFirstChild();
+                       return
DOMUtils.parseStatus(((org.w3c.dom.Text)statusNode).getData());
+                    }
+                 }
+              }
+           }
+           catch (ClassCastException e) {}
+           return -1;
+        }
+
+       public String getHref() {
             Element href = getFirstElement("DAV:", "href");
             if (href != null) {
                 return
getState().URLDecode(DOMUtils.getTextValue(href));
@@ -438,6 +468,10 @@
         }
 
         public int getStatusCode() {
+            return this.statusCode;
+        }
+
+        public int getStatusCode(org.w3c.dom.Element element) {
             return this.statusCode;
         }




--- BaseProperty_1.1.java	Tue Jul 24 17:52:45 2001
+++ BaseProperty.java	Tue Jul 10 16:01:31 2001
@@ -169,7 +169,14 @@
      * This method returns the status code associated with the
property.
      */
     public int getStatusCode() {
-        return response.getStatusCode();
+        int sc = response.getStatusCode();
+        if (sc == -1)
+        {
+			// find the status code for this property
+			sc = response.getStatusCode(this.element);
+		}
+		return sc;
+      // return response.getStatusCode();
     }
 



--- ResponseEntity_1.1.java	Tue Jul 24 17:52:57 2001
+++ ResponseEntity.java	Tue Jul 10 15:58:18 2001
@@ -99,6 +99,15 @@
      */
     public int getStatusCode();
 
+    /**
+     * Get the status code in context for the element within 207
(Multi-Status).
+     *
+     * Unless explicitly prohibited any 2/3/4/5xx series
+     * response code may be used in a Multi-Status response.
+     *
+     * @return the status code.
+     */
+    public int getStatusCode(org.w3c.dom.Element element);
 
     /**
      * Get the properties in the response XML element.