Search in sources :

Example 1 with LockingCollectionResource

use of io.milton.resource.LockingCollectionResource 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)

Aggregations

LockInfo (io.milton.http.LockInfo)1 LockTimeout (io.milton.http.LockTimeout)1 LockToken (io.milton.http.LockToken)1 LockingCollectionResource (io.milton.resource.LockingCollectionResource)1 IOException (java.io.IOException)1 SAXException (org.xml.sax.SAXException)1