Author: jukka Date: Fri May 26 03:53:59 2006 New Revision: 409635 URL: http://svn.apache.org/viewvc?rev=409635&view=rev Log: 1.0: Merged revision 392905: JCR-389 Modified: jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java Modified: jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java?rev=409635&r1=409634&r2=409635&view=diff ============================================================================== --- jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java (original) +++ jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java Fri May 26 03:53:59 2006 @@ -119,11 +119,13 @@ /** * Parse the Xml request body and return a {@link org.w3c.dom.Document}. - * If the request body can not be parsed null is returned. * - * @return Document representing the Xml request body or null. + * @return Document representing the Xml request body or null + * if no request body is present. + * @throws DavException If the request body cannot be parsed into an Xml + * Document. */ - public Document getRequestDocument(); + public Document getRequestDocument() throws DavException; /** * Return the type of PROPFIND request as indicated by the PROPFIND request Modified: jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java?rev=409635&r1=409634&r2=409635&view=diff ============================================================================== --- jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java (original) +++ jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java Fri May 26 03:53:59 2006 @@ -56,6 +56,8 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; + +import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -242,15 +244,15 @@ } /** - * @return Xml document * @see DavServletRequest#getRequestDocument() */ - public Document getRequestDocument() { + public Document getRequestDocument() throws DavException { Document requestDocument = null; /* - Don't attempt to parse the body if the contentlength header is 0 - NOTE: a value of -1 indicates that the length is unknown, thus we have to parse the body. - NOTE that http1.1 request using chunked transfer coding will therefore not be detected here + Don't attempt to parse the body if the contentlength header is 0. + NOTE: a value of -1 indicates that the length is unknown, thus we have + to parse the body. Note that http1.1 request using chunked transfer + coding will therefore not be detected here. */ if (httpRequest.getContentLength() == 0) { return requestDocument; @@ -259,19 +261,32 @@ try { InputStream in = httpRequest.getInputStream(); if (in != null) { - DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder(); - requestDocument = docBuilder.parse(in); + // use a buffered input stream to find out whether there actually + // is a request body + InputStream bin = new BufferedInputStream(in); + bin.mark(1); + boolean isEmpty = -1 == bin.read(); + bin.reset(); + if (!isEmpty) { + DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder(); + requestDocument = docBuilder.parse(bin); + } } } catch (IOException e) { if (log.isDebugEnabled()) { log.debug("Unable to build an XML Document from the request body: " + e.getMessage()); } + throw new DavException(DavServletResponse.SC_BAD_REQUEST); } catch (ParserConfigurationException e) { if (log.isDebugEnabled()) { log.debug("Unable to build an XML Document from the request body: " + e.getMessage()); } + throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (SAXException e) { - log.debug("Unable to build an XML Document from the request body: " + e.getMessage()); + if (log.isDebugEnabled()) { + log.debug("Unable to build an XML Document from the request body: " + e.getMessage()); + } + throw new DavException(DavServletResponse.SC_BAD_REQUEST); } return requestDocument; } @@ -313,8 +328,7 @@ private void parsePropFindRequest() throws DavException { propfindProps = new DavPropertyNameSet(); Document requestDocument = getRequestDocument(); - // propfind httpRequest with empty body or invalid Xml >> retrieve all property - // TODO: invalid XML -> spec requires a 'BAD REQUEST' error code + // propfind httpRequest with empty body >> retrieve all property if (requestDocument == null) { return; } @@ -910,4 +924,4 @@ public String getRealPath(String s) { return httpRequest.getRealPath(s); } -} \ No newline at end of file +}