Search in sources :

Example 1 with WebdavResponseImpl

use of org.apache.jackrabbit.webdav.WebdavResponseImpl 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)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)1 DavResource (org.apache.jackrabbit.webdav.DavResource)1 WebdavRequest (org.apache.jackrabbit.webdav.WebdavRequest)1 WebdavRequestImpl (org.apache.jackrabbit.webdav.WebdavRequestImpl)1 WebdavResponse (org.apache.jackrabbit.webdav.WebdavResponse)1 WebdavResponseImpl (org.apache.jackrabbit.webdav.WebdavResponseImpl)1