@Override
 public void sendContent(
     OutputStream out, Range range, Map<String, String> params, String contentType)
     throws IOException, NotAuthorizedException, BadRequestException {
   String uri = HttpManager.request().getAbsolutePath();
   contentGenerator.generateContent(this, out, uri);
 }
示例#2
0
  public void processResource(
      HttpManager manager, Request request, Response response, Resource resource)
      throws NotAuthorizedException, ConflictException, BadRequestException {
    long t = System.currentTimeMillis();
    try {
      if (enableAuthorisation) {
        if (!handlerHelper.checkAuthorisation(manager, resource, request)) {
          responseHandler.respondUnauthorised(resource, response, request);
          return;
        }
      }

      manager.onProcessResourceStart(request, response, resource);

      List<String> methodsAllowed = determineMethodsAllowed(manager, resource);
      responseHandler.respondWithOptions(resource, response, request, methodsAllowed);

    } finally {
      t = System.currentTimeMillis() - t;
      manager.onProcessResourceFinish(request, response, resource, t);
    }
  }
示例#3
0
 private List<String> determineMethodsAllowed(HttpManager manager, Resource res) {
   List<String> list = new ArrayList<String>();
   for (Handler f : manager.getAllHandlers()) {
     if (f.isCompatible(res)) {
       for (String m : f.getMethods()) {
         Method httpMethod = Method.valueOf(m);
         if (!handlerHelper.isNotCompatible(res, httpMethod)) {
           list.add(m);
         }
       }
     }
   }
   return list;
 }
示例#4
0
  @Override
  public Resource getResource(String host, String sPath)
      throws NotAuthorizedException, BadRequestException {
    LogUtils.trace(log, "getResource", host, sPath);
    Path path = Path.path(sPath);
    Path parent = path.getParent();
    Request request = HttpManager.request();
    String encodedPath = request.getAbsolutePath();

    // This is to support a use case where a developer wants their resources to
    // be accessible through milton-json, but don't want to use DAV urls. Instead
    // they use a parameter and DO NOT implement PostableResource.
    if (request.getMethod().equals(Method.POST)) {
      Resource wrappedResource = wrapped.getResource(host, sPath);
      if (wrappedResource != null && !(wrappedResource instanceof PostableResource)) {
        LogUtils.trace(log, "getResource: is post, and got a: ", wrappedResource.getClass());
        return new PostJsonResource(host, encodedPath, wrappedResource, methodParamName, this);
      }
    }
    if (request.getMethod().equals(Method.GET)
        && isMatchingContentType(request.getAcceptHeader())) {
      Resource wrappedResource = wrapped.getResource(host, sPath);
      if (wrappedResource != null) {
        log.trace("getResource: matches content type, and found wrapped resource");
        return wrapResource(host, wrappedResource, Method.PROPFIND.code, encodedPath);
      } else {
        LogUtils.trace(
            log, "getResource: is GET and matched type, but found no actual resource on", sPath);
      }
    }
    if (isMatchingPath(parent)) {
      log.trace("getResource: is matching path");
      Path resourcePath = parent.getParent();
      if (resourcePath != null) {
        String method = path.getName();
        Resource wrappedResource = wrapped.getResource(host, resourcePath.toString());
        if (wrappedResource != null) {
          Resource r = wrapResource(host, wrappedResource, method, encodedPath);
          LogUtils.trace(log, "returning a", r.getClass());
          return r;
        }
      }
    } else {
      log.trace("getResource: not matching path");
      return wrapped.getResource(host, sPath);
    }
    return null;
  }
示例#5
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");
	}