Fix a handful of failures when using the litmus WebDAV testsuite.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 3 Apr 2009 10:28:40 +0000 (10:28 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 3 Apr 2009 10:28:40 +0000 (10:28 +0000)
Still other failures but these appear to relate to the lack of PROPPATCH support.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@761601 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/servlets/WebdavServlet.java
java/org/apache/naming/resources/FileDirContext.java

index cfa0125..94b0b12 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.catalina.servlets;
 
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
@@ -463,7 +464,7 @@ public class WebdavServlet
 
         Node propNode = null;
         
-        if (req.getInputStream().available() > 0) {
+        if (req.getContentLength() > 0) {
             DocumentBuilder documentBuilder = getDocumentBuilder();
     
             try {
@@ -494,9 +495,11 @@ public class WebdavServlet
                     }
                 }
             } catch (SAXException e) {
-                // Something went wrong - use the defaults.
+                // Something went wrong - bad request
+                resp.sendError(WebdavStatus.SC_BAD_REQUEST);
             } catch (IOException e) {
-                // Something went wrong - use the defaults.
+                // Something went wrong - bad request
+                resp.sendError(WebdavStatus.SC_BAD_REQUEST);
             }
         }
 
@@ -1662,14 +1665,20 @@ public class WebdavServlet
                                       path, destinationPath);
 
         if ((!result) || (!errorList.isEmpty())) {
-
-            sendReport(req, resp, errorList);
+            if (errorList.size() == 1) {
+                resp.sendError(errorList.elements().nextElement().intValue());
+            } else {
+                sendReport(req, resp, errorList);
+            }
             return false;
-
         }
 
         // Copy was successful
-        resp.setStatus(WebdavStatus.SC_CREATED);
+        if (exists) {
+            resp.setStatus(WebdavStatus.SC_NO_CONTENT);
+        } else {
+            resp.setStatus(WebdavStatus.SC_CREATED);
+        }
 
         // Removing any lock-null resource which would be present at
         // the destination path
@@ -1739,9 +1748,15 @@ public class WebdavServlet
                 try {
                     resources.bind(dest, object);
                 } catch (NamingException e) {
-                    errorList.put
-                        (source,
-                         new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
+                    if (e.getCause() instanceof FileNotFoundException) {
+                        // We know the source exists so it must be the
+                        // destination dir that can't be found
+                        errorList.put(source,
+                                new Integer(WebdavStatus.SC_CONFLICT));
+                    } else {
+                        errorList.put(source,
+                                new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
+                    }
                     return false;
                 }
             } else {
index 1bdd9db..f42c367 100644 (file)
@@ -578,8 +578,10 @@ public class FileDirContext extends BaseDirContext {
                 is.close();
             }
         } catch (IOException e) {
-            throw new NamingException
-                (sm.getString("resources.bindFailed", e));
+            NamingException ne = new NamingException
+                    (sm.getString("resources.bindFailed", e));
+            ne.initCause(e);
+            throw ne;
         }
 
     }