use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doRebind.
/**
* The REBIND method
*
* @param request
* @param response
* @param resource the collection resource to which a new member will be added
* @throws IOException
* @throws DavException
*/
protected void doRebind(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
if (!resource.exists()) {
response.sendError(DavServletResponse.SC_NOT_FOUND);
}
RebindInfo rebindInfo = request.getRebindInfo();
DavResource oldBinding = getResourceFactory().createResource(request.getHrefLocator(rebindInfo.getHref()), request, response);
if (!(oldBinding instanceof BindableResource)) {
response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
DavResource newBinding = getResourceFactory().createResource(request.getMemberLocator(rebindInfo.getSegment()), request, response);
int status = validateDestination(newBinding, request, false);
if (status > DavServletResponse.SC_NO_CONTENT) {
response.sendError(status);
return;
}
((BindableResource) oldBinding).rebind(resource, newBinding);
response.setStatus(status);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doMkCol.
/**
* The MKCOL method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doMkCol(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
DavResource parentResource = resource.getCollection();
if (parentResource == null || !parentResource.exists() || !parentResource.isCollection()) {
// parent does not exist or is not a collection
response.sendError(DavServletResponse.SC_CONFLICT);
return;
}
// shortcut: mkcol is only allowed on deleted/non-existing resources
if (resource.exists()) {
response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
if (request.getContentLength() > 0 || request.getHeader("Transfer-Encoding") != null) {
parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
} else {
parentResource.addMember(resource, getInputContext(request, null));
}
response.setStatus(DavServletResponse.SC_CREATED);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method service.
/**
* Service the given request.
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
WebdavRequest webdavRequest = new WebdavRequestImpl(request, getLocatorFactory(), isCreateAbsoluteURI());
// 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);
try {
// make sure there is a authenticated user
if (!getDavSessionProvider().attachSession(webdavRequest)) {
return;
}
// perform referrer host checks if CSRF protection is enabled
if (!csrfUtil.isValidRequest(webdavRequest)) {
webdavResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
// check matching if=header for lock-token relevant operations
DavResource resource = getResourceFactory().createResource(webdavRequest.getRequestLocator(), webdavRequest, webdavResponse);
if (!isPreconditionValid(webdavRequest, resource)) {
webdavResponse.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
return;
}
if (!execute(webdavRequest, webdavResponse, methodCode, resource)) {
super.service(request, response);
}
} catch (DavException e) {
if (e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
sendUnauthorized(webdavRequest, webdavResponse, e);
} else {
webdavResponse.sendError(e);
}
} finally {
getDavSessionProvider().releaseSession(webdavRequest);
}
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doMove.
/**
* The MOVE method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doMove(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
DavResource destResource = getResourceFactory().createResource(request.getDestinationLocator(), request, response);
int status = validateDestination(destResource, request, true);
if (status > DavServletResponse.SC_NO_CONTENT) {
response.sendError(status);
return;
}
resource.move(destResource);
response.setStatus(status);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doCopy.
/**
* The COPY method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doCopy(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
// only depth 0 and infinity is allowed
int depth = request.getDepth(DEPTH_INFINITY);
if (!(depth == DEPTH_0 || depth == DEPTH_INFINITY)) {
response.sendError(DavServletResponse.SC_BAD_REQUEST);
return;
}
DavResource destResource = getResourceFactory().createResource(request.getDestinationLocator(), request, response);
int status = validateDestination(destResource, request, true);
if (status > DavServletResponse.SC_NO_CONTENT) {
response.sendError(status);
return;
}
resource.copy(destResource, depth == DEPTH_0);
response.setStatus(status);
}
Aggregations