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());
}
}
}
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);
}
}
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);
}
}
Aggregations