use of org.apache.jackrabbit.webdav.WebdavResponse in project archiva by apache.
the class RepositoryServlet method service.
/**
* Service the given request. This method has been overridden and copy/pasted to allow better exception handling and
* to support different realms
*
* @param request
* @param response
* @throws ServletException
* @throws java.io.IOException
*/
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
WebdavRequest webdavRequest = new WebdavRequestImpl(request, getLocatorFactory());
// 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);
DavResource resource = null;
try {
// make sure there is a authenticated user
if (!getDavSessionProvider().attachSession(webdavRequest)) {
return;
}
// check matching if=header for lock-token relevant operations
resource = getResourceFactory().createResource(webdavRequest.getRequestLocator(), webdavRequest, webdavResponse);
if (!isPreconditionValid(webdavRequest, resource)) {
webdavResponse.sendError(DavServletResponse.SC_PRECONDITION_FAILED);
return;
}
if (!execute(webdavRequest, webdavResponse, methodCode, resource)) {
super.service(request, response);
}
} catch (UnauthorizedDavException e) {
webdavResponse.setHeader("WWW-Authenticate", getAuthenticateHeaderValue(e.getRepositoryName()));
webdavResponse.sendError(e.getErrorCode(), e.getStatusPhrase());
} catch (BrowserRedirectException e) {
response.sendRedirect(e.getLocation());
} catch (DavException e) {
if (e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
final String msg = "Should throw " + UnauthorizedDavException.class.getName();
log.error(msg);
webdavResponse.sendError(e.getErrorCode(), msg);
} else if (e.getCause() != null) {
webdavResponse.sendError(e.getErrorCode(), e.getCause().getMessage());
} else {
webdavResponse.sendError(e.getErrorCode(), e.getMessage());
}
} finally {
getDavSessionProvider().releaseSession(webdavRequest);
}
}
use of org.apache.jackrabbit.webdav.WebdavResponse 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