Package org.tmatesoft.svn.core.internal.server.dav

Examples of org.tmatesoft.svn.core.internal.server.dav.DAVException


*/
public class DAVValidateWalker implements IDAVResourceWalkHandler {

    public DAVResponse handleResource(DAVResponse response, DAVResource resource, DAVLockInfoProvider lockInfoProvider, LinkedList ifHeaders,
            int flags, DAVLockScope lockScope, CallType callType) throws DAVException {
        DAVException exception = null;
        try {
            validateResourceState(ifHeaders, resource, lockInfoProvider, lockScope, flags);
            return response;
        } catch (DAVException e) {
            exception = e;
        }
       
        //TODO: I'm not sure what resources we should compare here
        if (DAVServlet.isHTTPServerError(exception.getResponseCode())) {
            throw exception;
        }
       
        DAVResponse resp = new DAVResponse(null, resource.getResourceURI().getRequestURI(), response, null, exception.getResponseCode());       
        return resp;
    }
View Full Code Here


        DAVLock lock = null;
        if (provider != null) {
            try {
                lock = provider.getLock(resource);
            } catch (DAVException dave) {
                throw new DAVException("The locks could not be queried for verification against a possible \"If:\" header.", null,
                        HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, SVNLogType.NETWORK, Level.FINE, dave, null, null, 0, null);
            }
        }
   
        boolean seenLockToken = false;
        if (lockScope == DAVLockScope.EXCLUSIVE) {
            if (lock != null) {
                throw new DAVException("Existing lock(s) on the requested resource prevent an exclusive lock.", ServletDAVHandler.SC_HTTP_LOCKED, 0);
            }
            seenLockToken = true;
        } else if (lockScope == DAVLockScope.SHARED) {
            if (lock.getScope() == DAVLockScope.EXCLUSIVE) {
                throw new DAVException("The requested resource is already locked exclusively.", ServletDAVHandler.SC_HTTP_LOCKED, 0);
            }
            seenLockToken = true;
        } else {
            seenLockToken = lock == null;
        }
       
        if (ifHeaders == null || ifHeaders.isEmpty()) {
            if (seenLockToken) {
                return;
            }
           
            throw new DAVException("This resource is locked and an \"If:\" header was not supplied to allow access to the resource.",
                    ServletDAVHandler.SC_HTTP_LOCKED, 0);
        }
       
        DAVIFHeader ifHeader = (DAVIFHeader) ifHeaders.getFirst();
        if (lock == null && ifHeader.isDummyHeader()) {
            if ((flags & ServletDAVHandler.DAV_VALIDATE_IS_PARENT) != 0) {
                return;
            }
            throw new DAVException("The locktoken specified in the \"Lock-Token:\" header is invalid because this resource has no outstanding locks.",
                    HttpServletResponse.SC_BAD_REQUEST, 0);
        }

        String eTag = resource.getETag();
        String uri = DAVPathUtil.dropTraillingSlash(resource.getResourceURI().getRequestURI());
       
