Java Code Examples for org.apache.jackrabbit.webdav.WebdavResponse#sendError()

The following examples show how to use org.apache.jackrabbit.webdav.WebdavResponse#sendError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The PROPPATCH method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 */
@SuppressWarnings("rawtypes")
protected void doPropPatch(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doPropPatch");

	List changeList = request.getPropPatchChangeList();
	if (changeList.isEmpty()) {
		response.sendError(DavServletResponse.SC_BAD_REQUEST);
		return;
	}

	MultiStatus ms = new MultiStatus();
	MultiStatusResponse msr = resource.alterProperties(changeList);
	ms.addResponse(msr);
	response.sendMultiStatus(ms);
}
 
Example 2
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The DELETE method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doDelete(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doDelete");
	try {
		if (log.isDebugEnabled())
			log.debug("[DELETE] {} {}", (resource.isCollection() ? " FOLDER" : " DOCUMENT"),
					resource.getDisplayName());

		DavResource parent = resource.getCollection();
		if (parent != null) {
			parent.removeMember(resource);
			response.setStatus(DavServletResponse.SC_NO_CONTENT);
		} else {
			response.sendError(DavServletResponse.SC_FORBIDDEN, "Cannot remove the root resource.");
		}
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
}
 
Example 3
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The COPY method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doCopy(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doCopy");
	// 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 = null;
	try {
		destResource = getResourceFactory().createResource(request.getDestinationLocator(), request);
	} catch (Throwable e) {
		destResource = resource.getCollection();
	}
	int status = validateDestination(destResource, request);
	if (status > DavServletResponse.SC_NO_CONTENT) {
		response.sendError(status);
		return;
	}

	resource.copy(destResource, depth == DEPTH_0);
	response.setStatus(status);
}
 
Example 4
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The REPORT method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doReport(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doReport");

	ReportInfo info = request.getReportInfo();
	Report report;
	if (resource instanceof DeltaVResource) {
		report = ((DeltaVResource) resource).getReport(info);
	} else if (resource instanceof AclResource) {
		report = ((AclResource) resource).getReport(info);
	} else {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}

	int statusCode = (report.isMultiStatusReport()) ? DavServletResponse.SC_MULTI_STATUS : DavServletResponse.SC_OK;
	response.sendXmlResponse(report, statusCode);
}
 
Example 5
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * @param sendContent
 * 
 * @throws IOException generic I/O error
 */
private void spoolResource(WebdavRequest request, WebdavResponse response, DavResource resource,
		boolean sendContent) throws IOException {

	if (!resource.exists()) {
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return;
	}

	long modSince = request.getDateHeader("If-Modified-Since");
	if (modSince > UNDEFINED_TIME) {
		long modTime = resource.getModificationTime();
		// test if resource has been modified. note that formatted
		// modification
		// time lost the milli-second precision
		if (modTime != UNDEFINED_TIME && (modTime / 1000 * 1000) <= modSince) {
			// resource has not been modified since the time indicated in
			// the
			// 'If-Modified-Since' header.
			response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
			return;
		}
	}

	// spool resource properties and ev. resource content.
	OutputStream out = (sendContent) ? response.getOutputStream() : null;
	resource.spool(getOutputContext(response, out));
}
 
Example 6
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The PUT method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doPut(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("************doPut*****************");
	if (log.isDebugEnabled())
		log.debug("[ADD] Document {}", resource.getDisplayName());

	try {
		DavResource parentResource = resource.getCollection();
		if (parentResource == null || !parentResource.exists()) {
			// parent does not exist
			response.sendError(DavServletResponse.SC_CONFLICT);
			return;
		}

		int status;
		// test if resource already exists
		if (resource.exists()) {
			status = DavServletResponse.SC_NO_CONTENT;
		} else {
			status = DavServletResponse.SC_CREATED;
		}

		parentResource.addMember(resource, getInputContext(request, request.getInputStream()));

		getResourceFactory().putInCache((com.logicaldoc.webdav.session.DavSession) parentResource.getSession(),
				parentResource);

		response.setStatus(status);
	} catch (Exception e) {
	}
}
 
Example 7
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The MKCOL method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doMkCol(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doMkCol");
	if (log.isDebugEnabled())
		log.debug("[ADD] Directory {}", resource.getDisplayName());
	try {
		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);
		}

		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);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 8
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void doVersionControl(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doVersionControl");
	if (!(resource instanceof VersionableResource)) {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}
	((VersionableResource) resource).addVersionControl();
}
 
Example 9
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The EVENT_UNCHECKOUT method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doUncheckout(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doUncheckout(" + resource.getDisplayName() + ")");
	if (!(resource instanceof VersionControlledResource)) {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}
	((VersionControlledResource) resource).uncheckout();
	response.setStatus(DavServletResponse.SC_OK);
}
 
Example 10
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * The PROPFIND method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 */
protected void doPropFind(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doPropFind");
	if (log.isDebugEnabled())
		log.debug("[READ] FINDING {} {}",
				(resource.isCollection() ? "DOCUMENTS WITHIN THE FOLDER" : "JUST THE DOCUMENT"),
				resource.getDisplayName());

	if (!resource.exists()) {
		log.warn("Resource not found: {}", resource.getResourcePath());
		response.sendError(DavServletResponse.SC_NOT_FOUND);
		return;
	}

	DavPropertyNameSet requestProperties = request.getPropFindProperties();

	if (log.isDebugEnabled()) {
		DavPropertyNameIterator iter = requestProperties.iterator();
		StringBuffer sb = new StringBuffer("Requested properties: ");
		while (iter.hasNext()) {
			sb.append(((DavPropertyName) iter.next()).getName());
			sb.append(",");
		}
		log.debug(sb.toString());
	}

	int propfindType = request.getPropFindType();

	int depth = Context.get().getProperties().getInt("webdav.depth", 1);
	String headerDepth = request.getHeader("Depth");
	if (StringUtils.isNotEmpty(headerDepth)) {
		if ("infinity".equals(headerDepth))
			depth = request.getDepth(DEPTH_INFINITY);
		else {
			depth = Integer.parseInt(headerDepth);
		}
	}

	MultiStatus mstatus = new MultiStatus();
	mstatus.addResourceProperties(resource, requestProperties, propfindType, depth);

	response.sendMultiStatus(mstatus);
}
 
Example 11
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * The EVENT_CHECKEDOUT method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws DavException
 * @throws IOException
 */
protected void doCheckout(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doCheckout");
	if (!(resource instanceof VersionControlledResource)) {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}
	((VersionControlledResource) resource).checkout();
}
 
Example 12
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * The EVENT_CHECKEDIN method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doCheckin(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doCheckin");

	response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
}