Search in sources :

Example 6 with LockToken

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);
    }
}
Also used : LockToken(io.milton.http.LockToken) LockingCollectionResource(io.milton.resource.LockingCollectionResource) LockInfo(io.milton.http.LockInfo) IOException(java.io.IOException) LockTimeout(io.milton.http.LockTimeout) SAXException(org.xml.sax.SAXException)

Example 7 with LockToken

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;
    }
}
Also used : LockToken(io.milton.http.LockToken)

Aggregations

LockToken (io.milton.http.LockToken)7 LockInfo (io.milton.http.LockInfo)5 LockTimeout (io.milton.http.LockTimeout)3 LockResult (io.milton.http.LockResult)2 FsFileResource (io.milton.http.fs.FsFileResource)1 FsResource (io.milton.http.fs.FsResource)1 SimpleFileContentService (io.milton.http.fs.SimpleFileContentService)1 LockingCollectionResource (io.milton.resource.LockingCollectionResource)1 File (java.io.File)1 IOException (java.io.IOException)1 SAXException (org.xml.sax.SAXException)1