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);
}
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();
}
}
Aggregations