Class WebdavServlet

  • All Implemented Interfaces:
    Servlet, ServletConfig, java.io.Serializable

    public class WebdavServlet
    extends DefaultServlet
    Servlet which adds support for WebDAV level 2. All the basic HTTP requests are handled by the DefaultServlet. The WebDAVServlet must not be used as the default servlet (ie mapped to '/') as it will not work in this configuration.

    Mapping a subpath (e.g. /webdav/* to this servlet has the effect of re-mounting the entire web application under that sub-path, with WebDAV access to all the resources. The WEB-INF and META-INF directories are protected in this re-mounted resource tree.

    To enable WebDAV for a context add the following to web.xml:

     <servlet>
      <servlet-name>webdav</servlet-name>
      <servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>listings</param-name>
          <param-value>false</param-value>
        </init-param>
      </servlet>
      <servlet-mapping>
        <servlet-name>webdav</servlet-name>
        <url-pattern>/*</url-pattern>
      </servlet-mapping>
     
    This will enable read only access. To enable read-write access add:
      <init-param>
        <param-name>readonly</param-name>
        <param-value>false</param-value>
      </init-param>
     
    To make the content editable via a different URL, use the following mapping:
      <servlet-mapping>
        <servlet-name>webdav</servlet-name>
        <url-pattern>/webdavedit/*</url-pattern>
      </servlet-mapping>
     
    By default access to /WEB-INF and META-INF are not available via WebDAV. To enable access to these URLs, use add:
      <init-param>
        <param-name>allowSpecialPaths</param-name>
        <param-value>true</param-value>
      </init-param>
     
    Don't forget to secure access appropriately to the editing URLs, especially if allowSpecialPaths is used. With the mapping configuration above, the context will be accessible to normal users as before. Those users with the necessary access will be able to edit content available via http://host:port/context/content using http://host:port/context/webdavedit/content
    Author:
    Remy Maucherat
    See Also:
    RFC 4918, Serialized Form
    • Field Detail

      • DEFAULT_NAMESPACE

        protected static final java.lang.String DEFAULT_NAMESPACE
        Default namespace.
        See Also:
        Constant Field Values
      • creationDateFormat

        protected static final ConcurrentDateFormat creationDateFormat
        Simple date format for the creation date ISO representation (partial).
    • Constructor Detail

      • WebdavServlet

        public WebdavServlet()
    • Method Detail

      • getDocumentBuilder

        protected javax.xml.parsers.DocumentBuilder getDocumentBuilder()
                                                                throws ServletException
        Return JAXP document builder instance.
        Returns:
        the document builder
        Throws:
        ServletException - document builder creation failed (wrapped ParserConfigurationException exception)
      • checkIfHeaders

        protected boolean checkIfHeaders​(HttpServletRequest request,
                                         HttpServletResponse response,
                                         WebResource resource)
                                  throws java.io.IOException
        Description copied from class: DefaultServlet
        Check if the conditions specified in the optional If headers are satisfied.
        Overrides:
        checkIfHeaders in class DefaultServlet
        Parameters:
        request - The servlet request we are processing
        response - The servlet response we are creating
        resource - The resource
        Returns:
        true if the resource meets all the specified conditions, and false if any of the conditions is not satisfied, in which case request processing is stopped
        Throws:
        java.io.IOException - an IO error occurred
      • rewriteUrl

        protected java.lang.String rewriteUrl​(java.lang.String path)
        URL rewriter.
        Overrides:
        rewriteUrl in class DefaultServlet
        Parameters:
        path - Path which has to be rewritten
        Returns:
        the rewritten path
      • getRelativePath

        protected java.lang.String getRelativePath​(HttpServletRequest request)
        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.
        Overrides:
        getRelativePath in class DefaultServlet
        Parameters:
        request - The servlet request we are processing
        Returns:
        the relative path
      • getPathPrefix

        protected java.lang.String getPathPrefix​(HttpServletRequest request)
        Determines the prefix for standard directory GET listings.
        Overrides:
        getPathPrefix in class DefaultServlet
        Parameters:
        request - the request to determine the path for
        Returns:
        the prefix to apply to all resources in the listing.
      • doProppatch

        protected void doProppatch​(HttpServletRequest req,
                                   HttpServletResponse resp)
                            throws java.io.IOException
        PROPPATCH Method.
        Parameters:
        req - The Servlet request
        resp - The Servlet response
        Throws:
        java.io.IOException - If an IO error occurs
      • doPut

        protected void doPut​(HttpServletRequest req,
                             HttpServletResponse resp)
                      throws ServletException,
                             java.io.IOException
        Process a PUT request for the specified resource.
        Overrides:
        doPut in class DefaultServlet
        Parameters:
        req - The servlet request we are processing
        resp - The servlet response we are creating
        Throws:
        java.io.IOException - if an input/output error occurs
        ServletException - if a servlet-specified error occurs
      • doCopy

        protected void doCopy​(HttpServletRequest req,
                              HttpServletResponse resp)
                       throws java.io.IOException
        COPY Method.
        Parameters:
        req - The Servlet request
        resp - The Servlet response
        Throws:
        java.io.IOException - If an IO error occurs
      • doMove

        protected void doMove​(HttpServletRequest req,
                              HttpServletResponse resp)
                       throws java.io.IOException
        MOVE Method.
        Parameters:
        req - The Servlet request
        resp - The Servlet response
        Throws:
        java.io.IOException - If an IO error occurs
      • doUnlock

        protected void doUnlock​(HttpServletRequest req,
                                HttpServletResponse resp)
                         throws java.io.IOException
        UNLOCK Method.
        Parameters:
        req - The Servlet request
        resp - The Servlet response
        Throws:
        java.io.IOException - If an IO error occurs
      • determineMethodsAllowed

        protected java.lang.String determineMethodsAllowed​(HttpServletRequest req)
        Determines the methods normally allowed for the resource.
        Overrides:
        determineMethodsAllowed in class DefaultServlet
        Parameters:
        req - The Servlet request
        Returns:
        The allowed HTTP methods