From: markt Date: Mon, 30 Jul 2007 23:37:47 +0000 (+0000) Subject: Fix WebDAV for MS clients. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f3f862fac332a46ff2bd57e9664b24939b636dc1;p=tomcat7.0 Fix WebDAV for MS clients. Fix error message when there is no request content Ported from TC5 git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@561186 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java index 6b30ab96b..88312fc2e 100644 --- a/java/org/apache/catalina/servlets/WebdavServlet.java +++ b/java/org/apache/catalina/servlets/WebdavServlet.java @@ -44,6 +44,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.apache.catalina.Globals; import org.apache.catalina.util.DOMWriter; import org.apache.catalina.util.MD5Encoder; import org.apache.catalina.util.RequestUtil; @@ -312,6 +313,35 @@ public class WebdavServlet /** + * Override the DefaultServlet implementation and only use the PathInfo. If + * the ServletPath is non-null, it will be because the WebDAV servlet has + * been mapped to a url other than /* to configure editing at different url + * than normal viewing. + * + * @param request The servlet request we are processing + */ + protected String getRelativePath(HttpServletRequest request) { + + // Are we being processed by a RequestDispatcher.include()? + if (request.getAttribute(Globals.INCLUDE_REQUEST_URI_ATTR) != null) { + String result = (String) request.getAttribute( + Globals.INCLUDE_PATH_INFO_ATTR); + if ((result == null) || (result.equals(""))) + result = "/"; + return (result); + } + + // No, extract the desired path directly from the request + String result = request.getPathInfo(); + if ((result == null) || (result.equals(""))) { + result = "/"; + } + return (result); + + } + + + /** * OPTIONS Method. * * @param req The request @@ -381,40 +411,42 @@ public class WebdavServlet } Node propNode = null; - - DocumentBuilder documentBuilder = getDocumentBuilder(); - - try { - Document document = documentBuilder.parse - (new InputSource(req.getInputStream())); - - // Get the root element of the document - Element rootElement = document.getDocumentElement(); - NodeList childList = rootElement.getChildNodes(); - - for (int i=0; i < childList.getLength(); i++) { - Node currentNode = childList.item(i); - switch (currentNode.getNodeType()) { - case Node.TEXT_NODE: - break; - case Node.ELEMENT_NODE: - if (currentNode.getNodeName().endsWith("prop")) { - type = FIND_BY_PROPERTY; - propNode = currentNode; - } - if (currentNode.getNodeName().endsWith("propname")) { - type = FIND_PROPERTY_NAMES; - } - if (currentNode.getNodeName().endsWith("allprop")) { - type = FIND_ALL_PROP; + + if (req.getInputStream().available() > 0) { + DocumentBuilder documentBuilder = getDocumentBuilder(); + + try { + Document document = documentBuilder.parse + (new InputSource(req.getInputStream())); + + // Get the root element of the document + Element rootElement = document.getDocumentElement(); + NodeList childList = rootElement.getChildNodes(); + + for (int i=0; i < childList.getLength(); i++) { + Node currentNode = childList.item(i); + switch (currentNode.getNodeType()) { + case Node.TEXT_NODE: + break; + case Node.ELEMENT_NODE: + if (currentNode.getNodeName().endsWith("prop")) { + type = FIND_BY_PROPERTY; + propNode = currentNode; + } + if (currentNode.getNodeName().endsWith("propname")) { + type = FIND_PROPERTY_NAMES; + } + if (currentNode.getNodeName().endsWith("allprop")) { + type = FIND_ALL_PROP; + } + break; } - break; } + } catch (SAXException e) { + // Something went wrong - use the defaults. + } catch (IOException e) { + // Something went wrong - use the defaults. } - } catch (SAXException e) { - // Most likely there was no content : we use the defaults. - } catch (IOException e) { - // Most likely there was no content : we use the defaults. } if (type == FIND_BY_PROPERTY) { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 35e64089e..8663dc760 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -26,6 +26,9 @@ stop to fail. Based on a fix suggested by Michael Vorburger. Port of r454193 (36976) from Tomcat 5.5.x. (markt,rjung) + + Fix WebDAV Servlet so it works correctly with MS clients. (markt) +