WebdavRequest webdavRequest = new WebdavRequestImpl( request, getLocatorFactory() );
// DeltaV requires 'Cache-Control' header for all methods except 'VERSION-CONTROL' and 'REPORT'.
int methodCode = DavMethods.getMethodCode( request.getMethod() );
boolean noCache = DavMethods.isDeltaVMethod( webdavRequest ) && !( DavMethods.DAV_VERSION_CONTROL == methodCode
|| DavMethods.DAV_REPORT == methodCode );
WebdavResponse webdavResponse = new WebdavResponseImpl( response, noCache );
DavResource resource = null;
try
{
// make sure there is a authenticated user
if ( !getDavSessionProvider().attachSession( webdavRequest ) )
{
return;
}
// check matching if=header for lock-token relevant operations
resource =
getResourceFactory().createResource( webdavRequest.getRequestLocator(), webdavRequest, webdavResponse );
if ( !isPreconditionValid( webdavRequest, resource ) )
{
webdavResponse.sendError( DavServletResponse.SC_PRECONDITION_FAILED );
return;
}
if ( !execute( webdavRequest, webdavResponse, methodCode, resource ) )
{
super.service( request, response );
}
}
catch ( UnauthorizedDavException e )
{
webdavResponse.setHeader( "WWW-Authenticate", getAuthenticateHeaderValue( e.getRepositoryName() ) );
webdavResponse.sendError( e.getErrorCode(), e.getStatusPhrase() );
}
catch ( BrowserRedirectException e )
{
response.sendRedirect( e.getLocation() );
}
catch ( DavException e )
{
if ( e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED )
{
final String msg = "Should throw " + UnauthorizedDavException.class.getName();
log.error( msg );
webdavResponse.sendError( e.getErrorCode(), msg );
}
else if ( e.getCause() != null )
{
webdavResponse.sendError( e.getErrorCode(), e.getCause().getMessage() );
}
else
{
webdavResponse.sendError( e.getErrorCode(), e.getMessage() );
}
}
finally
{
getDavSessionProvider().releaseSession( webdavRequest );