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

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


            invalidXMLRoot();
        }
    }

    protected void invalidXMLRoot() throws SVNException {
        throw new DAVException("The request body, if present, must be a DAV:checkout element.", null, HttpServletResponse.SC_BAD_REQUEST,
                null, SVNLogType.NETWORK, Level.FINE, null, null, null, 0, null);
    }
View Full Code Here


        if (myResource.isWorking()) {
            return response;
        }
       
        if (myResource.getType() != DAVResourceType.REGULAR) {
            throw new DAVException("Walking the resource hierarchy can only be done on 'regular' resources [at this time].",
                    HttpServletResponse.SC_METHOD_NOT_ALLOWED, 0);
        }
        //TODO: log here that we are listing a dir
View Full Code Here

        try {
            int flags = resourceState == DAVResourceState.NULL ? DAV_VALIDATE_PARENT : DAV_VALIDATE_RESOURCE;
            flags |= DAV_VALIDATE_ADD_LD;
            validateRequest(resource, depth, flags, isNewLockRequest ? lock.getScope() : null, null, lockProvider);
        } catch (DAVException dave) {
            DAVException next = new DAVException("Could not LOCK {0} due to a failed precondition (e.g. other locks).",
                    new Object[] { SVNEncodingUtil.xmlEncodeCDATA(resource.getResourceURI().getRequestURI(), true) }, dave.getResponseCode(), dave, 0);
            throw next;
        }
           
        if (!isNewLockRequest) {
            List lockTokens = null;
            try {
                lockTokens = getLockTokensList();
            } catch (DAVException dave) {
                DAVException next = new DAVException("The lock refresh for {0} failed because no lock tokens were specified in an \"If:\" header.",
                        new Object[] { SVNEncodingUtil.xmlEncodeCDATA(resource.getResourceURI().getRequestURI(), true) }, dave.getResponseCode(), dave, 0);
                throw next;
            }
               
            String lockToken = (String) lockTokens.get(0);
            lock = lockProvider.refreshLock(resource, lockToken, getTimeout());
        } else {
            if (lock.getTimeOutDate() != null) {
                //TODO: add expiration date renewal
                //Date timeoutDate = lock.getTimeOutDate();
            }
           
            lockProvider.addLock(lock, resource);
            setResponseHeader(HTTPHeader.LOCK_TOKEN_HEADER, "<" + lock.getLockToken() + ">");
        }
       
        HttpServletResponse servletResponse = getHttpServletResponse();
        servletResponse.setContentType(DEFAULT_XML_CONTENT_TYPE);
        servletResponse.setStatus(HttpServletResponse.SC_OK);
       
        try {
            StringBuffer xmlBuffer = SVNXMLUtil.addXMLHeader(null);
            DAVXMLUtil.openNamespaceDeclarationTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.PROP.getName(), null, null, xmlBuffer, true, false);
            if (lock == null) {
                SVNXMLUtil.openXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_DISCOVERY.getName(), SVNXMLUtil.XML_STYLE_SELF_CLOSING, null, xmlBuffer);
            } else {
                SVNXMLUtil.openXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_DISCOVERY.getName(), SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, xmlBuffer);
                xmlBuffer.append(DAVLockInfoProvider.getActiveLockXML(lock));
                xmlBuffer.append('\n');
                SVNXMLUtil.closeXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.LOCK_DISCOVERY.getName(), xmlBuffer);
            }
            SVNXMLUtil.closeXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.PROP.getName(), xmlBuffer);
            getResponseWriter().write(xmlBuffer.toString());
        } catch (IOException e) {
            throw new DAVException(e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 0);
        }
    }