        int numThatAppy = 0;
        String reason = null;
        Iterator ifHeadersIter = ifHeaders.iterator();
        for (;ifHeadersIter.hasNext();) {
            ifHeader = (DAVIFHeader) ifHeadersIter.next();
            if (ifHeader.getURI() != null && !uri.equals(ifHeader.getURI())) {
                continue;
            }
           
            ++numThatAppy;
            LinkedList stateList = ifHeader.getStateList();
            boolean doContinue = false;
            for (Iterator stateListIter = stateList.iterator(); stateListIter.hasNext();) {
                DAVIFState state = (DAVIFState) stateListIter.next();
                if (state.getType() == DAVIFStateType.IF_ETAG) {
                    String currentETag = null;
                    String givenETag = null;
                    String stateETag = state.getETag();
                    if (stateETag.startsWith("W/")) {
                        givenETag = stateETag.substring(2);
                    } else {
                        givenETag = stateETag;
                    }
                   
                    if (eTag.startsWith("W/")) {
                        currentETag = eTag.substring(2);
                    } else {
                        currentETag = eTag;
                    }
                   
                    boolean eTagsDoNotMatch = !givenETag.equals(currentETag);
                   
                    if (state.getCondition() == DAVIFState.IF_CONDITION_NORMAL && eTagsDoNotMatch) {
                        reason = "an entity-tag was specified, but the resource's actual ETag does not match.";
                        doContinue = true;
                        break;
                    } else if (state.getCondition() == DAVIFState.IF_CONDITION_NOT && !eTagsDoNotMatch) {
                        reason = "an entity-tag was specified using the \"Not\" form, but the resource's actual ETag matches the provided entity-tag.";
                        doContinue = true;
                        break;
                    }
                } else if (state.getType() == DAVIFStateType.IF_OPAQUE_LOCK) {
                    if (provider == null) {
                        if (state.getCondition() == DAVIFState.IF_CONDITION_NOT) {
                            continue;
                        }
                       
                        reason = "a State-token was supplied, but a lock database is not available for to provide the required lock.";
                        doContinue = true;
                        break;
                    }
                   
                    boolean matched = false;
                    if (lock != null) {
                        if (!lock.getLockToken().equals(state.getLockToken())) {
                            continue;
                        }
                       
                        seenLockToken = true;
                       
                        if (state.getCondition() == DAVIFState.IF_CONDITION_NOT) {
                            reason = "a State-token was supplied, which used a \"Not\" condition. The State-token was found in the locks on this resource";
                            doContinue = true;
                            break;
                        }
                       
                        String lockAuthUser = lock.getAuthUser();
                        String requestUser = resource.getUserName();
                        if (lockAuthUser != null && (requestUser == null || !lockAuthUser.equals(requestUser))) {
                            throw new DAVException("User \"{0}\" submitted a locktoken created by user \"{1}\".",
                                    new Object[] { requestUser, lockAuthUser }, HttpServletResponse.SC_FORBIDDEN, 0);
                        }
                       
                        matched = true;
                    }
                   
                    if (!matched && state.getCondition() == DAVIFState.IF_CONDITION_NORMAL) {
                        reason = "a State-token was supplied, but it was not found in the locks on this resource.";
                        doContinue = true;
                        break;
                    }
                } else if (state.getType() == DAVIFStateType.IF_UNKNOWN) {
                    if (state.getCondition() == DAVIFState.IF_CONDITION_NORMAL) {
                        reason = "an unknown state token was supplied";
                        doContinue = true;
                        break;
                    }
                }
            }
           
            if (doContinue) {
                continue;
            }
           
            if (seenLockToken) {
                return;
            }
           
            break;
        }
       
        if (!ifHeadersIter.hasNext()) {
            if (numThatAppy == 0) {
                if (seenLockToken) {
                    return;
                }
               
                if (findSubmittedLockToken(ifHeaders, lock)) {
                    return;
                }
               
                throw new DAVException("This resource is locked and the \"If:\" header did not specify one of the locktokens for this resource's lock(s).",
                        ServletDAVHandler.SC_HTTP_LOCKED, 0);
            }
           
            ifHeader = (DAVIFHeader) ifHeaders.getFirst();
            if (ifHeader.isDummyHeader()) {
                throw new DAVException("The locktoken specified in the \"Lock-Token:\" header did not specify one of this resource's locktoken(s).",
                        HttpServletResponse.SC_BAD_REQUEST, 0);
            }
           
            if (reason == null) {
                throw new DAVException("The preconditions specified by the \"If:\" header did not match this resource.",
                        HttpServletResponse.SC_PRECONDITION_FAILED, 0);
            }

            throw new DAVException("The precondition(s) specified by the \"If:\" header did not match this resource. At least one failure is because: {0}",
                    new Object[] { reason }, HttpServletResponse.SC_PRECONDITION_FAILED, 0);
        }
       
        if (findSubmittedLockToken(ifHeaders, lock)) {
            return;
        }
       
        if (ifHeader.isDummyHeader()) {
            throw new DAVException("The locktoken specified in the \"Lock-Token:\" header did not specify one of this resource's locktoken(s).",
                    HttpServletResponse.SC_BAD_REQUEST, 0);
        }
       
        throw new DAVException("This resource is locked and the \"If:\" header did not specify one of the locktokens for this resource's lock(s).",
                ServletDAVHandler.SC_HTTP_LOCKED, 1);
    }
