Top Description Inners Fields Constructors Methods
org.apache.catalina.servlets

public Class WebdavServlet

Additional top-level class in compilation unit: WebdavStatus.

extends DefaultServlet
Class Inheritance
Imports
java.io.IOException, .InputStream, .Serializable, .StringReader, .StringWriter, .Writer, java.net.URI, .URISyntaxException, java.nio.charset.StandardCharsets, java.util.ArrayDeque, .ArrayList, .Collections, .Date, .Deque, .HashMap, .Iterator, .List, .Locale, .Map, .TimeZone, java.util.concurrent.ConcurrentHashMap, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, .ParserConfigurationException, jakarta.servlet.DispatcherType, .RequestDispatcher, .ServletContext, .ServletException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.apache.catalina.WebResource, org.apache.catalina.connector.RequestFacade, org.apache.catalina.util.DOMWriter, .XMLWriter, org.apache.tomcat.util.buf.HexUtils, org.apache.tomcat.util.http.ConcurrentDateFormat, .FastHttpDateFormat, .RequestUtil, org.apache.tomcat.util.security.ConcurrentMessageDigest, org.w3c.dom.Document, .Element, .Node, .NodeList, org.xml.sax.EntityResolver, .InputSource, .SAXException

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
WebdavServlet.LockInfo

Holds a lock information.

private static class
WebdavServlet.WebdavResolver

Work around for XML parsers that don't fully respect DocumentBuilderFactory#setExpandEntityReferences(boolean) when called with false.

Field Summary

Modifier and TypeField and Description
private boolean
allowSpecialPaths

Is access allowed via WebDAV to the special paths (/WEB-INF and /META-INF)?

private final List<WebdavServlet.LockInfo>
collectionLocks

List of the inheritable collection locks.

protected static final ConcurrentDateFormat
creationDateFormat

Simple date format for the creation date ISO representation (partial).

protected static final String
DEFAULT_NAMESPACE

Default namespace.

private static final int
DEFAULT_TIMEOUT

Default lock timeout value.

private static final int
FIND_ALL_PROP

PROPFIND - Display all properties.

private static final int
FIND_BY_PROPERTY

PROPFIND - Specify a property mask.

private static final int
FIND_PROPERTY_NAMES

PROPFIND - Return property names.

private static final int
LOCK_CREATION

Create a new lock.

private static final int
LOCK_REFRESH

Refresh lock.

private final Map<String, List<String>>
lockNullResources

Repository of the lock-null resources.

private static final int
MAX_TIMEOUT

Maximum lock timeout.

private int
maxDepth

Default depth in spec is infinite.

private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private final Map<String, WebdavServlet.LockInfo>
resourceLocks

Repository of the locks put on single resources.

private String
secret

Secret information used to generate reasonably secure lock ids.

private static final long
Inherited from org.apache.catalina.servlets.DefaultServlet:
BUFFER_SIZEcompressionFormatscontextXsltFiledebugfileEncodingFULLglobalXsltFileinputlistingslocalXsltFilemimeSeparationoutputreadmeFilereadOnlyresourcessendfileSizeshowServerInfosmsortListingssortManageruseAcceptRanges

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean
checkIfHeaders(HttpServletRequest
The servlet request we are processing
request
,
HttpServletResponse
The servlet response we are creating
response
,
WebResource
The resource
resource
)

Overrides org.apache.catalina.servlets.DefaultServlet.checkIfHeaders.

Check if the conditions specified in the optional If headers are satisfied.

private boolean

Returns:

boolean true if the copy is successful
copyResource
(HttpServletRequest
Servlet request
req
,
HttpServletResponse
Servlet response
resp
)

Copy a resource.

private boolean

Returns:

true if the copy was successful
copyResource
(Map<String, Integer>
Map containing the list of errors which occurred during the copy operation
errorList
,
String
Path of the resource to be copied
source
,
String
Destination path
dest
)

Copy a collection.

private void
deleteCollection(HttpServletRequest
The Servlet request
req
,
String
Path to the collection to be deleted
path
,
Map<String, Integer>
Contains the list of the errors which occurred
errorList
)

Deletes a collection.

private boolean

Returns:

true if the delete is successful
deleteResource
(HttpServletRequest
Servlet request
req
,
HttpServletResponse
Servlet response
resp
)

Delete a resource.

private boolean

Returns:

true if the delete is successful
deleteResource
(String
Path of the resource which is to be deleted
path
,
HttpServletRequest
Servlet request
req
,
HttpServletResponse
Servlet response
resp
,
boolean
Should the response status be set on successful completion
setStatus
)

Delete a resource.

protected String

Returns:

The allowed HTTP methods
determineMethodsAllowed
(HttpServletRequest
The Servlet request
req
)

Overrides org.apache.catalina.servlets.DefaultServlet.determineMethodsAllowed.

Determines the methods normally allowed for the resource.

protected void
doCopy(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

COPY Method.

protected void
doDelete(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

Overrides org.apache.catalina.servlets.DefaultServlet.doDelete.

DELETE Method.

protected void
doLock(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

LOCK Method.

protected void
doMkcol(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

MKCOL Method.

protected void
doMove(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

MOVE Method.

protected void
doOptions(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

Overrides org.apache.catalina.servlets.DefaultServlet.doOptions.

OPTIONS Method.

protected void
doPropfind(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

PROPFIND Method.

protected void
doProppatch(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

PROPPATCH Method.

protected void
doPut(HttpServletRequest
The servlet request we are processing
req
,
HttpServletResponse
The servlet response we are creating
resp
)

Overrides org.apache.catalina.servlets.DefaultServlet.doPut.

Process a PUT request for the specified resource.

protected void
doUnlock(HttpServletRequest
The Servlet request
req
,
HttpServletResponse
The Servlet response
resp
)

UNLOCK Method.

private boolean

Returns:

true if at least one lock was displayed
generateLockDiscovery
(String
Path
path
,
XMLWriter
XML data to which the locks info will be appended
generatedXML
)

Print the lock discovery information associated with a path.

private void
generatePropFindResponse(XMLWriter generatedXML, String rewrittenUrl, String path, int propFindType, List<String> properties, boolean isFile, boolean isLockNull, long created, long lastModified, long contentLength, String contentType, String eTag)

protected DocumentBuilder

Returns:

the document builder
getDocumentBuilder
()

Return JAXP document builder instance.

private String

Returns:

the formatted creation date
getISOCreationDate
(long creationDate)

Get creation date in ISO format.

protected String
getPathPrefix(final HttpServletRequest
the request to determine the path for
request
)

Overrides org.apache.catalina.servlets.DefaultServlet.getPathPrefix.

Determines the prefix for standard directory GET listings.

protected String
getRelativePath(HttpServletRequest
The servlet request we are processing
request
)

Overrides org.apache.catalina.servlets.DefaultServlet.getRelativePath.

Override the DefaultServlet implementation and only use the PathInfo.

protected String
public void
init()

Overrides org.apache.catalina.servlets.DefaultServlet.init.

Initialize this servlet.

private boolean

Returns:

true if the resource is locked (and no appropriate lock token has been found for at least one of the non-shared locks which are present on the resource).
isLocked
(HttpServletRequest
Servlet request
req
)

Check to see if a resource is currently write locked.

private boolean

Returns:

true if the resource is locked (and no appropriate lock token has been found for at least one of the non-shared locks which are present on the resource).
isLocked
(String
Path of the resource
path
,
String
"If" HTTP header which was included in the request
ifHeader
)

Check to see if a resource is currently write locked.

private boolean

Returns:

true if the resource specified is under a special path
isSpecialPath
(final String
the full path of the resource being accessed
path
)

Checks whether a given path refers to a resource under WEB-INF or META-INF.

private void
parseLockNullProperties(HttpServletRequest
The servlet request
req
,
XMLWriter
XML response to the Propfind request
generatedXML
,
String
Path of the current resource
path
,
int
Propfind type
type
,
List<String>
If the propfind type is find properties by name, then this List contains those properties
properties
)

Propfind helper method.

private void
parseProperties(HttpServletRequest
The servlet request
req
,
XMLWriter
XML response to the Propfind request
generatedXML
,
String
Path of the current resource
path
,
int
Propfind type
type
,
List<String>
If the propfind type is find properties by name, then this List contains those properties
properties
)

Propfind helper method.

private void
sendReport(HttpServletRequest
Servlet request
req
,
HttpServletResponse
Servlet response
resp
,
Map<String, Integer>
List of error to be displayed
errorList
)

Send a multistatus element containing a complete error report to the client.

protected void
service(HttpServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
HttpServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
resp
)

Overrides org.apache.catalina.servlets.DefaultServlet.service.

Handles the special WebDAV methods.

Inherited from org.apache.catalina.servlets.DefaultServlet:
checkIfMatchcheckIfModifiedSincecheckIfNoneMatchcheckIfUnmodifiedSincecheckSendfilecopycopycopycopycopyRangecopyRangecopyRangedestroydoGetdoHeaddoPostexecutePartialPutfindXsltSourcegenerateETaggetReadmeparseContentRangeparseRangerenderrenderHtmlrenderSizerenderXmlrewriteUrlsendNotAllowedserveResource