View Full Code Here

        DAVPropertiesProvider propsProvider = null;
        try {
            propsProvider = DAVPropertiesProvider.createPropertiesProvider(resource, this);
        } catch (DAVException dave) {
            autoCheckIn(resource, true, false, avInfo);
            throw new DAVException("Could not open the property database for {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) },
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 0);
        }
       
        boolean isFailure = false;
        List properties = new LinkedList();
        DAVPropPatchRequest requestXMLObject = getPropPatchRequest()
        DAVElementProperty rootElement = requestXMLObject.getRoot();
        List childrenElements = rootElement.getChildren();
        for (Iterator childrenIter = childrenElements.iterator(); childrenIter.hasNext();) {
            DAVElementProperty childElement = (DAVElementProperty) childrenIter.next();
            DAVElement childElementName = childElement.getName();
            if (!DAVElement.DAV_NAMESPACE.equals(childElementName.getNamespace()) || (childElementName != DAVPropPatchRequest.REMOVE &&
                    childElementName != DAVPropPatchRequest.SET)) {
                continue;
            }

            DAVElementProperty propChildrenElement = childElement.getChild(DAVElement.PROP);
            if (propChildrenElement == null) {
                autoCheckIn(resource, true, false, avInfo);
                SVNDebugLog.getDefaultLog().logError(SVNLogType.NETWORK, "A \"prop\" element is missing inside the propertyupdate command.");
                setResponseStatus(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
           
            boolean isRemove = childElementName == DAVPropPatchRequest.REMOVE;
            List propChildren = propChildrenElement.getChildren();
            for (Iterator propsIter = propChildren.iterator(); propsIter.hasNext();) {
                DAVElementProperty property = (DAVElementProperty) propsIter.next();
                DAVElement propertyName = property.getName();
                PropertyChangeContext propContext = new PropertyChangeContext();
                propContext.myIsSet = !isRemove;
                propContext.myProperty = property;
                properties.add(propContext);
                validateProp(propertyName, propsProvider, propContext);
                if (propContext.myError != null && propContext.myError.getResponseCode() >= 300) {
                    isFailure = true;
                }
            }
        }
       
        String propStatText = null;
        DAVPropertyExecuteHandler executeHandler = new DAVPropertyExecuteHandler(propsProvider);
        if (!isFailure && processPropertyContextList(executeHandler, properties, true, false)) {
            isFailure = true;
        }
       
        if (isFailure) {
            DAVPropertyRollBackHandler rollBackHandler = new DAVPropertyRollBackHandler(propsProvider);
            processPropertyContextList(rollBackHandler, properties, false, true);
            propStatText = getFailureMessage(properties);
        } else {
            propStatText = getSuccessMessage(properties);
        }
       
        autoCheckIn(resource, isFailure, false, avInfo);
        //TODO: log propCtxt.error here later
        DAVPropsResult propResult = new DAVPropsResult();
        propResult.addPropStatsText(propStatText);
        DAVResponse response = new DAVResponse(null, resource.getResourceURI().getRequestURI(), null, propResult, 0);
        try {
            DAVXMLUtil.sendMultiStatus(response, getHttpServletResponse(), SC_MULTISTATUS, getNamespaces());
        } catch (IOException ioe) {
            throw new DAVException(ioe.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, SVNErrorCode.IO_ERROR.getCode());
        }
    }
View Full Code Here

            throw new DAVException(ioe.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, SVNErrorCode.IO_ERROR.getCode());
        }
    }

    private String getFailureMessage(List propContextList) {
        DAVException err424Set = null;
        DAVException err424Delete = null;
        StringBuffer buffer = new StringBuffer();
        for (Iterator propsIter = propContextList.iterator(); propsIter.hasNext();) {
            PropertyChangeContext propContext = (PropertyChangeContext) propsIter.next();
            SVNXMLUtil.openXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.PROPSTAT.getName(), SVNXMLUtil.XML_STYLE_NORMAL, null, buffer);
            SVNXMLUtil.openXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.PROP.getName(), SVNXMLUtil.XML_STYLE_PROTECT_CDATA, null, buffer);
            DAVXMLUtil.addEmptyElement(getNamespaces(), propContext.myProperty.getName(), buffer);
            SVNXMLUtil.closeXMLTag(SVNXMLUtil.DAV_NAMESPACE_PREFIX, DAVElement.PROP.getName(), buffer);
            if (propContext.myError == null) {
                if (propContext.myIsSet) {
                    if (err424Set == null) {
                        err424Set = new DAVException("Attempted DAV:set operation could not be completed due to other errors.",
                                SC_FAILED_DEPENDANCY, 0);
                    }
                    propContext.myError = err424Set;
                } else {
                    if (err424Delete == null) {
                        err424Delete = new DAVException("Attempted DAV:remove operation could not be completed due to other errors.",
                                SC_FAILED_DEPENDANCY, 0);
                    }
                    propContext.myError = err424Delete;
                }
            }
View Full Code Here

    private void validateProp(DAVElement property, DAVPropertiesProvider propsProvider,
            PropertyChangeContext propContext) {
        LivePropertySpecification livePropSpec = findLiveProperty(property);
        propContext.myLivePropertySpec = livePropSpec;
        if (!isPropertyWritable(property, livePropSpec)) {
            propContext.myError = new DAVException("Property is read-only.", HttpServletResponse.SC_CONFLICT, DAVErrorCode.PROP_READONLY);
            return;
        }
       
        if (livePropSpec != null && livePropSpec.isSVNSupported()) {
            return;
        }
       
        if (propsProvider.isDeferred()) {
            try {
                propsProvider.open(false);
            } catch (DAVException dave) {
                propContext.myError = dave;
                return;
            }
        }
       
        if (!propsProvider.isOperative()) {
            propContext.myError = new DAVException("Attempted to set/remove a property without a valid, open, read/write property database.",
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DAVErrorCode.PROP_NO_DATABASE);
            return;
        }
    }