View Full Code Here

    protected void checkSVNNamespace(String errorMessage) throws DAVException {
        errorMessage = errorMessage == null ? "The request does not contain the 'svn:' namespace, so it is not going to have certain required elements." : errorMessage;
        List namespaces = getNamespaces();
        if (!namespaces.contains(DAVElement.SVN_NAMESPACE)) {
            throw new DAVException(errorMessage, HttpServletResponse.SC_BAD_REQUEST, SVNLogType.NETWORK, DAVXMLUtil.SVN_DAV_ERROR_TAG, DAVElement.SVN_DAV_ERROR_NAMESPACE);
        }
    }
View Full Code Here

    }

    public void execute() throws SVNException {
        long read = readInput(false);
        if (myIsUnknownReport) {
            throw new DAVException("The requested report is unknown.", null, HttpServletResponse.SC_NOT_IMPLEMENTED, null, SVNLogType.DEFAULT, Level.FINE,
                    null, DAVXMLUtil.SVN_DAV_ERROR_TAG, DAVElement.SVN_DAV_ERROR_NAMESPACE, SVNErrorCode.UNSUPPORTED_FEATURE.getCode(), null);
        }
       
        if (read == 0) {
            throw new DAVException("The request body must specify a report.", HttpServletResponse.SC_BAD_REQUEST, SVNLogType.NETWORK);
        }

        setDefaultResponseHeaders();
        setResponseContentType(DEFAULT_XML_CONTENT_TYPE);
        setResponseStatus(HttpServletResponse.SC_OK);
View Full Code Here

       
        DAVResourceState resourceState = getResourceState(resource);
        validateRequest(resource, DAVDepth.DEPTH_ZERO, resourceState == DAVResourceState.NULL ? DAV_VALIDATE_PARENT : DAV_VALIDATE_RESOURCE,
                null, null, null);
       
        DAVException err1 = null;
        DAVException err2 = null;
        DAVAutoVersionInfo avInfo = autoCheckOut(resource, true);
        resource.setCollection(true);
        try {
            createdCollection(resource);
        } catch (DAVException dave) {
            err1 = dave;
        }
       
        try {
            autoCheckIn(resource, err1 != null, false, avInfo);
        } catch (DAVException dave) {
            err2 = dave;
        }
       
        if (err1 != null) {
            throw err1;
        }
       
        if (err2 != null) {
            err1 = new DAVException("The MKCOL was successful, but there was a problem opening the lock database which prevents inheriting locks from the parent resources.",
                    err2.getResponseCode(), err2, 0);
        }
       
        DAVLockInfoProvider lockProvider = null;
        try {
            lockProvider = DAVLockInfoProvider.createLockInfoProvider(this, false);
View Full Code Here

        DAVGetLocationsRequest request = getGetLocationsRequest();
        String path = request.getPath();
        long pegRevision = request.getPegRevision();
       
        if (path == null || !SVNRevision.isValidRevisionNumber(pegRevision)) {
            throw new DAVException("Not all parameters passed.", HttpServletResponse.SC_BAD_REQUEST, SVNLogType.NETWORK,
                    DAVXMLUtil.SVN_DAV_ERROR_TAG, DAVElement.SVN_DAV_ERROR_NAMESPACE);
        }
       
        if (!path.startsWith("/")) {
            path = SVNPathUtil.append(resource.getResourceURI().getPath(), path);   
View Full Code Here

            DAVLockWalker lockHandler = new DAVLockWalker(resource, lock);
            DAVResponse response = walker.walk(this, resource, null, 0, null, DAVResourceWalker.DAV_WALKTYPE_NORMAL | DAVResourceWalker.DAV_WALKTYPE_AUTH,
                    lockHandler, DAVDepth.DEPTH_INFINITY);

            if (response != null) {
                throw new DAVException("Error(s) occurred on resources during the addition of a depth lock.", ServletDAVHandler.SC_MULTISTATUS, 0, response);
            }
        }
    }
View Full Code Here

        } catch (SVNException e) {
            throw DAVException.convertError(e.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Token doesn't point to a lock.", null);
        }
       
        if (svnLock == null || !svnLock.getID().equals(lockToken)) {
            throw new DAVException("Lock refresh request doesn't match existing lock.", HttpServletResponse.SC_UNAUTHORIZED, DAVErrorCode.LOCK_SAVE_LOCK);
        }
       
        try {
            svnLock = (FSLock) fsfs.lockPath(svnLock.getPath(), svnLock.getID(), resource.getUserName(), svnLock.getComment(), newTime,
                    SVNRepository.INVALID_REVISION, true, svnLock.isDAVComment());
        } catch (SVNException e) {
            SVNErrorMessage err = e.getErrorMessage();
            if (err.getErrorCode() == SVNErrorCode.FS_NO_USER) {
                throw new DAVException("Anonymous lock refreshing is not allowed.", HttpServletResponse.SC_UNAUTHORIZED, DAVErrorCode.LOCK_SAVE_LOCK);
            }
            throw DAVException.convertError(err, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to refresh existing lock.", null);
        }
        return convertSVNLockToDAVLock(svnLock, false, resource.exists());
    }
View Full Code Here

    public void inheritLocks(DAVResource resource, boolean useParent) throws DAVException {
        DAVResource whichResource = resource;
        if (useParent) {
            DAVResource parentResource = DAVResourceHelper.createParentResource(resource);
            if (parentResource == null) {
                throw new DAVException("Could not fetch parent resource. Unable to inherit locks from the parent and apply them to this resource.",
                        HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 0);
            }
            whichResource = parentResource;
        }
       
View Full Code Here

        if (!resource.exists()) {
            SVNProperties revisionProps = new SVNProperties();
            revisionProps.put(SVNRevisionProperty.AUTHOR, resource.getUserName());
            DAVConfig config = resource.getRepositoryManager().getDAVConfig();
            if (resource.isSVNClient()) {
                throw new DAVException("Subversion clients may not lock nonexistent paths.", HttpServletResponse.SC_METHOD_NOT_ALLOWED,
                        DAVErrorCode.LOCK_SAVE_LOCK);
            } else if (!config.isAutoVersioning()) {
                throw new DAVException("Attempted to lock non-existent path; turn on autoversioning first.",
                        HttpServletResponse.SC_METHOD_NOT_ALLOWED, DAVErrorCode.LOCK_SAVE_LOCK);
            }
           
            long youngestRev = SVNRepository.INVALID_REVISION;
            try {
                youngestRev = resource.getLatestRevision();
            } catch (SVNException svne) {
                throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "Could not determine youngest revision", null);
            }
           
            FSTransactionInfo txnInfo = null;
            try {
                txnInfo = FSTransactionRoot.beginTransactionForCommit(youngestRev, revisionProps, fsfs);
            } catch (SVNException svne) {
                throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "Could not begin a transaction", null);
            }
           
            FSTransactionRoot root = null;
            try {
                root = fsfs.createTransactionRoot(txnInfo);
            } catch (SVNException svne) {
                throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "Could not begin a transaction", null);
            }
           
            FSCommitter committer = new FSCommitter(fsfs, root, txnInfo, resource.getLockTokens(), resource.getUserName());
            try {
                committer.makeFile(path);
            } catch (SVNException svne) {
                throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "Could not create empty file.", null);
            }
           
            try {
                DAVServletUtil.attachAutoRevisionProperties(txnInfo, path, fsfs);
            } catch (SVNException svne) {
                throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "Could not create empty file.", null);
            }
           
            StringBuffer conflictPath = new StringBuffer();
            try {
                committer.commitTxn(true, true, null, conflictPath);
            } catch (SVNException svne) {
                throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_CONFLICT, "Conflict when committing ''{0}''.",
                        new Object[] { conflictPath.toString() });
            }
        }
       
        FSLock svnLock = convertDAVLockToSVNLock(lock, path, resource.isSVNClient(), ServletDAVHandler.getSAXParserFactory());
        try {
            fsfs.lockPath(path, svnLock.getID(), svnLock.getOwner(), svnLock.getComment(), svnLock.getExpirationDate(), myWorkingRevision,
                    myIsStealLock, svnLock.isDAVComment());
        } catch (SVNException svne) {
            if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.FS_NO_USER) {
                throw new DAVException("Anonymous lock creation is not allowed.", HttpServletResponse.SC_UNAUTHORIZED,
                        DAVErrorCode.LOCK_SAVE_LOCK);
            }
            throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create new lock.",
                    null);
        }
View Full Code Here

TOP

Related Classes of org.tmatesoft.svn.core.internal.server.dav.DAVException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.