Esempio n. 1
0
  private void processCreateAndLock(
      HttpManager manager, Request request, Response response, Resource parentResource, String name)
      throws NotAuthorizedException {
    if (parentResource instanceof LockingCollectionResource) {
      log.debug("parent supports lock-null. doing createAndLock");
      LockingCollectionResource lockingParent = (LockingCollectionResource) parentResource;
      LockTimeout timeout = LockTimeout.parseTimeout(request);
      response.setContentTypeHeader(Response.XML);

      LockInfo lockInfo;
      try {
        lockInfo = LockInfoSaxHandler.parseLockInfo(request);
      } catch (SAXException ex) {
        throw new RuntimeException("Exception reading request body", ex);
      } catch (IOException ex) {
        throw new RuntimeException("Exception reading request body", ex);
      }

      // TODO: this should be refactored to return a LockResult as for existing entities

      log.debug("Creating lock on unmapped resource: " + name);
      LockToken tok = lockingParent.createAndLock(name, timeout, lockInfo);
      if (tok == null) {
        throw new RuntimeException(
            "createAndLock returned null, from resource of type: "
                + lockingParent.getClass().getCanonicalName());
      }
      response.setStatus(Status.SC_CREATED);
      response.setLockTokenHeader(
          "<opaquelocktoken:" + tok.tokenId + ">"); // spec says to set response header. See 8.10.1
      respondWithToken(tok, request, response);

    } else {
      log.debug("parent does not support lock-null, respondong method not allowed");
      responseHandler.respondMethodNotImplemented(parentResource, response, request);
    }
  }
Esempio n. 2
0
  protected void processExistingResource(
      HttpManager manager, Request request, Response response, Resource resource)
      throws NotAuthorizedException {
    if (handlerHelper.isNotCompatible(resource, request.getMethod()) || !isCompatible(resource)) {
      responseHandler.respondMethodNotImplemented(resource, response, request);
      return;
    }
    if (!handlerHelper.checkAuthorisation(manager, resource, request)) {
      responseHandler.respondUnauthorised(resource, response, request);
      return;
    }

    handlerHelper.checkExpects(responseHandler, request, response);

    LockableResource r = (LockableResource) resource;
    LockTimeout timeout = LockTimeout.parseTimeout(request);
    String ifHeader = request.getIfHeader();
    response.setContentTypeHeader(Response.XML);
    if (ifHeader == null || ifHeader.length() == 0) {
      processNewLock(manager, request, response, r, timeout);
    } else {
      processRefresh(manager, request, response, r, timeout, ifHeader);
    }
  }