View Full Code Here

                }
            }
        }
       
        private void handleError(DAVException dave, PropertyChangeContext propContext) {
            DAVException exc = new DAVException("Could not execute PROPPATCH.", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, dave,
                    DAVErrorCode.PROP_EXEC);
            propContext.myError = exc;
        }
View Full Code Here

                            propContext.myRollBackProperty.myRollBackPropertyValue);
                } catch (DAVException dave) {
                    if (propContext.myError == null) {
                        propContext.myError = dave;
                    } else {
                        DAVException err = dave;
                        while (err.getPreviousException() != null) {
                            err = err.getPreviousException();
                        }
                        err.setPreviousException(propContext.myError);
                        propContext.myError = dave;
                    }
                }
            }
        }
View Full Code Here

        String path = uri.getPath();
        DAVRepositoryManager manager = getRepositoryManager();
        String resourceContext = manager.getResourceContext();
       
        if (!path.startsWith(resourceContext)) {
            throw new DAVException("Destination url starts with a wrong context", HttpServletResponse.SC_BAD_REQUEST, 0);
        }
       
        path = path.substring(resourceContext.length());
        DAVResource newResource = getRequestedDAVResource(false, false, path);
        int overwrite = getOverwrite();
        if (overwrite < 0) {
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        if (newResource.exists() && overwrite == 0) {
            response("Destination is not empty and Overwrite is not \"T\"", DAVServlet.getStatusLine(HttpServletResponse.SC_PRECONDITION_FAILED),
                    HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
       
        if (resource.equals(newResource)) {
            response("Source and Destination URIs are the same.", DAVServlet.getStatusLine(HttpServletResponse.SC_FORBIDDEN),
                    HttpServletResponse.SC_FORBIDDEN);
            return;
        }
       
        boolean isDir = resource.isCollection();
        DAVDepth depth = null;
        try {
            depth = getRequestDepth(DAVDepth.DEPTH_INFINITY);
        } catch (SVNException svne) {
            throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_BAD_REQUEST, null, null);
        }
       
        if (depth == DAVDepth.DEPTH_ONE) {
            //add logging here later
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        if (myIsMove && isDir && depth != DAVDepth.DEPTH_INFINITY) {
            //add logging here later
            sendError(HttpServletResponse.SC_BAD_REQUEST, null);
            return;
        }
       
        if (myIsMove) {
            try {
                validateRequest(resource, depth, DAV_VALIDATE_PARENT | DAV_VALIDATE_USE_424, null, null, null);
            } catch (DAVException dave) {
                throw new DAVException("Could not MOVE {0} due to a failed precondition on the source (e.g. locks).",
                        new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) }, dave.getResponseCode(), null, SVNLogType.NETWORK,
                        Level.FINE, dave, null, null, 0, dave.getResponse());
            }
        }
       
        try {
            validateRequest(newResource, DAVDepth.DEPTH_INFINITY, DAV_VALIDATE_PARENT | DAV_VALIDATE_USE_424, null, null, null);
        } catch (DAVException dave) {
            throw new DAVException("Could not MOVE/COPY {0} due to a failed precondition on the destination (e.g. locks).",
                    new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) }, dave.getResponseCode(), null, SVNLogType.NETWORK, Level.FINE,
                    dave, null, null, 0, dave.getResponse());
        }
       
        if (isDir && depth == DAVDepth.DEPTH_INFINITY && resource.isParentResource(newResource)) {
            response("Source collection contains the Destination.", DAVServlet.getStatusLine(HttpServletResponse.SC_FORBIDDEN), HttpServletResponse.SC_FORBIDDEN);
            return;
        }
       
        if (isDir && newResource.isParentResource(newResource)) {
            response("Destination collection contains the Source and Overwrite has been specified.", DAVServlet.getStatusLine(HttpServletResponse.SC_FORBIDDEN),
                    HttpServletResponse.SC_FORBIDDEN);
            return;
        }
       
        readInput(true);
        DAVLockInfoProvider lockProvider = null;
        try {
            lockProvider = DAVLockInfoProvider.createLockInfoProvider(this, false);
        } catch (SVNException svne) {
            throw DAVException.convertError(svne.getErrorMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, null);
        }
       
        if (myIsMove) {
            unlock(resource, null);
        }
       
        DAVAutoVersionInfo srcAVInfo = null;
        if (myIsMove) {
            srcAVInfo = autoCheckOut(resource, true);
           
        }
       
        boolean replaceDestination = false;
        DAVResourceState resNewState = getResourceState(newResource);
        if (newResource.exists()) {
            if (myIsMove || !newResource.isVersioned()) {
                replaceDestination = true;
            } else if (resource.getType() != newResource.getType()) {
                replaceDestination = true;
            } else if (resource.isCollection() != newResource.isCollection()) {
                replaceDestination = true;
            }
        }
       
        DAVAutoVersionInfo dstAVInfo = null;
        if (!newResource.exists() || replaceDestination) {
            try {
                 dstAVInfo = autoCheckOut(newResource, true);
            } catch (DAVException dave) {
                if (myIsMove) {
                    autoCheckIn(null, true, false, srcAVInfo);
                }
                throw dave;
            }
        }
       
        if (srcAVInfo != null && srcAVInfo.getParentResource() != null && dstAVInfo != null &&
                dstAVInfo.getParentResource() != null) {
            DAVResource srcParentResource = srcAVInfo.getParentResource();
            DAVResource dstParentResource = dstAVInfo.getParentResource();
            if (srcParentResource.equals(dstParentResource)) {
                dstAVInfo.setParentResource(srcAVInfo.getParentResource());
            }
        }
       
        DAVException err1 = null;
        if (replaceDestination) {
            try {
                removeResource(newResource);
            } catch (DAVException dave) {
                err1 = dave;
            }
        }

        if (err1 == null) {
            if (myIsMove) {
                try {
                    moveResource(resource, newResource);
                } catch (DAVException dave) {
                    err1 = dave;
                }
            } else {
                try {
                    copyResource(resource, newResource);
                } catch (DAVException dave) {
                    err1 = dave;
                }
            }
        }

        DAVException err2 = null;
        try {
            autoCheckIn(null, err1 != null, false, dstAVInfo);
        } catch (DAVException dave) {
            err2 = dave;
        }
       
        DAVException err3 = null;
        if (myIsMove) {
            try {
                autoCheckIn(null, err1 != null, false, srcAVInfo);
            } catch (DAVException dave) {
                err3 = dave;
            }
        }
       
        if (err1 != null) {
            throw new DAVException("Could not MOVE/COPY {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) },
                    err1.getResponseCode(), err1, 0);
        }
       
        if (err2 != null) {
            //throw new DAVException("The MOVE/COPY was successful, but there was a problem automatically checking in the source parent collection.", null, err2.getResponseCode(), err2, 0);
            //TODO: add logging here later
        }
        if (err3 != null) {
            //TODO: add logging here later
        }
       
        try {
            notifyCreated(newResource, lockProvider, resNewState, depth);
        } catch (DAVException dave) {
            throw new DAVException("The MOVE/COPY was successful, but there was a problem updating the lock information.", null,
                    dave.getResponseCode(), dave, 0);
        }
       
        handleDAVCreated(uri.toString(), "Destination", resNewState == DAVResourceState.EXISTS);
    }
