Package org.apache.slide.webdav

Examples of org.apache.slide.webdav.WebdavException


        // 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 {
            reportWorker.checkPreconditions(resourcePath, getDepth());
            Element rootElm;
            if (reportWorker instanceof PrincipalSearchPropertySetReport) {
                rootElm = new Element(E_PRINCIPAL_SEARCH_PROPERTY_SET, DNSP);
                reportWorker.execute(resourcePath, rootElm, getDepth());
                resp.setStatus(WebdavStatus.SC_OK);
            }
            else {
                rootElm = new Element(E_MULTISTATUS, DNSP);
                reportWorker.execute(resourcePath, rootElm, getDepth());
                resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
            }
            new XMLOutputter(XML_REPONSE_INDENT, true).
                output(new Document(rootElm), resp.getWriter());
        }
        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


        // 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 {
            VersioningHelper vh = VersioningHelper.getVersioningHelper(
                slideToken, token, req, resp, getConfig() );
            vh.mkworkspace( resourcePath );
        }
        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);
        }
    }
View Full Code Here

       
        depth = requestHeaders.getDepth(INFINITY);
        if (depth != 0 && depth != INFINITY) {
            int sc = WebdavStatus.SC_PRECONDITION_FAILED;
            sendError( sc, "Invalid header Depth: "+depth );
            throw new WebdavException( sc );
        }
       
        lockDuration = requestHeaders.getTimeout(MAX_TIMEOUT);
       
        if (req.getContentLength() > 0) {
View Full Code Here

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

                            resp.getWriter().write(errorMessage);
                        } catch(IOException ex) {
                            // Critical error ... Servlet container is dead or something
                            int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
                            sendError( statusCode, e );
                            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.
                        resp.setStatus(WebdavStatus.SC_LOCKED);
                    }
                    //
                    // 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 (Exception e) {
                    int statusCode = getErrorCode( e );
                    sendError( statusCode, e );
                    throw new WebdavException( statusCode );
                }
               
                break;
               
            case LOCK_REFRESH:
               
                try {
                   
                    Enumeration lockTokens =
                        lock.enumerateLocks(slideToken, lockInfo_lockSubject, false);
                   
                    NodeLock currentLockToken = null;
                    Date newExpirationDate =
                        new Date((new Date()).getTime() + ((long)lockDuration * 1000L));
                    while (lockTokens.hasMoreElements()) {
                        currentLockToken = (NodeLock) lockTokens.nextElement();
                        lock.renew(slideToken, currentLockToken,
                                   newExpirationDate);
                    }
                   
                    showLockDiscoveryInfo(currentLockToken);
                   
                } catch (SlideException e) {
                    int statusCode = WebdavStatus.SC_PRECONDITION_FAILED;
                    sendError( statusCode, e );
                    throw new WebdavException( statusCode );
                }
               
                break;
               
        }
View Full Code Here

            new org.jdom.output.XMLOutputter(XML_REPONSE_INDENT, true).output(new org.jdom.Document(prop), writer);
            writer.flush();
        } catch (Exception e) {
            int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
       
       
    }
