use of io.milton.http.LockTimeout in project lobcder by skoulouzis.
the class WebDataResource method getCurrentLock.
@Override
public LockToken getCurrentLock() {
if (getLogicalData().getLockTokenID() == null) {
return null;
} else {
LockInfo lockInfo = new LockInfo(LockInfo.LockScope.valueOf(getLogicalData().getLockScope()), LockInfo.LockType.valueOf(getLogicalData().getLockType()), getLogicalData().getLockedByUser(), LockInfo.LockDepth.valueOf(getLogicalData().getLockDepth()));
LockTimeout lockTimeOut = new LockTimeout(getLogicalData().getLockTimeout());
return new LockToken(getLogicalData().getLockTokenID(), lockInfo, lockTimeOut);
}
}
use of io.milton.http.LockTimeout 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.LockTimeout in project lobcder by skoulouzis.
the class LockHandler method processCreateAndLock.
private void processCreateAndLock(HttpManager manager, Request request, Response response, Resource parentResource, String name) throws NotAuthorizedException {
if (parentResource instanceof LockingCollectionResource) {
LockingCollectionResource lockingParent = (LockingCollectionResource) parentResource;
LockTimeout timeout = LockTimeout.parseTimeout(request);
response.setContentTypeHeader(Response.XML);
LockInfo lockInfo;
try {
lockInfo = 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);
// spec says to set response header. See 8.10.1
response.setLockTokenHeader("<opaquelocktoken:" + tok.tokenId + ">");
respondWithToken(tok, request, response);
} else {
// log.debug( "parent does not support lock-null, respondong method not allowed" );
responseHandler.respondMethodNotImplemented(parentResource, response, request);
}
}
use of io.milton.http.LockTimeout in project lobcder by skoulouzis.
the class LockHandler method processExistingResource.
private void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, IOException, SAXException, LockedException, PreConditionFailedException {
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);
}
}
use of io.milton.http.LockTimeout in project lobcder by skoulouzis.
the class SimpleLockManager method refresh.
@Override
public synchronized LockResult refresh(String tokenId, LockableResource resource) {
CurrentLock curLock = locksByToken.get(tokenId);
if (curLock == null || curLock.token == null) {
log.warn("attempt to refresh missing token: " + tokenId + " on resource: " + resource.getName() + " will create a new lock");
LockTimeout timeout = new LockTimeout(60 * 60l);
LockInfo lockInfo = new LockInfo(LockInfo.LockScope.EXCLUSIVE, LockInfo.LockType.WRITE, tokenId, LockInfo.LockDepth.ZERO);
return lock(timeout, lockInfo, resource, tokenId);
}
curLock.token.setFrom(new Date());
return LockResult.success(curLock.token);
}
Aggregations