Search in sources :

Example 1 with ContentCodingAwareRequest

use of org.apache.jackrabbit.webdav.ContentCodingAwareRequest in project jackrabbit by apache.

the class AbstractWebdavServlet method addHintAboutPotentialRequestEncodings.

/**
 * If request payload was uncompressed, hint about acceptable content codings (RFC 7694)
 */
private void addHintAboutPotentialRequestEncodings(WebdavRequest webdavRequest, WebdavResponse webdavResponse) {
    if (webdavRequest instanceof ContentCodingAwareRequest) {
        ContentCodingAwareRequest ccr = (ContentCodingAwareRequest) webdavRequest;
        List<String> ces = ccr.getRequestContentCodings();
        if (ces.isEmpty()) {
            webdavResponse.setHeader("Accept-Encoding", ccr.getAcceptableCodings());
        }
    }
}
Also used : ContentCodingAwareRequest(org.apache.jackrabbit.webdav.ContentCodingAwareRequest)

Example 2 with ContentCodingAwareRequest

use of org.apache.jackrabbit.webdav.ContentCodingAwareRequest in project jackrabbit by apache.

the class AbstractWebdavServlet method handleDavException.

private void handleDavException(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavException ex) throws IOException {
    if (ex.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
        sendUnauthorized(webdavRequest, webdavResponse, ex);
    } else {
        Element condition = ex.getErrorCondition();
        if (DomUtil.matches(condition, ContentCodingAwareRequest.PRECONDITION_SUPPORTED)) {
            if (webdavRequest instanceof ContentCodingAwareRequest) {
                webdavResponse.setHeader("Accept-Encoding", ((ContentCodingAwareRequest) webdavRequest).getAcceptableCodings());
            }
        }
        webdavResponse.sendError(ex);
    }
}
Also used : Element(org.w3c.dom.Element) ContentCodingAwareRequest(org.apache.jackrabbit.webdav.ContentCodingAwareRequest)

Example 3 with ContentCodingAwareRequest

use of org.apache.jackrabbit.webdav.ContentCodingAwareRequest 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 {
        WebdavRequestContextHolder.setContext(new WebdavRequestContextImpl(webdavRequest));
        // 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;
        }
        // support it (see JCR-4166)
        if (!(webdavRequest instanceof ContentCodingAwareRequest)) {
            List<String> ces = getContentCodings(request);
            if (!ces.isEmpty()) {
                webdavResponse.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
                webdavResponse.setHeader("Accept-Encoding", "identity");
                webdavResponse.setContentType("text/plain; charset=UTF-8");
                webdavResponse.getWriter().println("Content-Encodings not supported, but received: " + ces);
                webdavResponse.getWriter().flush();
            }
        }
        // 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) {
        handleDavException(webdavRequest, webdavResponse, e);
    } catch (IOException ex) {
        Throwable cause = ex.getCause();
        if (cause instanceof DavException) {
            handleDavException(webdavRequest, webdavResponse, (DavException) cause);
        } else {
            throw ex;
        }
    } finally {
        WebdavRequestContextHolder.clearContext();
        getDavSessionProvider().releaseSession(webdavRequest);
    }
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) WebdavResponseImpl(org.apache.jackrabbit.webdav.WebdavResponseImpl) DavException(org.apache.jackrabbit.webdav.DavException) WebdavRequestImpl(org.apache.jackrabbit.webdav.WebdavRequestImpl) IOException(java.io.IOException) ContentCodingAwareRequest(org.apache.jackrabbit.webdav.ContentCodingAwareRequest) WebdavRequest(org.apache.jackrabbit.webdav.WebdavRequest) WebdavResponse(org.apache.jackrabbit.webdav.WebdavResponse)

Aggregations

ContentCodingAwareRequest (org.apache.jackrabbit.webdav.ContentCodingAwareRequest)3 IOException (java.io.IOException)1 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 Element (org.w3c.dom.Element)1