use of io.milton.http.LockToken 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.LockToken in project lobcder by skoulouzis.
the class SimpleLockManager method currentLock.
private LockToken currentLock(LockableResource resource) {
CurrentLock curLock = locksByUniqueId.get(resource.getUniqueId());
if (curLock == null) {
return null;
}
LockToken token = curLock.token;
if (token.isExpired()) {
removeLock(token);
return null;
} else {
return token;
}
}
Aggregations