Search in sources :

Example 1 with LockedException

use of io.milton.http.exceptions.LockedException in project lobcder by skoulouzis.

the class WebDataResource method lock.

@Override
public LockResult lock(LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException, PreConditionFailedException, LockedException {
    if (getCurrentLock() != null) {
        throw new LockedException(this);
    }
    LockToken lockToken = new LockToken(UUID.randomUUID().toString(), lockInfo, timeout);
    Long lockTimeout;
    try (Connection connection = getCatalogue().getConnection()) {
        try {
            getLogicalData().setLockTokenID(lockToken.tokenId);
            getCatalogue().setLockTokenID(getLogicalData().getUid(), getLogicalData().getLockTokenID(), connection);
            getLogicalData().setLockScope(lockToken.info.scope.toString());
            getCatalogue().setLockScope(getLogicalData().getUid(), getLogicalData().getLockScope(), connection);
            getLogicalData().setLockType(lockToken.info.type.toString());
            getCatalogue().setLockType(getLogicalData().getUid(), getLogicalData().getLockType(), connection);
            getLogicalData().setLockedByUser(lockToken.info.lockedByUser);
            getCatalogue().setLockByUser(getLogicalData().getUid(), getLogicalData().getLockedByUser(), connection);
            getLogicalData().setLockDepth(lockToken.info.depth.toString());
            getCatalogue().setLockDepth(getLogicalData().getUid(), getLogicalData().getLockDepth(), connection);
            lockTimeout = lockToken.timeout.getSeconds();
            if (lockTimeout == null) {
                lockTimeout = Long.valueOf(System.currentTimeMillis() + Constants.LOCK_TIME);
            }
            getLogicalData().setLockTimeout(lockTimeout);
            getCatalogue().setLockTimeout(getLogicalData().getUid(), lockTimeout, connection);
            connection.commit();
            return LockResult.success(lockToken);
        } catch (Exception ex) {
            Logger.getLogger(WebDataResource.class.getName()).log(Level.SEVERE, null, ex);
            connection.rollback();
            throw new PreConditionFailedException(this);
        }
    } catch (SQLException e) {
        Logger.getLogger(WebDataResource.class.getName()).log(Level.SEVERE, null, e);
        throw new PreConditionFailedException(this);
    }
}
Also used : LockedException(io.milton.http.exceptions.LockedException) PreConditionFailedException(io.milton.http.exceptions.PreConditionFailedException) URISyntaxException(java.net.URISyntaxException) BadRequestException(io.milton.http.exceptions.BadRequestException) PreConditionFailedException(io.milton.http.exceptions.PreConditionFailedException) IOException(java.io.IOException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LockedException(io.milton.http.exceptions.LockedException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with LockedException

use of io.milton.http.exceptions.LockedException in project lobcder by skoulouzis.

the class LockHandler method process.

@Override
public void process(HttpManager httpManager, Request request, Response response) throws ConflictException, NotAuthorizedException, BadRequestException, NotFoundException {
    if (!handlerHelper.checkExpects(responseHandler, request, response)) {
        return;
    }
    String host = request.getHostHeader();
    String url = HttpManager.decodeUrl(request.getAbsolutePath());
    Resource r = httpManager.getResourceFactory().getResource(host, url);
    try {
        // Find a resource if it exists
        if (r != null) {
            processExistingResource(httpManager, request, response, r);
        } else {
            processNonExistingResource(httpManager, request, response, host, url);
        }
    } catch (IOException ex) {
        throw new BadRequestException(r);
    } catch (SAXException ex) {
        throw new BadRequestException(r);
    } catch (LockedException ex) {
        responseHandler.respondLocked(request, response, r);
    } catch (PreConditionFailedException ex) {
        responseHandler.respondPreconditionFailed(request, response, r);
    }
}
Also used : LockedException(io.milton.http.exceptions.LockedException) PreConditionFailedException(io.milton.http.exceptions.PreConditionFailedException) LockingCollectionResource(io.milton.resource.LockingCollectionResource) Resource(io.milton.resource.Resource) LockableResource(io.milton.resource.LockableResource) BadRequestException(io.milton.http.exceptions.BadRequestException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

BadRequestException (io.milton.http.exceptions.BadRequestException)2 LockedException (io.milton.http.exceptions.LockedException)2 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)2 IOException (java.io.IOException)2 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)1 LockableResource (io.milton.resource.LockableResource)1 LockingCollectionResource (io.milton.resource.LockingCollectionResource)1 Resource (io.milton.resource.Resource)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SAXException (org.xml.sax.SAXException)1