Search in sources :

Example 1 with LockTimeout

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

Example 2 with 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);
}
Also used : FsResource(io.milton.http.fs.FsResource) LockResult(io.milton.http.LockResult) FsFileResource(io.milton.http.fs.FsFileResource) LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo) SimpleFileContentService(io.milton.http.fs.SimpleFileContentService) File(java.io.File) LockTimeout(io.milton.http.LockTimeout)

Example 3 with LockTimeout

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);
    }
}
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 4 with LockTimeout

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

Example 5 with LockTimeout

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);
}
Also used : LockInfo(io.milton.http.LockInfo) Date(java.util.Date) LockTimeout(io.milton.http.LockTimeout)

Aggregations

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