Package org.apache.slide.webdav

Examples of org.apache.slide.webdav.WebdavException


                }
            }
            catch (IOException  e){
                int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
                sendError( statusCode, e );
                throw new WebdavException( statusCode );
            }
            catch (JDOMException  e){
                int statusCode = WebdavStatus.SC_BAD_REQUEST;
                sendError( statusCode, e );
                throw new WebdavException( statusCode );
            }
        }
    }
View Full Code Here


        // check lock-null resources
        try {
            if (isLockNull(resourcePath)) {
                int statusCode = WebdavStatus.SC_NOT_FOUND;
                sendError( statusCode, "lock-null resource", new Object[]{resourcePath} );
                throw new WebdavException( statusCode );
            }
        }
        catch (ServiceAccessException e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }

        try {
            VersioningHelper vh = VersioningHelper.getVersioningHelper(
                slideToken, token, req, resp, getConfig() );

            if ( WebdavEvent.CHECKIN.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.CHECKIN, new WebdavEvent(this));

            locationValue = vh.checkin( resourcePath , forkOk, keepCheckedOut, false);
        }
        catch (PreconditionViolationException e) {
            sendPreconditionViolation(e);
            throw e;
        }
        catch (Exception e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
        finally {
            resp.setHeader(H_CACHE_CONTROL, NO_CACHE);
            if( locationValue != null && locationValue.length() > 0 ) {
                locationValue = getFullPath( locationValue );
View Full Code Here

            sourceUri = parseUri(MethodUtil.getChildUrl(content, E_HREF));
        }
        catch (IOException e) {  // TODO: merge exception handling into jdom access methods
            int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
        catch (JDOMException e) {  // TODO: merge exception handling into jdom access methods
            int statusCode = WebdavStatus.SC_BAD_REQUEST;
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }

        collectionUri = requestUri;
        if (collectionUri == null) {
            collectionUri = "/";
View Full Code Here

        // check lock-null resources
        try {
            if (isLockNull(collectionUri)) {
                int statusCode = WebdavStatus.SC_NOT_FOUND;
                sendError( statusCode, "lock-null resource", new Object[]{collectionUri} );
                throw new WebdavException( statusCode );
            }
        }
        catch (ServiceAccessException e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }

        try {
            checkPreconditions();

            if ( WebdavEvent.BIND.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.BIND, new WebdavEvent(this));

            structure.addBinding( slideToken, collectionNode, segment, sourceNode );
        }
        catch (ObjectLockedException e) {
            ViolatedPrecondition violatedPrecondition;
            if (collectionUri.equals(e.getObjectUri())) {
                violatedPrecondition =
                    new ViolatedPrecondition(C_LOCKED_UPDATE_ALLOWED, WebdavStatus.SC_LOCKED);
            }
            else {
                violatedPrecondition =
                    new ViolatedPrecondition(C_LOCKED_OVERWRITE_ALLOWED, WebdavStatus.SC_CONFLICT);
            }
            sendPreconditionViolation(
                new PreconditionViolationException(violatedPrecondition, collectionNode.getUri())
            );
        }
        catch (CrossServerBindingException e) {
            sendPreconditionViolation(
                new PreconditionViolationException(
                                         new ViolatedPrecondition(C_CROSS_SERVER_BINDING, WebdavStatus.SC_FORBIDDEN),
                                         collectionNode.getUri()
                                     )
            );
        }
        catch (PreconditionViolationException e) {
            sendPreconditionViolation(e);
            throw e;
        }
        catch (Exception e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
    }
View Full Code Here

        throws WebdavException {
       
        if (req.getContentLength() > 0) {
            int statusCode = WebdavStatus.SC_UNSUPPORTED_MEDIA_TYPE;
            sendError( statusCode, getClass().getName()+".requestBodyMustBeEmpty" );
            throw new WebdavException( statusCode );
        }
       
        colName = requestUri;
        if (colName == null) {
            colName = "/";
View Full Code Here

            isLockNull = isLockNull( revisionDescriptor );
        }
        catch (ServiceAccessException e) {
            int statusCode = getErrorCode((Exception)e);
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
        catch (SlideException e) {
            // ignore silently
        }
       
        if (revisionDescriptor == null) {
            revisionDescriptor =
                new NodeRevisionDescriptor(0);
        }
       
        // check destination URI
        UriHandler destinationUriHandler = UriHandler.getUriHandler(colName);
        if (destinationUriHandler.isRestrictedUri()) {
            int statusCode = WebdavStatus.SC_FORBIDDEN;
            sendError( statusCode, getClass().getName()+".restrictedDestinationUri", new Object[]{colName} );
            throw new WebdavException( statusCode );
        }
       
        // Resource type
        revisionDescriptor.setResourceType(NodeRevisionDescriptor.COLLECTION_TYPE);
       
        // Creation date
        revisionDescriptor.setCreationDate(new Date());
       
        // Last modification date
        revisionDescriptor.setLastModified(new Date());
       
        // Content length name
        revisionDescriptor.setContentLength(0);
       
        // Source
        revisionDescriptor.setSource("");
       
        // Owner
        try {
            String creator = ((SubjectNode)security.getPrincipal(slideToken)).getPath().lastSegment();
            revisionDescriptor.setCreationUser(creator);
            revisionDescriptor.setOwner(creator);
        } catch (Exception e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
       
        // Added for DeltaV --start--
        if( Configuration.useVersionControl() ) {
            VersioningHelper vHelp =  VersioningHelper.getVersioningHelper(
                slideToken, token, req, resp, getConfig() );
           
            // Workspace
            vHelp.setWorkspaceProperty( colName, revisionDescriptor );
        }
        // Added for DeltaV --end--
       
        if (isMsProprietarySupport()) {
           
            NodeProperty property = null;
           
            // Name
            /*
             property = new NodeProperty("name", colName, "ms", "MICROSOFT");
             properties.setProperty(property);
             */
           
            // ParentName
            // TODO : Fix this
            /*
             property = new NodeProperty("parentname", colName, "ms",
             "MICROSOFT");
             properties.setProperty(property);
             */
           
            // Href
            /*
             property = new NodeProperty("href", colName, "ms", "MICROSOFT");
             properties.setProperty(property);
             */
           
            // Is hidden
            property = new NodeProperty("ishidden", "0", "MICROSOFT");
            revisionDescriptor.setProperty(property);
           
            // Is collection
            property = new NodeProperty("iscollection", "1", "MICROSOFT");
            revisionDescriptor.setProperty(property);
           
            // Is read only
            property = new NodeProperty("isreadonly", "0", "MICROSOFT");
            revisionDescriptor.setProperty(property);
           
            // Last accessed
            property = new NodeProperty("lastaccessed",
                                            (new Date()).toString(), "MICROSOFT");
            revisionDescriptor.setProperty(property);
           
        }
       
        // If everything is ok : 201 - Created / OK
        resp.setStatus(WebdavStatus.SC_CREATED);
       
        try {
            if ( WebdavEvent.MKCOL.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.MKCOL, new WebdavEvent(this));

            if (!isLockNull) {
                SubjectNode collection = new SubjectNode();
                structure.create(slideToken, collection, colName);
                content.create(slideToken, colName, revisionDescriptor, null);
            }
            else {
                content.store(slideToken, colName, revisionDescriptor, null);
            }
        } catch (Exception e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
       
        // 415 - Unsupported Media Type
        // TODO : Has something to do with the body of the request ...
        // WebDAV RFC is vague on the subject.
View Full Code Here

        // check lock-null resources
        try {
            if (isLockNull(toDelete)) {
                int statusCode = WebdavStatus.SC_NOT_FOUND;
                sendError( statusCode, "lock-null resource", new Object[]{toDelete} );
                throw new WebdavException( statusCode );
            }
        }
        catch (ServiceAccessException e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
       
        isCollection = isCollection(toDelete);
        try {
            if ( WebdavEvent.DELETE.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.DELETE, new WebdavEvent(this));

            macro.delete(slideToken, toDelete, null, this);
            resp.setStatus(WebdavStatus.SC_NO_CONTENT);
        } catch (DeleteMacroException dme) {
            // If it's not a collection, we don't want to give a 207,
            // because it's silly, and it confuses many clients (such as
            // MS Web Folders).
            if (generateMultiStatusResponse(isCollection, dme, requestUri)) {
                String errorMessage = generateErrorMessage(dme);
                // Write it on the servlet writer
                resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
                try {
                    resp.setContentType(TEXT_XML_UTF_8);
                    resp.getWriter().write(errorMessage);
                } catch(IOException ex) {
                    // Critical error ... Servlet container is dead or something
                    int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
                    sendError( statusCode, ex );
                    throw new WebdavException( statusCode );
                }
            } else {
                // Returning 207 on non-collection requests is generally
                // considered bad. So let's not do it, since this way
                // makes clients generally behave better.
                SlideException exception = (SlideException)dme.enumerateExceptions().nextElement();
                if (exception instanceof PreconditionViolationException) {
                    try {
                        sendPreconditionViolation((PreconditionViolationException)exception);
                    } catch(IOException ex) {
                        // Critical error ... Servlet container is dead or something
                        int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
                        sendError( statusCode, ex );
                        throw new WebdavException( statusCode );
                    }
                }
                else {
                    int statusCode = getErrorCode( exception );
                    sendError( statusCode, exception );
                    throw new WebdavException( statusCode );
                }
            }
            //
            // make sure the transaction is aborted
            // throw any WebDAV exception to indicate the transaction wants to be aborted
            //
            throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
        } catch( SlideException x ) {
            int statusCode = getErrorCode((SlideException)x);
            sendError( statusCode, x );
            throw new WebdavException( statusCode );
        }
    }
View Full Code Here

            }
            xmlOut.output(new Document(multistatus), resp.getWriter());
        } catch (Exception e) {
            int statusCode = getErrorCode( (Exception)e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
    }
View Full Code Here

               
            }
            catch( Exception e ) {
                int statusCode = getErrorCode( e );
                sendError( statusCode, e );
                throw new WebdavException( statusCode );
            }
        }
        else {
            int statusCode = WebdavStatus.SC_BAD_REQUEST;
            sendError( statusCode, getClass().getName()+".missingRequestBody" );
            throw new WebdavException( statusCode );
        }
       
    }
View Full Code Here

        // check lock-null resources
        try {
            if (isLockNull(resourcePath)) {
                int statusCode = WebdavStatus.SC_NOT_FOUND;
                sendError( statusCode, "lock-null resource", new Object[]{resourcePath} );
                throw new WebdavException( statusCode );
            }
        }
        catch (ServiceAccessException e) {
            int statusCode = getErrorCode((Exception)e);
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }

        try {
            if ( WebdavEvent.PROPPATCH.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.PROPPATCH, new WebdavEvent(this));
           
            VersioningHelper vHelp =
                VersioningHelper.getVersioningHelper(slideToken, token, req, resp, getConfig() );
            NodeRevisionDescriptors revisionDescriptors =
                content.retrieve(slideToken, resourcePath);
           
            NodeRevisionNumber revisionNumber =
                revisionDescriptors.getLatestRevision();
            NodeRevisionDescriptor revisionDescriptor = null;
            if (revisionNumber != null) {
                try {
                    revisionDescriptor = content.retrieve
                        (slideToken, revisionDescriptors);
                } catch (RevisionDescriptorNotFoundException e) {
                }
            }
           
            if (revisionDescriptor == null) {
                revisionDescriptor = new NodeRevisionDescriptor(0);
            }
           
            ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, resourcePath, revisionDescriptor);
           
            // check preconditions
            ViolatedPrecondition violatedPrecondition = getPreconditionViolation(revisionDescriptors, revisionDescriptor, resourceKind);
            if (violatedPrecondition != null) {
                throw new PreconditionViolationException(violatedPrecondition, resourcePath);
            }
           
            // Changed for DeltaV --start--
            boolean mustCheckIn = false;
            if( Configuration.useVersionControl() &&
                   (resourceKind instanceof CheckedInVersionControlled) &&
               versioningHelper.mustCheckoutAutoVersionedVCR(revisionDescriptors, revisionDescriptor) ) {
               
                vHelp.checkout(revisionDescriptors, revisionDescriptor, false, false, true );
                mustCheckIn = versioningHelper.mustCheckinAutoVersionedVCR(slideToken, revisionDescriptors, revisionDescriptor);
            }
           
            // Modifying the properties
           
            Iterator propertyIterator = null;
           
            propertyIterator = propertiesToSet.iterator();
            PropPatchProperty currentProperty = null;
            while (propertyIterator.hasNext()) {
               
                currentProperty = (PropPatchProperty)propertyIterator.next();
                if (checkPropertyModification(currentProperty, revisionDescriptor, resourceKind)) {
                    // Convert absolute URIs to relative ones, because Slide
                    // converts them to absolute ones in the result of queries.
                    String finalValue = currentProperty.getValue();
                    Element property = new Element(currentProperty.getName(), currentProperty.getNamespace());
                    String propertyValue = currentProperty.getValue();
                    if ( (propertyValue != null) && (propertyValue.toString().length() > 0)) {
                        if( propertyValue.toString().indexOf('<') >= 0 ) {
                            try {
                                XMLValue xmlValue = new XMLValue(propertyValue.toString(), Namespace.getNamespace(currentProperty.getNamespace()));
                                if (AbstractResourceKind.isLiveProperty(currentProperty.getName())) {
                                    convertHrefValueToRelativeURL (xmlValue, getSlideContextPath(), config);
                                }
                                Iterator iterator = xmlValue.iterator();
                                while (iterator.hasNext()) {
                                    Object o = iterator.next();
                                    if( o instanceof Element )
                                        property.addContent((Element)o);
                                    else if( o instanceof Text )
                                        property.addContent((Text)o);
                                    else if( o instanceof Comment )
                                        property.addContent((Comment)o);
                                    else if( o instanceof ProcessingInstruction )
                                        property.addContent((ProcessingInstruction)o);
                                    else if( o instanceof CDATA )
                                        property.addContent((CDATA)o);
                                    else if( o instanceof EntityRef )
                                        property.addContent((EntityRef)o);
                                }
                                finalValue = new XMLOutputter(Format.getRawFormat()).outputString(property.getContent());
                            }
                            catch (JDOMException e) {
                                // Fallback to original value
                            }
                        }
                    }
                    NodeProperty newProperty =
                        new NodeProperty(currentProperty.getName(),
                                         finalValue,
                                         currentProperty.getNamespace());
                    revisionDescriptor.setProperty(newProperty);
                   
                }
                else {
                    allOperationsExcecuted = false;
                }
            }
           
            propertyIterator = propertiesToRemove.iterator();
            while (propertyIterator.hasNext()) {
               
                currentProperty = (PropPatchProperty)propertyIterator.next();
                if (checkPropertyModification(currentProperty, revisionDescriptor, resourceKind)) {
                    revisionDescriptor.removeProperty(currentProperty.getName(),
                                                      currentProperty.getNamespace());
                }
                else {
                    allOperationsExcecuted = false;
                }
               
            }
           
            if (updateLastModified) {
                revisionDescriptor.setLastModified(new Date());
            }
           
            if (allOperationsExcecuted) {
                content.store(slideToken, resourcePath, revisionDescriptor, null);
            }
           
            // Changed for DeltaV --start--
            if( Configuration.useVersionControl() && mustCheckIn) {
                vHelp.checkin(revisionDescriptors, revisionDescriptor, false, false, true ); //forkOk=false, keepCheckedOut=false
            }
            // Changed for DeltaV --end--
           
            resp.setContentType(TEXT_XML_UTF_8);
           
            resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
           
        }
        catch (PreconditionViolationException e) {
            sendPreconditionViolation(e);
            throw e;
        }
        catch (Exception e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
       
       
        // No serious errors. Printing the XML report.
        writeReport();
       
        if (!allOperationsExcecuted) {
            throw new WebdavException( WebdavStatus.SC_ACCEPTED ); // abort the TA
        }
       
    }
View Full Code Here

TOP

Related Classes of org.apache.slide.webdav.WebdavException

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.