smbdav
Class AbstractHandler

java.lang.Object
  extended bysmbdav.AbstractHandler
All Implemented Interfaces:
MethodHandler
Direct Known Subclasses:
DefaultCopyHandler, DefaultDeleteHandler, DefaultGetHandler, DefaultHeadHandler, DefaultLockHandler, DefaultMkcolHandler, DefaultMoveHandler, DefaultOptionsHandler, DefaultPostHandler, DefaultPropfindHandler, DefaultProppatchHandler, DefaultPutHandler, DefaultUnlockHandler, NotAllowedHandler

public abstract class AbstractHandler
extends java.lang.Object
implements MethodHandler

An abstract implementation of the MethodHandler interface. This class serves as a convenient basis for building method handlers. In addition to providing basic init and destroy methods, several useful utility methods are supplied.

Author:
Eric Glass

Field Summary
 
Fields inherited from interface smbdav.MethodHandler
SC_FAILED_DEPENDENCY, SC_INSUFFICIENT_STORAGE, SC_LOCKED, SC_MULTISTATUS, SC_PROCESSING, SC_UNPROCESSABLE_ENTITY
 
Constructor Summary
AbstractHandler()
           
 
Method Summary
protected  int checkConditionalRequest(javax.servlet.http.HttpServletRequest request, jcifs.smb.SmbFile file)
          Checks if a conditional request should apply.
protected  int checkLockOwnership(javax.servlet.http.HttpServletRequest request, jcifs.smb.SmbFile file)
          Checks lock ownership.
protected  jcifs.smb.SmbFile createSmbFile(java.lang.String smbUrl, jcifs.smb.NtlmPasswordAuthentication authentication)
          Convenience method to create an SmbFile object from a specified SMB URL and authentication information.
 void destroy()
          Called by the Davenport servlet to indicate that the handler is being taken out of service.
protected  jcifs.smb.SmbFileFilter getFilter()
          Returns the SmbFileFilter used to filter resource requests.
protected  LockManager getLockManager()
          Returns the LockManager used to maintain WebDAV locks.
protected  java.security.Principal getPrincipal(javax.servlet.http.HttpServletRequest request)
          Obtains the requesting principal.
protected  java.lang.String getRequestURICharset()
          Returns the charset used to interpret request URIs.
protected  java.lang.String getRequestURL(javax.servlet.http.HttpServletRequest request)
          Convenience method to return the HTTP URL from the request, rewritten against the active context base as necessary.
protected  javax.servlet.ServletConfig getServletConfig()
          Returns the ServletConfig object that was provided to the init method.
protected  jcifs.smb.SmbFile getSmbFile(javax.servlet.http.HttpServletRequest request, jcifs.smb.NtlmPasswordAuthentication auth)
          Convenience method to retrieve the SmbFile that is the target of the given request.
protected  java.lang.String getSmbURL(javax.servlet.http.HttpServletRequest request, java.lang.String httpUrl)
          Convenience method to convert a given HTTP URL to the corresponding SMB URL.
protected  java.lang.String getSmbURL(javax.servlet.http.HttpServletRequest request, java.lang.String httpUrl, java.lang.String charset)
          Convenience method to convert a given HTTP URL to the corresponding SMB URL.
 void init(javax.servlet.ServletConfig config)
          Initializes the method handler.
protected  java.lang.String rewriteURL(javax.servlet.http.HttpServletRequest request, java.lang.String url)
          Rewrites the supplied HTTP URL against the active context base if necessary.
abstract  void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, jcifs.smb.NtlmPasswordAuthentication auth)
          Called by the Davenport servlet to allow the handler to service a request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHandler

public AbstractHandler()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Initializes the method handler. This implementation stores the provided ServletConfig object and makes it available via the getServletConfig method. Subclasses overriding this method should start by invoking

super.init(config);

Specified by:
init in interface MethodHandler
Parameters:
config - a ServletConfig object containing the servlet's configuration and initialization parameters.
Throws:
javax.servlet.ServletException - If an error occurs during initialization.

destroy