View Full Code Here

                            activities.add(activitySetChild.getFirstValue(true));
                        }
                    }
                   
                    if (activities.isEmpty()) {
                        throw new DAVException("Within the DAV:activity-set element, the DAV:new element must be used, or at least one DAV:href must be specified.",
                                null, HttpServletResponse.SC_BAD_REQUEST, null, SVNLogType.NETWORK, Level.FINE, null, null, null, 0, null);
                    }
                }
            }
        }
       
        DAVResource resource = getRequestedDAVResource(true, applyToVSN);
        if (!resource.exists()) {
            throw new DAVException(DAVServlet.getStatusLine(HttpServletResponse.SC_NOT_FOUND), null, HttpServletResponse.SC_NOT_FOUND, null,
                    SVNLogType.NETWORK, Level.FINE, null, null, null, 0, null);
        }
       
        if (resource.getResourceURI().getType() != DAVResourceType.REGULAR &&
                resource.getResourceURI().getType() != DAVResourceType.VERSION) {
            response("Cannot checkout this type of resource.", DAVServlet.getStatusLine(HttpServletResponse.SC_CONFLICT),
                    HttpServletResponse.SC_CONFLICT);
        }
       
        if (!resource.isVersioned()) {
            response("Cannot checkout unversioned resource.", DAVServlet.getStatusLine(HttpServletResponse.SC_CONFLICT),
                    HttpServletResponse.SC_CONFLICT);
        }
       
        if (resource.isWorking()) {
            response("The resource is already checked out to the workspace.", DAVServlet.getStatusLine(HttpServletResponse.SC_CONFLICT),
                    HttpServletResponse.SC_CONFLICT);
        }

        DAVResource workingResource = null;
        try {
            workingResource = checkOut(resource, false, isUnreserved, createActivity, activities);
        } catch (DAVException dave) {
            throw new DAVException("Could not CHECKOUT resource {0}.", new Object[] { SVNEncodingUtil.xmlEncodeCDATA(getURI()) },
                    HttpServletResponse.SC_CONFLICT, null, SVNLogType.NETWORK, Level.FINE, dave, null, null, 0, null);
        }
       
        setResponseHeader(CACHE_CONTROL_HEADER, CACHE_CONTROL_VALUE);
       
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.