Search in sources :

Example 11 with DavResource

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);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) BindableResource(org.apache.jackrabbit.webdav.bind.BindableResource) RebindInfo(org.apache.jackrabbit.webdav.bind.RebindInfo)

Example 12 with DavResource

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);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Example 13 with DavResource

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);
    }
}
Also used : WebdavRequest(org.apache.jackrabbit.webdav.WebdavRequest) DavResource(org.apache.jackrabbit.webdav.DavResource) WebdavResponseImpl(org.apache.jackrabbit.webdav.WebdavResponseImpl) DavException(org.apache.jackrabbit.webdav.DavException) WebdavRequestImpl(org.apache.jackrabbit.webdav.WebdavRequestImpl) WebdavResponse(org.apache.jackrabbit.webdav.WebdavResponse)

Example 14 with DavResource

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);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Example 15 with DavResource

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);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Aggregations

DavResource (org.apache.jackrabbit.webdav.DavResource)40 DavException (org.apache.jackrabbit.webdav.DavException)21 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)19 RepositoryException (javax.jcr.RepositoryException)16 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 Node (javax.jcr.Node)6 VersionHistory (javax.jcr.version.VersionHistory)6 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)5 Version (javax.jcr.version.Version)4 DavResourceIterator (org.apache.jackrabbit.webdav.DavResourceIterator)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Item (javax.jcr.Item)3 NodeIterator (javax.jcr.NodeIterator)3 Repository (javax.jcr.Repository)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 Session (javax.jcr.Session)2 VersionIterator (javax.jcr.version.VersionIterator)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2