Class WebdavServlet
- java.lang.Object
-
- jakarta.servlet.GenericServlet
-
- jakarta.servlet.http.HttpServlet
-
- org.apache.catalina.servlets.DefaultServlet
-
- org.apache.catalina.servlets.WebdavServlet
-
- All Implemented Interfaces:
Servlet
,ServletConfig
,java.io.Serializable
,PeriodicEventListener
public class WebdavServlet extends DefaultServlet implements PeriodicEventListener
Servlet which adds support for WebDAV level 3. 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. TheWEB-INF
andMETA-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/contentThe Servlet provides support for arbitrary dead properties on all resources (dead properties are properties whose values are not protected by the server, such as the content length of a resource). By default the Servlet will use non persistent memory storage for them. Persistence can be achieved by implementing the
PropertyStore
interface and configuring the Servlet to use that store. ThepropertyStore
init-param allows configuring the classname of the store to use, while the parameters in the form ofstore.xxx
will be set on the store object as bean properties. For example, this would configure a store with classcom.MyPropertyStore
, and set its fieldmyName
to valuemyValue
:<init-param> <param-name>propertyStore</param-name> <param-value>com.MyPropertyStore</param-value> </init-param> <init-param> <param-name>store.myName</param-name> <param-value>myValue</param-value> </init-param>
- See Also:
- RFC 4918, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
WebdavServlet.PropertyStore
Handling of dead properties on resources.static class
WebdavServlet.ProppatchOperation
Represents a PROPPATCH sub operation to be performed.-
Nested classes/interfaces inherited from class org.apache.catalina.servlets.DefaultServlet
DefaultServlet.CompressionFormat
-
-
Field Summary
Fields Modifier and Type Field Description protected static ConcurrentDateFormat
creationDateFormat
Simple date format for the creation date ISO representation (partial).protected static java.lang.String
DEFAULT_NAMESPACE
Default namespace.protected static java.lang.String
LOCK_SCHEME
Lock scheme used.protected static java.lang.String
SUPPORTED_LOCKS
Pre generated raw XML for supported locks.-
Fields inherited from class org.apache.catalina.servlets.DefaultServlet
BUFFER_SIZE, compressionFormats, contextXsltFile, debug, fileEncoding, FULL, globalXsltFile, input, listings, localXsltFile, mimeSeparation, output, readmeFile, readOnly, resources, sendfileSize, showServerInfo, sm, sortListings, sortManager, useAcceptRanges
-
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD
-
-
Constructor Summary
Constructors Constructor Description WebdavServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
checkIfHeaders(HttpServletRequest request, HttpServletResponse response, WebResource resource)
Check if the conditions specified in the optional If headers are satisfied.void
destroy()
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.protected java.lang.String
determineMethodsAllowed(HttpServletRequest req)
Determines the methods normally allowed for the resource.protected void
doCopy(HttpServletRequest req, HttpServletResponse resp)
COPY Method.protected void
doDelete(HttpServletRequest req, HttpServletResponse resp)
Called by the server (via theservice
method) to allow a servlet to handle a DELETE request.protected void
doLock(HttpServletRequest req, HttpServletResponse resp)
LOCK Method.protected void
doMkcol(HttpServletRequest req, HttpServletResponse resp)
MKCOL Method.protected void
doMove(HttpServletRequest req, HttpServletResponse resp)
MOVE Method.protected void
doOptions(HttpServletRequest req, HttpServletResponse resp)
Override default implementation to ensure that TRACE is correctly handled.protected void
doPropfind(HttpServletRequest req, HttpServletResponse resp)
PROPFIND Method.protected void
doProppatch(HttpServletRequest req, HttpServletResponse resp)
PROPPATCH Method.protected void
doPut(HttpServletRequest req, HttpServletResponse resp)
Called by the server (via theservice
method) to allow a servlet to handle a PUT request.protected void
doUnlock(HttpServletRequest req, HttpServletResponse resp)
UNLOCK Method.protected javax.xml.parsers.DocumentBuilder
getDocumentBuilder()
Return JAXP document builder instance.protected java.lang.String
getPathPrefix(HttpServletRequest request)
Determines the appropriate path to prepend resources with when generating directory listings.protected java.lang.String
getRelativePath(HttpServletRequest request, boolean allowEmptyPath)
Override the DefaultServlet implementation and only use the PathInfo.void
init()
A convenience method which can be overridden so that there's no need to callsuper.init(config)
.void
periodicEvent()
Execute a periodic task, such as reloading, etc.protected void
service(HttpServletRequest req, HttpServletResponse resp)
Receives standard HTTP requests from the publicservice
method and dispatches them to thedo
Method methods defined in this class.-
Methods inherited from class org.apache.catalina.servlets.DefaultServlet
checkIfMatch, checkIfModifiedSince, checkIfNoneMatch, checkIfUnmodifiedSince, checkSendfile, copy, copy, copy, copy, copyRange, copyRange, copyRange, doGet, doHead, doPost, executePartialPut, findXsltSource, generateETag, getReadme, getRelativePath, parseContentRange, parseRange, render, renderHtml, renderSize, renderTimestamp, renderXml, rewriteUrl, sendNotAllowed, serveResource
-
Methods inherited from class jakarta.servlet.http.HttpServlet
doTrace, getLastModified, init, service
-
Methods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, log, log
-
-
-
-
Field Detail
-
DEFAULT_NAMESPACE
protected static final java.lang.String DEFAULT_NAMESPACE
Default namespace.- See Also:
- Constant Field Values
-
SUPPORTED_LOCKS
protected static final java.lang.String SUPPORTED_LOCKS
Pre generated raw XML for supported locks.- See Also:
- Constant Field Values
-
creationDateFormat
protected static final ConcurrentDateFormat creationDateFormat
Simple date format for the creation date ISO representation (partial).
-
LOCK_SCHEME
protected static final java.lang.String LOCK_SCHEME
Lock scheme used.- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init() throws ServletException
Description copied from class:jakarta.servlet.GenericServlet
A convenience method which can be overridden so that there's no need to callsuper.init(config)
.Instead of overriding
GenericServlet.init(ServletConfig)
, simply override this method and it will be called byGenericServlet.init(ServletConfig config)
. TheServletConfig
object can still be retrieved viaGenericServlet.getServletConfig()
.- Overrides:
init
in classDefaultServlet
- Throws:
ServletException
- if an exception occurs that interrupts the servlet's normal operation
-
destroy
public void destroy()
Description copied from class:jakarta.servlet.GenericServlet
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. SeeServlet.destroy()
.- Specified by:
destroy
in interfaceServlet
- Overrides:
destroy
in classDefaultServlet
-
periodicEvent
public void periodicEvent()
Description copied from interface:PeriodicEventListener
Execute a periodic task, such as reloading, etc.- Specified by:
periodicEvent
in interfacePeriodicEventListener
-
getDocumentBuilder
protected javax.xml.parsers.DocumentBuilder getDocumentBuilder() throws ServletException
Return JAXP document builder instance.- Returns:
- the document builder
- Throws:
ServletException
- document builder creation failed (wrappedParserConfigurationException
exception)
-
service
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
Description copied from class:jakarta.servlet.http.HttpServlet
Receives standard HTTP requests from the publicservice
method and dispatches them to thedo
Method methods defined in this class. This method is an HTTP-specific version of theServlet.service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
method. There's no need to override this method.- Overrides:
service
in classDefaultServlet
- Parameters:
req
- theHttpServletRequest
object that contains the request the client made of the servletresp
- theHttpServletResponse
object that contains the response the servlet returns to the client- Throws:
ServletException
- if the HTTP request cannot be handledjava.io.IOException
- if an input or output error occurs while the servlet is handling the HTTP request- See Also:
Servlet.service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
-
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 classDefaultServlet
- Parameters:
request
- The servlet request we are processingresponse
- The servlet response we are creatingresource
- The resource- Returns:
true
if the resource meets all the specified conditions, andfalse
if any of the conditions is not satisfied, in which case request processing is stopped- Throws:
java.io.IOException
- an IO error occurred
-
getRelativePath
protected java.lang.String getRelativePath(HttpServletRequest request, boolean allowEmptyPath)
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 classDefaultServlet
- Parameters:
request
- The servlet request we are processingallowEmptyPath
- Used only to identify a call from DefaultServlet, to avoid removing the trailing slash- Returns:
- the relative path
-
getPathPrefix
protected java.lang.String getPathPrefix(HttpServletRequest request)
Description copied from class:DefaultServlet
Determines the appropriate path to prepend resources with when generating directory listings. Depending on the behaviour ofDefaultServlet.getRelativePath(HttpServletRequest)
this will change.- Overrides:
getPathPrefix
in classDefaultServlet
- Parameters:
request
- the request to determine the path for- Returns:
- the prefix to apply to all resources in the listing.
-
determineMethodsAllowed
protected java.lang.String determineMethodsAllowed(HttpServletRequest req)
Description copied from class:DefaultServlet
Determines the methods normally allowed for the resource.- Overrides:
determineMethodsAllowed
in classDefaultServlet
- Parameters:
req
- The Servlet request- Returns:
- The allowed HTTP methods
-
doOptions
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
Description copied from class:DefaultServlet
Override default implementation to ensure that TRACE is correctly handled.- Overrides:
doOptions
in classDefaultServlet
- Parameters:
req
- theHttpServletRequest
object that contains the request the client made of the servletresp
- theHttpServletResponse
object that contains the response the servlet returns to the client- Throws:
ServletException
- if the request for the OPTIONS cannot be handledjava.io.IOException
- if an input or output error occurs while the servlet is handling the OPTIONS request
-
doPropfind
protected void doPropfind(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
PROPFIND Method.- Parameters:
req
- The Servlet requestresp
- The Servlet response- Throws:
ServletException
- If an error occursjava.io.IOException
- If an IO error occurs
-
doProppatch
protected void doProppatch(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
PROPPATCH Method. Dead properties support is a SHOULD in the specification and are not implemented.- Parameters:
req
- The Servlet requestresp
- The Servlet response- Throws:
ServletException
- If an error occursjava.io.IOException
- If an IO error occurs
-
doMkcol
protected void doMkcol(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
MKCOL Method.- Parameters:
req
- The Servlet requestresp
- The Servlet response- Throws:
ServletException
- If an error occursjava.io.IOException
- If an IO error occurs
-
doDelete
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
Description copied from class:jakarta.servlet.http.HttpServlet
Called by the server (via theservice
method) to allow a servlet to handle a DELETE request. The DELETE operation allows a client to remove a document or Web page from the server.This method does not need to be either safe or idempotent. Operations requested through DELETE can have side effects for which users can be held accountable. When using this method, it may be useful to save a copy of the affected URL in temporary storage.
If the HTTP DELETE request is incorrectly formatted,
doDelete
returns an HTTP "Bad Request" message.- Overrides:
doDelete
in classDefaultServlet
- Parameters:
req
- theHttpServletRequest
object that contains the request the client made of the servletresp
- theHttpServletResponse
object that contains the response the servlet returns to the client- Throws:
ServletException
- if the request for the DELETE cannot be handledjava.io.IOException
- if an input or output error occurs while the servlet is handling the DELETE request
-
doPut
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
Description copied from class:jakarta.servlet.http.HttpServlet
Called by the server (via theservice
method) to allow a servlet to handle a PUT request. The PUT operation allows a client to place a file on the server and is similar to sending a file by FTP.When overriding this method, leave intact any content headers sent with the request (including Content-Length, Content-Type, Content-Transfer-Encoding, Content-Encoding, Content-Base, Content-Language, Content-Location, Content-MD5, and Content-Range). If your method cannot handle a content header, it must issue an error message (HTTP 501 - Not Implemented) and discard the request. For more information on HTTP 1.1, see RFC 2616 .
This method does not need to be either safe or idempotent. Operations that
doPut
performs can have side effects for which the user can be held accountable. When using this method, it may be useful to save a copy of the affected URL in temporary storage.If the HTTP PUT request is incorrectly formatted,
doPut
returns an HTTP "Bad Request" message.- Overrides:
doPut
in classDefaultServlet
- Parameters:
req
- theHttpServletRequest
object that contains the request the client made of the servletresp
- theHttpServletResponse
object that contains the response the servlet returns to the client- Throws:
ServletException
- if the request for the PUT cannot be handledjava.io.IOException
- if an input or output error occurs while the servlet is handling the PUT request
-
doCopy
protected void doCopy(HttpServletRequest req, HttpServletResponse resp) throws java.io.IOException
COPY Method.- Parameters:
req
- The Servlet requestresp
- 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 requestresp
- The Servlet response- Throws:
java.io.IOException
- If an IO error occurs
-
doLock
protected void doLock(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException
LOCK Method.- Parameters:
req
- The Servlet requestresp
- The Servlet response- Throws:
ServletException
- If an error occursjava.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 requestresp
- The Servlet response- Throws:
java.io.IOException
- If an IO error occurs
-
-