示例#1
0
  public void processExistingResource(
      HttpManager manager, Request request, Response response, Resource resource)
      throws NotAuthorizedException, BadRequestException, ConflictException {
    LockableResource r = (LockableResource) resource;
    String sToken = request.getLockTokenHeader();
    sToken = LockHandler.parseToken(sToken);

    // this should be checked in processResource now

    //       	if( r.getCurrentLock() != null &&
    //       			!sToken.equals( r.getCurrentLock().tokenId) &&
    //       			isLockedOut( request, resource ))
    //    	{
    //       		//Should this be unlocked easily? With other tokens?
    //    		response.setStatus(Status.SC_LOCKED);
    //    	    log.info("cant unlock with token: " + sToken);
    //    		return;
    //    	}

    log.debug("unlocking token: " + sToken);
    try {
      r.unlock(sToken);
      responseHandler.respondNoContent(resource, response, request);
    } catch (PreConditionFailedException ex) {
      responseHandler.respondPreconditionFailed(request, response, resource);
    }
  }
示例#2
0
	@Override
	public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
		MoveableResource r = (MoveableResource) resource;
		String xpUserAgent = "Microsoft Data Access Internet Publishing Provider DAV 1.1";
		// TODO: investigating some weird character encoding issues for non english character sets on XP

		Dest dest = Utils.getDecodedDestination(request.getDestinationHeader());
		Resource rDest = manager.getResourceFactory().getResource(dest.host, dest.url);
		log.debug("process: moving from: " + r.getName() + " -> " + dest.url + " with name: " + dest.name);
		if (rDest == null) {
			log.debug("process: destination parent does not exist: " + dest);
			responseHandler.respondConflict(resource, response, request, "Destination parent does not exist: " + dest);
		} else if (!(rDest instanceof CollectionResource)) {
			log.debug("process: destination exists but is not a collection");
			responseHandler.respondConflict(resource, response, request, "Destination exists but is not a collection: " + dest);
		} else {
			boolean wasDeleted = false;
			CollectionResource colDest = (CollectionResource) rDest;
			// check if the dest exists
			Resource rExisting = colDest.child(dest.name);
			if (rExisting != null) {
				// check for overwrite header
				if (!canOverwrite(request)) {
					log.info("destination resource exists, and overwrite header is not set");
					responseHandler.respondPreconditionFailed(request, response, rExisting);
					return;
				} else {
					if (deleteExistingBeforeMove) {
						if (rExisting instanceof DeletableResource) {
							log.debug("deleting existing resource");
							DeletableResource drExisting = (DeletableResource) rExisting;
							if (deleteHelper.isLockedOut(request, drExisting)) {
								log.debug("destination resource exists but is locked");
								responseHandler.respondLocked(request, response, drExisting);
								return;
							}
							log.debug("deleting pre-existing destination resource");
							deleteHelper.delete(drExisting, manager.getEventManager());
							wasDeleted = true;
						} else {
							log.warn("destination exists, and overwrite header is set, but destination is not a DeletableResource");
							responseHandler.respondConflict(resource, response, request, "A resource exists at the destination, and it cannot be deleted");
							return;
						}
					}
				}
			}
			log.debug("process: moving resource to: " + rDest.getName());
			try {
				manager.getEventManager().fireEvent(new MoveEvent(resource, colDest, dest.name));
				r.moveTo(colDest, dest.name);
				// See http://www.ettrema.com:8080/browse/MIL-87
				if (wasDeleted) {
					responseHandler.respondNoContent(resource, response, request);
				} else {
					responseHandler.respondCreated(resource, response, request);
				}
			} catch (ConflictException ex) {
				log.warn("conflict", ex);
				responseHandler.respondConflict(resource, response, request, dest.toString());
			}
		}
		log.debug("process: finished");
	}