Exemplo n.º 1
0
  protected void processNewLock(
      HttpManager milton,
      Request request,
      Response response,
      LockableResource r,
      LockTimeout timeout)
      throws NotAuthorizedException {
    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);
    }

    if (handlerHelper.isLockedOut(request, r)) {
      this.responseHandler.respondLocked(request, response, r);
      return;
    }

    log.debug("locking: " + r.getName());
    LockResult result;
    try {
      result = r.lock(timeout, lockInfo);
    } catch (PreConditionFailedException ex) {
      responseHandler.respondPreconditionFailed(request, response, r);
      return;
    } catch (LockedException ex) {
      responseHandler.respondLocked(request, response, r);
      return;
    }

    if (result.isSuccessful()) {
      LockToken tok = result.getLockToken();
      log.debug("..locked ok: " + tok.tokenId);
      response.setLockTokenHeader(
          "<opaquelocktoken:" + tok.tokenId + ">"); // spec says to set response header. See 8.10.1
      respondWithToken(tok, request, response);
    } else {
      respondWithLockFailure(result, request, response);
    }
  }
Exemplo n.º 2
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);
    }
  }