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 re...@apache.org on 2001/07/27 02:31:07 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method AclMethod.java LockMethod.java PropFindMethod.java PropPatchMethod.java WebdavMethod.java

remm        01/07/26 17:31:07

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        AclMethod.java LockMethod.java PropFindMethod.java
                        PropPatchMethod.java WebdavMethod.java
  Log:
  - Only create the DOM DocumentBuilder when the WebdavMethod actually
    needs to parse XML content
  - Don't store the DocumentBuilder as member, as it is only needed
    once in every WebdavMethod subclass that needs XML parsing
  - Return SC_BAD_REQUEST only when a SAXException occurs while parsing
    the XML request, and return SC_INTERNAL_SERVER_ERROR for
    ParserConfigurationException and IOException.
  
  - Patch submitted by Christopher Lenz.
  
  Revision  Changes    Path
  1.9       +12 -9     jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AclMethod.java
  
  Index: AclMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AclMethod.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AclMethod.java	2001/07/25 11:28:07	1.8
  +++ AclMethod.java	2001/07/27 00:31:07	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AclMethod.java,v 1.8 2001/07/25 11:28:07 juergen Exp $
  - * $Revision: 1.8 $
  - * $Date: 2001/07/25 11:28:07 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AclMethod.java,v 1.9 2001/07/27 00:31:07 remm Exp $
  + * $Revision: 1.9 $
  + * $Date: 2001/07/27 00:31:07 $
    *
    * ====================================================================
    *
  @@ -68,9 +68,11 @@
   import java.util.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  +import javax.xml.parsers.ParserConfigurationException;
  +
   import org.w3c.dom.*;
  -import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  +
   import org.apache.util.XMLPrinter;
   import org.apache.util.WebdavStatus;
   import org.apache.util.DOMWriter;
  @@ -82,7 +84,6 @@
   import org.apache.slide.structure.*;
   import org.apache.slide.lock.*;
   import org.apache.slide.content.*;
  -import javax.xml.parsers.DocumentBuilder;
   
   /**
    * ACL method.
  @@ -176,8 +177,7 @@
           if (requestBody.length() != 0) {
               try {
                   
  -                Document document = documentBuilder.parse(new InputSource(
  -                    (new StringReader(requestBody))));
  +                Document document = parseRequestContent();
                   
                   // Get the root element of the document
                   Element acl = document.getDocumentElement();
  @@ -379,8 +379,6 @@
                   System.err.println("You are using using an incorrect older parser");
                   System.err.println("that doesn't provide Element::getElementsByTagNameNS");
                   System.err.println("consult the documentation for a list of valid parsers.");
  -                System.err.println("You are currently using: ");
  -                System.err.println("   " + documentBuilder.getClass().getName());
                   e.printStackTrace();
                   resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                   throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  @@ -390,6 +388,11 @@
                   e.printStackTrace();
                   resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
                   throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            } catch (ParserConfigurationException e) {
  +                System.err.println(e.getMessage());
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
               } catch (IOException e) {
                   e.printStackTrace();
                   resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  
  
  
  1.18      +34 -44    jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java
  
  Index: LockMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- LockMethod.java	2001/07/25 11:28:07	1.17
  +++ LockMethod.java	2001/07/27 00:31:07	1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java,v 1.17 2001/07/25 11:28:07 juergen Exp $
  - * $Revision: 1.17 $
  - * $Date: 2001/07/25 11:28:07 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java,v 1.18 2001/07/27 00:31:07 remm Exp $
  + * $Revision: 1.18 $
  + * $Date: 2001/07/27 00:31:07 $
    *
    * ====================================================================
    *
  @@ -68,8 +68,11 @@
   import java.util.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  +import javax.xml.parsers.ParserConfigurationException;
  +
   import org.w3c.dom.*;
  -import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
   import org.apache.util.XMLPrinter;
   import org.apache.util.DOMWriter;
   import org.apache.util.WebdavStatus;
  @@ -80,7 +83,6 @@
   import org.apache.slide.content.*;
   import org.apache.slide.security.AccessDeniedException;
   import org.apache.slide.structure.*;
  -import javax.xml.parsers.DocumentBuilder;
   
   /**
    * LOCK method.
  @@ -151,12 +153,6 @@
       
       
       /**
  -     * MS Proprietary properties support.
  -     */
  -    private boolean msProprietarySupport;
  -    
  -    
  -    /**
        * Lock scope.
        */
       private String lockInfo_lockScope;
  @@ -209,31 +205,24 @@
        */
       protected void parseRequest()
           throws WebdavException {
  -        
  -        // Show request
  -        //if (req.getContentLength() > 0) {
  -        //    System.out.println(requestBody);
  -        //}
           
  -        msProprietarySupport = isMsProprietarySupport();
  -        
  -    // Loads the associated object from the store.
  -    lockInfo_lockSubject = requestUri;
  -    if (lockInfo_lockSubject == null) {
  -        lockInfo_lockSubject = "/";
  -    }
  +        // Loads the associated object from the store.
  +        lockInfo_lockSubject = requestUri;
  +        if (lockInfo_lockSubject == null) {
  +            lockInfo_lockSubject = "/";
  +        }
           
  -    String depthStr = req.getHeader("Depth");
  +        String depthStr = req.getHeader("Depth");
       
  -    if (depthStr == null) {
  -        depth = INFINITY;
  -    } else {
  -        if (depthStr.equals("0")) {
  -        depth = 0;
  +        if (depthStr == null) {
  +            depth = INFINITY;
           } else {
  +            if (depthStr.equals("0")) {
  +                depth = 0;
  +            } else {
                   depth = INFINITY;
  +            }
           }
  -    }
           
           String lockDurationStr = req.getHeader("Timeout");
           if (lockDurationStr != null) {
  @@ -256,32 +245,33 @@
                   lockDuration = MAX_TIMEOUT;
               }
           }
  -        
  -        // For some strange reason, IIS doesn't handle properly
  -        // lock expiration.
  -        /*
  -          if (isMsProprietarySupport()) {
  -          lockDuration = MAX_TIMEOUT;
  -          }
  -        */
           
  -    if (req.getContentLength() > 0) {
  +        if (req.getContentLength() > 0) {
               
               lockType = LOCK_CREATION;
               
               Node lockInfoNode = null;
               
               try {
  -                Document document = documentBuilder.parse(new InputSource
  -                    (new StringReader(requestBody)));
  +                Document document = parseRequestContent();
                   
                   // Get the root element of the document
                   Element rootElement = document.getDocumentElement();
                   lockInfoNode = rootElement;
  -            } catch(Exception e) {
  +            } catch (SAXException e) {
  +                resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +                throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            } catch (ParserConfigurationException e) {
  +                System.err.println(e.getMessage());
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +            } catch (IOException e) {
  +                System.err.println(e.getMessage());
                   e.printStackTrace();
  -        resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -        throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
               }
               
               NodeList childList = lockInfoNode.getChildNodes();
  
  
  
  1.32      +20 -10    jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java
  
  Index: PropFindMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- PropFindMethod.java	2001/07/25 11:28:07	1.31
  +++ PropFindMethod.java	2001/07/27 00:31:07	1.32
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v 1.31 2001/07/25 11:28:07 juergen Exp $
  - * $Revision: 1.31 $
  - * $Date: 2001/07/25 11:28:07 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v 1.32 2001/07/27 00:31:07 remm Exp $
  + * $Revision: 1.32 $
  + * $Date: 2001/07/27 00:31:07 $
    *
    * ====================================================================
    *
  @@ -68,9 +68,11 @@
   import java.util.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  -import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.ParserConfigurationException;
  +
   import org.w3c.dom.*;
  -import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
   import org.apache.util.XMLPrinter;
   import org.apache.util.WebdavStatus;
   import org.apache.slide.authenticate.CredentialsToken;
  @@ -352,9 +354,7 @@
               Node propNode = null;
               
               try {
  -                Document document =
  -                    documentBuilder.parse(new InputSource
  -                                              (new StringReader(requestBody)));
  +                Document document = parseRequestContent();
                   
                   // Get the root element of the document
                   Element rootElement = document.getDocumentElement();
  @@ -379,10 +379,20 @@
                               break;
                       }
                   }
  -            } catch(Exception e) {
  -                e.printStackTrace();
  +            } catch (SAXException e) {
                   resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
                   throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            } catch (ParserConfigurationException e) {
  +                System.err.println(e.getMessage());
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +            } catch (IOException e) {
  +                System.err.println(e.getMessage());
  +                e.printStackTrace();
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
               }
               
               if (propFindType == FIND_BY_PROPERTY) {
  
  
  
  1.17      +20 -10    jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java
  
  Index: PropPatchMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- PropPatchMethod.java	2001/07/25 11:28:07	1.16
  +++ PropPatchMethod.java	2001/07/27 00:31:07	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v 1.16 2001/07/25 11:28:07 juergen Exp $
  - * $Revision: 1.16 $
  - * $Date: 2001/07/25 11:28:07 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v 1.17 2001/07/27 00:31:07 remm Exp $
  + * $Revision: 1.17 $
  + * $Date: 2001/07/27 00:31:07 $
    *
    * ====================================================================
    *
  @@ -68,8 +68,11 @@
   import java.util.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  +import javax.xml.parsers.ParserConfigurationException;
  +
   import org.w3c.dom.*;
  -import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
   import org.apache.util.XMLPrinter;
   import org.apache.util.DOMWriter;
   import org.apache.util.WebdavStatus;
  @@ -80,7 +83,6 @@
   import org.apache.slide.structure.*;
   import org.apache.slide.lock.*;
   import org.apache.slide.content.*;
  -import javax.xml.parsers.DocumentBuilder;
   
   /**
    * PROPPATCH method.
  @@ -165,9 +167,7 @@
                   Node setNode = null;
                   Node removeNode = null;
                   
  -                Document document =
  -                    documentBuilder.parse
  -                    (new InputSource(new StringReader(requestBody)));
  +                Document document = parseRequestContent();
                   
                   // Get the root element of the document
                   Element rootElement = document.getDocumentElement();
  @@ -214,10 +214,20 @@
                       }
                   }
                   
  -            } catch(Exception e) {
  -                e.printStackTrace();
  +            } catch (SAXException e) {
                   resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
                   throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            } catch (ParserConfigurationException e) {
  +                System.err.println(e.getMessage());
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +            } catch (IOException e) {
  +                System.err.println(e.getMessage());
  +                e.printStackTrace();
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
               }
           } else {
               try {
  
  
  
  1.31      +40 -21    jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java
  
  Index: WebdavMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- WebdavMethod.java	2001/07/25 11:28:07	1.30
  +++ WebdavMethod.java	2001/07/27 00:31:07	1.31
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v 1.30 2001/07/25 11:28:07 juergen Exp $
  - * $Revision: 1.30 $
  - * $Date: 2001/07/25 11:28:07 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v 1.31 2001/07/27 00:31:07 remm Exp $
  + * $Revision: 1.31 $
  + * $Date: 2001/07/27 00:31:07 $
    *
    * ====================================================================
    *
  @@ -68,12 +68,17 @@
   import java.security.NoSuchAlgorithmException;
   import java.io.*;
   import java.util.*;
  +
   import javax.servlet.*;
   import javax.servlet.http.*;
   import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.ParserConfigurationException;
  -import org.w3c.dom.*;
  +
  +import org.w3c.dom.Document;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
   import org.apache.util.URLUtil;
   import org.apache.util.MD5Encoder;
   import org.apache.util.WebdavStatus;
  @@ -138,6 +143,7 @@
        * Servlet context.
        */
       protected ServletContext context;
  +
       
       /**
        * Request body.
  @@ -188,12 +194,6 @@
       
       
       /**
  -     * DOM XML parser.
  -     */
  -    protected DocumentBuilder documentBuilder;
  -    
  -    
  -    /**
        * MD5 message digest provider.
        */
       protected static MessageDigest md5Helper;
  @@ -229,17 +229,6 @@
       public WebdavMethod(GenericServlet servlet, NamespaceAccessToken token,
                           HttpServletRequest req, HttpServletResponse resp) {
           
  -        if (documentBuilder == null) {
  -            try {
  -                DocumentBuilderFactory factory =
  -                    DocumentBuilderFactory.newInstance();
  -                factory.setNamespaceAware(true);
  -                documentBuilder = factory.newDocumentBuilder();
  -            } catch(ParserConfigurationException e) {
  -                e.printStackTrace();
  -            }
  -        }
  -        
           this.req = req;
           this.resp = resp;
           this.servlet = servlet;
  @@ -548,6 +537,36 @@
           throws WebdavException, IOException;
       
       
  +    /**
  +     * Parse WebDAV XML request body, and return the DOM representation.
  +     *
  +     * @exception ParserConfigurationException If the JAXP factory cannot
  +     *             configure a parser given its current configuration 
  +     *             parameters.
  +     * @exception SAXException If any parse errors occur.
  +     * @exception IOException If any IO errors occur.
  +     */
  +    protected Document parseRequestContent()
  +        throws ParserConfigurationException, SAXException, IOException {
  +
  +        if (requestBody == null) {
  +            readRequestContent();
  +            if (requestBody == null) {
  +                // there is no request content body, so there's nothing to 
  +                // parse
  +                return null;
  +            }
  +        }
  +
  +        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  +        factory.setNamespaceAware(true);
  +
  +        DocumentBuilder builder = factory.newDocumentBuilder();
  +        return builder.parse(new InputSource(new StringReader(requestBody)));
  +
  +    }
  +
  +
       /**
        * Generate XML response.
        *