public void destroy()
Description copied from interface: MethodHandler
Called by the Davenport servlet to indicate that the handler is being taken out of service. Semantics are identical to the Servlet destroy method. This method gives the handler an opportunity to clean up any resources that are being held. After this method has been called, the service method will not be invoked again.

Specified by:
destroy in interface MethodHandler

getServletConfig

protected javax.servlet.ServletConfig getServletConfig()
Returns the ServletConfig object that was provided to the init method.

Returns:
A ServletConfig object containing the servlet's configuration and initialization parameters.

getRequestURICharset

protected java.lang.String getRequestURICharset()
Returns the charset used to interpret request URIs. Davenport will attempt to use this charset before resorting to UTF-8.

Returns:
A String containing the charset name.

rewriteURL

protected java.lang.String rewriteURL(javax.servlet.http.HttpServletRequest request,
                                      java.lang.String url)
Rewrites the supplied HTTP URL against the active context base if necessary.

Parameters:
request - The request being serviced.
url - The HTTP URL to process for rewriting.
Returns:
A String containing the rewritten URL. If no rewriting is required, the provided URL will be returned.

getRequestURL

protected java.lang.String getRequestURL(javax.servlet.http.HttpServletRequest request)
Convenience method to return the HTTP URL from the request, rewritten against the active context base as necessary.

Parameters:
request - The request being serviced.
Returns:
A String containing the rewritten request URL.

getSmbURL

protected java.lang.String getSmbURL(javax.servlet.http.HttpServletRequest request,
                                     java.lang.String httpUrl)
                              throws java.io.IOException
