Search in sources :

Example 1 with HttpUnlock

use of org.apache.jackrabbit.webdav.client.methods.HttpUnlock in project nuxeo-filesystem-connectors by nuxeo.

the class WebDavClientTest method testLockUnlock.

protected void testLockUnlock(String accept) throws Exception {
    String fileUri = ROOT_URI + "quality.jpg";
    HttpLock request = new HttpLock(fileUri, new LockInfo(Scope.EXCLUSIVE, Type.WRITE, USERNAME, 10000L, false));
    if (accept != null) {
        request.setHeader("Accept", accept);
    }
    int status;
    String token;
    try (CloseableHttpResponse response = client.execute(request, context)) {
        request.checkSuccess(response);
        status = response.getStatusLine().getStatusCode();
        token = request.getLockToken(response);
    }
    assertEquals(HttpStatus.SC_OK, status);
    assertEquals("urn:uuid:Administrator", token);
    HttpUnlock request2 = new HttpUnlock(fileUri, token);
    if (accept != null) {
        request2.setHeader("Accept", accept);
    }
    try (CloseableHttpResponse response = client.execute(request2, context)) {
        status = response.getStatusLine().getStatusCode();
    }
    assertEquals(HttpStatus.SC_NO_CONTENT, status);
}
Also used : HttpUnlock(org.apache.jackrabbit.webdav.client.methods.HttpUnlock) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) HttpLock(org.apache.jackrabbit.webdav.client.methods.HttpLock)

Example 2 with HttpUnlock

use of org.apache.jackrabbit.webdav.client.methods.HttpUnlock in project jackrabbit by apache.

the class RepositoryServiceImpl method unlock.

@Override
public void unlock(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
    checkSessionInfo(sessionInfo);
    String uri = getItemUri(nodeId, sessionInfo);
    // Note: since sessionInfo does not allow to identify the id of the
    // lock holding node, we need to access the token via lockInfo
    // TODO: review this.
    LockInfoImpl lInfo = (LockInfoImpl) getLockInfo(sessionInfo, nodeId);
    if (lInfo == null) {
        throw new LockException("No Lock present on Node with id " + saveGetIdString(nodeId, sessionInfo));
    }
    String lockToken = lInfo.getActiveLock().getToken();
    boolean isSessionScoped = lInfo.isSessionScoped();
    if (!((SessionInfoImpl) sessionInfo).getAllLockTokens().contains(lockToken)) {
        throw new LockException("Lock " + lockToken + " not owned by this session");
    }
    HttpUnlock unlockRequest = new HttpUnlock(uri, lockToken);
    try {
        execute(unlockRequest, sessionInfo);
        ((SessionInfoImpl) sessionInfo).removeLockToken(lockToken, isSessionScoped);
    } finally {
        unlockRequest.releaseConnection();
    }
}
Also used : LockException(javax.jcr.lock.LockException) HttpUnlock(org.apache.jackrabbit.webdav.client.methods.HttpUnlock)

Aggregations

HttpUnlock (org.apache.jackrabbit.webdav.client.methods.HttpUnlock)2 LockException (javax.jcr.lock.LockException)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpLock (org.apache.jackrabbit.webdav.client.methods.HttpLock)1 LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)1