Search in sources :

Example 6 with LockInfo

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

Example 7 with LockInfo

use of io.milton.http.LockInfo 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 8 with LockInfo

use of io.milton.http.LockInfo 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

LockInfo (io.milton.http.LockInfo)8 LockToken (io.milton.http.LockToken)5 LockTimeout (io.milton.http.LockTimeout)4 LockResult (io.milton.http.LockResult)2 LockInfoSaxHandler (io.milton.http.LockInfoSaxHandler)1 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 InputStream (java.io.InputStream)1 Date (java.util.Date)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 DatatypeFactory (javax.xml.datatype.DatatypeFactory)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Permissions (nl.uva.cs.lobcder.auth.Permissions)1 PDRIDescr (nl.uva.cs.lobcder.resources.PDRIDescr)1 InputSource (org.xml.sax.InputSource)1