use of io.milton.http.LockResult in project lobcder by skoulouzis.
the class MemoryLockManagerTest method testLockUnLock.
public void testLockUnLock() throws NotAuthorizedException {
LockTimeout timeout = new LockTimeout(100l);
LockInfo lockInfo = new LockInfo(LockInfo.LockScope.NONE, LockInfo.LockType.READ, "me", LockInfo.LockDepth.ZERO);
SimpleFileContentService contentService = new SimpleFileContentService();
FsResource resource = new FsFileResource(null, null, new File(File.pathSeparator), contentService);
// lock it
LockResult res = lockManager.lock(timeout, lockInfo, resource);
assertNotNull(res);
assertTrue(res.isSuccessful());
// check is locked
LockToken token = lockManager.getCurrentToken(resource);
assertNotNull(token);
assertEquals(token.tokenId, res.getLockToken().tokenId);
// unlock
lockManager.unlock(token.tokenId, resource);
// check removed
token = lockManager.getCurrentToken(resource);
assertNull(token);
}
use of io.milton.http.LockResult in project lobcder by skoulouzis.
the class LockHandler method processNewLock.
private void processNewLock(HttpManager manager, Request request, Response response, LockableResource r, LockTimeout timeout) throws IOException, SAXException, NotAuthorizedException, PreConditionFailedException, LockedException {
LockInfo lockInfo = parseLockInfo(request);
if (handlerHelper.isLockedOut(request, r)) {
this.responseHandler.respondLocked(request, response, r);
return;
}
LockResult result = r.lock(timeout, lockInfo);
if (result.isSuccessful()) {
LockToken tok = result.getLockToken();
// spec says to set response header. See 8.10.1
response.setLockTokenHeader("<opaquelocktoken:" + tok.tokenId + ">");
respondWithToken(tok, request, response);
} else {
response.setStatus(result.getFailureReason().status);
}
}
Aggregations