Convenience method to convert a given HTTP URL to the corresponding SMB URL. The provided request is used to determine the servlet base; this is stripped from the given HTTP URL to get the SMB path. Escaped characters within the specified HTTP URL are interpreted as members of the character set returned by getRequestURICharset(). Note: Currently, the jCIFS library does not handle escaped characters in SMB URLs (i.e., "smb://server/share/my%20file.txt". The SMB URLs returned by this method are unescaped for compatibility with jCIFS (i.e., "smb://server/share/my file.txt". This may result in URLs which do not conform with RFC 2396. Such URLs may not be accepted by systems expecting compliant URLs (such as Java 1.4's java.net.URI class).

Parameters:
request - The servlet request upon which the HTTP URL is based.
httpUrl - An HTTP URL from which the SMB URL is derived.
Throws:
java.io.IOException - If an SMB URL cannot be constructed from the given request and HTTP URL.

getSmbURL

protected java.lang.String getSmbURL(javax.servlet.http.HttpServletRequest request,
                                     java.lang.String httpUrl,
                                     java.lang.String charset)
                              throws java.io.IOException
Convenience method to convert a given HTTP URL to the corresponding SMB URL. The provided request is used to determine the servlet base; this is stripped from the given HTTP URL to get the SMB path. Escaped characters within the specified HTTP URL are interpreted as members of the given character set. Note: Currently, the jCIFS library does not handle escaped characters in SMB URLs (i.e., "smb://server/share/my%20file.txt". The SMB URLs returned by this method are unescaped for compatibility with jCIFS (i.e., "smb://server/share/my file.txt". This may result in URLs which do not conform with RFC 2396. Such URLs may not be accepted by systems expecting compliant URLs (such as Java 1.4's java.net.URI class).

Parameters:
request - The servlet request upon which the HTTP URL is based.
httpUrl - An HTTP URL from which the SMB URL is derived.
charset - The character set that should be used to interpret the HTTP URL.
Throws:
java.io.IOException - If an SMB URL cannot be constructed from the given request and HTTP URL.

getLockManager

protected LockManager getLockManager()
Returns the LockManager used to maintain WebDAV locks.

Returns:
The currently installed lock manager. Returns null if no lock manager is present.

getFilter

protected jcifs.smb.SmbFileFilter getFilter()
Returns the SmbFileFilter used to filter resource requests. The default implementation uses the global filter installed by the Davenport servlet (if applicable).

Returns:
The filter to be applied to requested resources. Returns null if no filter is to be applied.

getSmbFile

protected jcifs.smb.SmbFile getSmbFile(javax.servlet.http.HttpServletRequest request,
                                       jcifs.smb.NtlmPasswordAuthentication auth)
                                throws java.io.IOException
Convenience method to retrieve the SmbFile that is the target of the given request. This will attempt to obtain the file by interpreting the URL with the character set given by getRequestURICharset(); if this file does not exist, a second attempt will be made using the UTF-8 charset. If neither file exists, the result of the first attempt will be returned.

Parameters:
request - The request that is being serviced.
auth - The user's authentication information.
Throws:
java.io.IOException - If the SmbFile targeted by the specified request could not be created.

createSmbFile

protected jcifs.smb.SmbFile createSmbFile(java.lang.String smbUrl,
                                          jcifs.smb.NtlmPasswordAuthentication authentication)
                                   throws java.io.IOException
Convenience method to create an SmbFile object from a specified SMB URL and authentication information. The SmbFile returned will automatically be adjusted to include a trailing slash ("/") in the event that it refers to a directory, share, server, or workgroup.

Parameters:
smbUrl - The SMB URL from which the SmbFile object will be created.
authentication - The authentication information to apply to the SmbFile object.
Throws:
java.io.IOException - If an SmbFile object could not be created from the provided information.

checkConditionalRequest

protected int checkConditionalRequest(javax.servlet.http.HttpServletRequest request,
                                      jcifs.smb.SmbFile file)
                               throws java.io.IOException
Checks if a conditional request should apply. If the client specifies one or more conditional cache headers ("If-Match", "If-None-Match", "If-Modified-Since", or "If-Unmodified-Since" -- "If-Range" is not currently supported), this method will indicate whether the request should be processed. If locking is supported, this method will additionally check the "If" header to determine whether the request should apply based on the status of the relevant locks.

Parameters:
request - The servlet request whose conditional cache headers will be examined.
file - The resource that is being examined.
Returns:
An HTTP status code indicating the result. This will be one of:
  • 200 (HttpServletResponse.SC_OK) -- if the request should be serviced normally
  • 304 (HttpServletResponse.SC_NOT_MODIFIED) -- if the resource has not been modified
  • 400 (HttpServletResponse.SC_BAD_REQUEST) -- if the client has submitted a malformed conditional header
  • 412 (HttpServletResponse.SC_PRECONDITION_FAILED) -- if no matching entity was found, or the request should not proceed based on the current lock status
Throws:
jcifs.smb.SmbException - If an error occurs while examining the resource.
java.io.IOException

getPrincipal

protected java.security.Principal getPrincipal(javax.servlet.http.HttpServletRequest request)
                                        throws java.io.IOException
Obtains the requesting principal.

Parameters:
request - The request being serviced.
Returns:
A Principal object containing the authenticated requesting principal.
Throws:
java.io.IOException

checkLockOwnership

protected int checkLockOwnership(javax.servlet.http.HttpServletRequest request,
                                 jcifs.smb.SmbFile file)
                          throws java.io.IOException
Checks lock ownership. This ensures that either no lock is outstanding on the requested resource, or at least one of the outstanding locks on the resource is held by the requesting principal

Parameters:
request - The request being serviced.
file - The requested resource.
Returns:
An int containing the return HTTP status code.
Throws:
java.io.IOException - If an IO error occurs.

service

public abstract void service(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             jcifs.smb.NtlmPasswordAuthentication auth)
                      throws java.io.IOException,
                             javax.servlet.ServletException
Description copied from interface: MethodHandler
Called by the Davenport servlet to allow the handler to service a request. The Davenport servlet will select an appropriate handler for a given HTTP method, and dispatch the request accordingly.

Specified by:
service in interface MethodHandler
Parameters:
request - The request that is being serviced.
response - The servlet response object.
auth - The authentication information provided by the user.
Throws:
javax.servlet.ServletException - If an exception occurs that interferes with normal operation.
java.io.IOException - If an input or output exception occurs.


Copyright © 2004 Eric Glass