View Full Code Here

            }
        }
        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 );
        }
        catch (PreconditionViolationException e) {
            try {
                sendPreconditionViolation(e);
            } catch (IOException x) {}
            throw new WebdavException(e.getStatusCode());
        }
    }
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 {
            checkPreconditions();
            security.setPermissions(slideToken, resourcePath, permissions.elements());
        }
        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

                catch( Exception x ) {};
            }
            if( sendError ) {
                int statusCode = WebdavStatus.SC_FORBIDDEN;
                sendError( statusCode, getClass().getName()+".restrictedDestinationUri", new Object[]{resourcePath} );
                throw new WebdavException( statusCode );
            }
        }
       
        try {
           
            try {
                boolean isLockedNullResource = false;
               
                NodeRevisionDescriptors revisionDescriptors =
                    content.retrieve(slideToken, resourcePath);
               
                NodeRevisionNumber revisionNumber =
                    revisionDescriptors.getLatestRevision();
                NodeRevisionDescriptor oldRevisionDescriptor = null;
                if (revisionNumber != null) {
                    try {
                        oldRevisionDescriptor = content.retrieve
                            (slideToken, revisionDescriptors);
                    } catch (RevisionDescriptorNotFoundException e) {
                    }
                }
                if (WebdavUtils.isCollection(oldRevisionDescriptor)) {
                    int statusCode = WebdavStatus.SC_METHOD_NOT_ALLOWED;
                    sendError( statusCode, getClass().getName()+".mustNotBeCollection" );
                    throw new WebdavException( statusCode );
                }
               
                NodeRevisionDescriptor revisionDescriptor = null;
                if (oldRevisionDescriptor == null) {
                    revisionDescriptor = new NodeRevisionDescriptor();
                } else {
                    revisionDescriptor = oldRevisionDescriptor;
                    revisionDescriptor.setContentLength(-1);
                }
               
                ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, resourcePath, revisionDescriptor);
               
                versioningHelper.isWriteLocked(slideToken, revisionDescriptors);
               
                // 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) ) {
                   
                    versioningHelper.checkout(revisionDescriptors, revisionDescriptor, false, false, true );
                    mustCheckIn = versioningHelper.mustCheckinAutoVersionedVCR(slideToken, revisionDescriptors, revisionDescriptor);
                }
                // Changed for DeltaV --end--
               
                NodeRevisionContent revisionContent =
                    new NodeRevisionContent();
                //revisionContent.setContent(req.getReader());
                revisionContent.setContent(req.getInputStream());
               
                // Get content length
                revisionDescriptor.setContentLength(req.getContentLength());
               
                // Last modification date
                revisionDescriptor.setLastModified(new Date());
               
                // Etag generation
                revisionDescriptor.setETag(PropertyHelper.computeEtag(resourcePath, revisionDescriptor) );
               
                // Get content type (allow content-type to be updated here)
                String contentType = req.getContentType();
                if (contentType == null) {
                    contentType = getConfig().getServletContext()
                        .getMimeType(resourcePath);
                }
                if (contentType == null) {
                    contentType = getConfig().getDefaultMimeType();
                }
                revisionDescriptor.setContentType(contentType);
               
                // Normally assume the 'getcontentlanguage'
                // is set, however, before we clear the
                // 'resourcetype' need to check for the case when a
                // 'lock-null' is created just before the initial PUT. In
                // that case need to add the missing properties.
                if (isLockNull(revisionDescriptor)) {
                    //              if (revisionDescriptor.getResourceType().equals("<lock-null/>")) {
                    isLockedNullResource = true;
                    revisionDescriptor.setContentLanguage("en");
                   
                    // Changed for DeltaV --start--
                    if( Configuration.useVersionControl() ) {
                        // Workspace
                        versioningHelper.setWorkspaceProperty( resourcePath, revisionDescriptor );
                    }
                    // Changed for DeltaV --end--
                }
               
                // Resource type
                revisionDescriptor.setResourceType("");
               
                // Owner
                if ( isLockedNullResource ) {
                    // set the owner when updating a lock-null resource
                    String creator = ((SubjectNode)security.getPrincipal(slideToken)).getPath().lastSegment();
                    revisionDescriptor.setCreationUser(creator);
                    revisionDescriptor.setOwner(creator);
                }
               
                content.store(slideToken, resourcePath, revisionDescriptor,
                              revisionContent);
               
                // Changed for DeltaV --start--
                // check if the resource should be put under version-control
                if ( isLockedNullResource ) {
                    if ( Configuration.useVersionControl() && AUTO_VERSION_CONTROL && !isInVersioncontrolExcludePath ) {
                        versioningHelper.versionControl(resourcePath);
                    }
                }
                if( Configuration.useVersionControl() && mustCheckIn) {
                    versioningHelper.checkin(revisionDescriptors, revisionDescriptor, false, false, true ); //forkOk=false, keepCheckedOut=false
                }
                // Changed for DeltaV --end--
               
               
                // ETag header
                resp.setHeader("ETag", revisionDescriptor.getETag() );
               
                resp.setStatus(WebdavStatus.SC_NO_CONTENT);
               
            } catch (LinkedObjectNotFoundException e) {
                int statusCode = getErrorCode( e );
                sendError( statusCode, e );
                throw new WebdavException( statusCode );
            } catch (ObjectNotFoundException e) {
                SubjectNode subject = new SubjectNode();
                // Creating an object
                structure.create(slideToken, subject, resourcePath);
               
                NodeRevisionDescriptor revisionDescriptor =
                    new NodeRevisionDescriptor(req.getContentLength());
               
                //NodeProperty property = null;
               
                // Creation date
               
                // Resource type
                revisionDescriptor.setResourceType("");
               
                // Source
                revisionDescriptor.setSource("");
               
                // Get content language
                revisionDescriptor.setContentLanguage("en");
               
                // Get content length
                revisionDescriptor.setContentLength(req.getContentLength());
               
                // Get content type
                String contentType = req.getContentType();
                if (contentType == null) {
                    contentType = getConfig().getServletContext()
                        .getMimeType(resourcePath);
                }
                if (contentType == null) {
                    contentType = getConfig().getDefaultMimeType();
                }
                revisionDescriptor.setContentType(contentType);
               
                // Last modification date
                revisionDescriptor.setLastModified(new Date());
               
                // Etag generation
                revisionDescriptor.setETag(PropertyHelper.computeEtag(resourcePath, revisionDescriptor));
               
                // Creation date
                revisionDescriptor.setCreationDate(new Date());
               
                // Owner
                String creator = ((SubjectNode)security.getPrincipal(slideToken)).getPath().lastSegment();
                revisionDescriptor.setCreationUser(creator);
                revisionDescriptor.setOwner(creator);
               
                // Added for DeltaV --start--
                if( Configuration.useVersionControl() ) {
                    // Workspace
                    versioningHelper.setWorkspaceProperty( resourcePath, revisionDescriptor );
                }
                // Added for DeltaV --end--
               
                if (isMsProprietarySupport()) {
                    NodeProperty property = null;
                    // Is hidden
                    property = new NodeProperty("ishidden", "0", "MICROSOFT");
                    revisionDescriptor.setProperty(property);
                   
                    // Is collection
                    property = new NodeProperty("iscollection", "0",
                                                "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);
                   
                }
               
                // Creating revisionDescriptor associated with the object
                NodeRevisionContent revisionContent =
                    new NodeRevisionContent();
                revisionContent.setContent(req.getInputStream());
               
                content.create(slideToken, resourcePath, revisionDescriptor,
                               revisionContent);
               
                // check if the resource should be put under version-control
                if ( Configuration.useVersionControl() && AUTO_VERSION_CONTROL && !isInVersioncontrolExcludePath ) {
                    versioningHelper.versionControl(resourcePath);
                }
               
                // ETag header
                resp.setHeader("ETag", revisionDescriptor.getETag() );
               
                resp.setStatus(WebdavStatus.SC_CREATED);
               
            }
        }
        catch (PreconditionViolationException e) {
            sendPreconditionViolation(e);
            throw e;
        }
        catch (SlideException e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
        catch (Exception e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
    }
View Full Code Here

        }

        if( req.getContentLength() == 0 ) {
            int statusCode = WebdavStatus.SC_BAD_REQUEST;
            sendError( statusCode, getClass().getName()+".missingRequestBody" );
            throw new WebdavException( statusCode );
        }

        try{
            parseUpdateRequestContent();
        }
        catch (JDOMException  e){
            int statusCode = WebdavStatus.SC_BAD_REQUEST;
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
        catch (PropertyParseException  e){
            int statusCode = WebdavStatus.SC_BAD_REQUEST;
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
        catch( IOException e ){
            int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
    }
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.