Package org.apache.slide.webdav

Examples of org.apache.slide.webdav.WebdavException


                output(new Document(multistatus), writer);
            writer.flush();
        } catch (Exception e) {
            int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
       
    }
View Full Code Here


            segment = MethodUtil.getChildText(content, E_SEGMENT);
        }
        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((Exception)e);
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }

        try {
            if ( WebdavEvent.UNBIND.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.UNBIND, new WebdavEvent(this));

            checkPreconditions();
            structure.removeBinding( slideToken, collectionNode, segment );
        }
        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_PROTECTED_URL_DELETION_ALLOWED, WebdavStatus.SC_CONFLICT);
            }
            sendPreconditionViolation(
                new PreconditionViolationException(violatedPrecondition, 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

        destinationUri = requestHeaders.getDestination();

        if (destinationUri == null) {
            int statusCode = WebdavStatus.SC_BAD_REQUEST;
            sendError( statusCode, getClass().getName()+".missingDestinationHeader" );
            throw new WebdavException( statusCode );
        }

        destinationUri = parseUri(destinationUri);
        overwrite = requestHeaders.getOverwrite(true);
    }
View Full Code Here

                                             WebdavStatus.SC_CONFLICT);
                try {
                    sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
                                                                                 resourcePath));
                } catch (IOException ioe) {}
                throw new WebdavException(getErrorCode((Exception)e));
            }
            catch (SlideException e) {
                int statusCode = getErrorCode( e );
                sendError( statusCode, e );
                throw new WebdavException( statusCode );
            }
        }


        if( req.getContentLength() > 0 ) {
//            readRequestContent();
            try{
                Iterator i = parseRequestContent(E_CHECKOUT).getChildren().iterator();
                while( i.hasNext() ) {
                    Element e = (Element)i.next();
                    if ( e.getName().equals(E_APPLY_TO_VERSION) ) {

                        String labelHeader = WebdavUtils.fixTomcatHeader(requestHeaders.getLabel(), "UTF-8");

                        if (labelHeader != null) {
                            ViolatedPrecondition violatedPrecondition =
                                new ViolatedPrecondition(DeltavConstants.C_MUST_NOT_HAVE_LABEL_AND_APPLY_TO_VERSION,
                                                         WebdavStatus.SC_CONFLICT);
                            sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
                                                                                         resourcePath));
                            throw new WebdavException(WebdavStatus.SC_CONFLICT);
                        }
                        applyToVersion = true;
                    }
                    if ( e.getName().equals(E_FORK_OK) ) {
                        forkOk = true;
                    }
                }
            }
            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 {
            if ( WebdavEvent.CHECKOUT.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.CHECKOUT, new WebdavEvent(this));

            locationValue = versioningHelper.checkout( resourcePath, forkOk, applyToVersion );
        }
        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

                                             WebdavStatus.SC_CONFLICT);
                try {
                    sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
                                                                                 resourcePath));
                } catch (IOException ioe) {}
                throw new WebdavException( WebdavStatus.SC_CONFLICT );
            }
            catch (SlideException e) {
                int statusCode = getErrorCode( (Exception)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 {
            // fire put event
            if ( WebdavEvent.GET.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.GET, new WebdavEvent(this));

            // Then we must get object contents ...

            structure.retrieve(slideToken, resourcePath);
            NodeRevisionDescriptors revisionDescriptors =
                content.retrieve(slideToken, resourcePath);

            if (revisionDescriptors.hasRevisions()) {

                // Retrieve latest revision descriptor
                NodeRevisionDescriptor revisionDescriptor =
                    content.retrieve(slideToken, revisionDescriptors);

                if (revisionDescriptor != null) {

                    if (revisionDescriptor.propertyValueContains(
                            NodeRevisionDescriptor.RESOURCE_TYPE,
                            NodeRevisionDescriptor.COLLECTION_TYPE)) {
                        displayDirectory();
                    } else {
                   
                        ResourceInfo resourceInfo =
                            new ResourceInfo(resourcePath, revisionDescriptor);
   
                        // Checking If headers
                        if (!checkIfHeaders(req, resp, resourceInfo))
                            return;
   
                        ServletOutputStream os = resp.getOutputStream();
                        InputStream         is = null;
   
                        if (printContent) {
                            is = content.retrieve
                                (slideToken, revisionDescriptors,
                                 revisionDescriptor).streamContent();
                        }
   
                        Vector ranges = parseRange(req, resp, resourceInfo);
   
                        // ETag header (tag must be quoted)
                        resp.setHeader("ETag", getETag(resourceInfo, true) );
                        resp.setHeader
                            ("Content-Language", revisionDescriptor.getContentLanguage());
                        resp.addHeader
                            ("Last-Modified",
                             revisionDescriptor.getLastModified().toString());
   
                        // do this before setting content length, as Tomcat 5 seems to be picky
                        // about this
                        resp.setBufferSize(output);

                        if ( ((ranges == null) || (ranges.isEmpty())) ) {
                            // full content response
                            resp.setContentType
                                (revisionDescriptor.getContentType());
                            resp.setContentLength
                                ((int) revisionDescriptor.getContentLength());
   
                            // Copy the input stream to our output stream
                            // (if requested)
                            if (printContent) {
                                copy(resourceInfo, is, os);
                            }
   
                        } else {
                            // Partial content response.
   
                            resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
   
                            if (ranges.size() == 1) {
   
                                Range range = (Range) ranges.elementAt(0);
                                resp.addHeader("Content-Range", "bytes "
                                                   + range.start
                                                   + "-" + range.end + "/"
                                                   + range.fileLength);
                                resp.setContentLength((int) range.length);
                                resp.setContentType
                                    (revisionDescriptor.getContentType());
   
                                if (printContent) {
                                    copy(resourceInfo, is, os, range);
                                }
   
                            } else {
   
                                resp.setContentType
                                    ("multipart/byteranges; boundary="
                                         + mimeSeparation);
   
                                if (printContent) {
                                    copy(resourceInfo, is, os,
                                         ranges.elements(),
                                         revisionDescriptor.getContentType());
                                }
                            }
                        }
                    }
                } else {
                    // XXX if there is no revision descriptor, this should be a directory
                    displayDirectory();
                    // resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
                }
            } else {
                // XXX if there is no revisions, this should be a directory
                displayDirectory();
                // resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
            }
        } catch (Exception e) {
            int statusCode;
            // XXX If there is some sort of IOException it has been issued by the copy methods
            // which indicates the client aborted the connection
            // like org.apache.catalina.connector.ClientAbortException thrown by Tomcat
            if (e instanceof IOException) {
                // XXX like in WebdavUtils which reacts on a failure upon put, we use this return method,
                // however, is it sensible?
                statusCode = WebdavStatus.SC_PRECONDITION_FAILED;
            } else {
                statusCode = getErrorCode( e );
            }
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }
    }
View Full Code Here

        // bytes is the only range unit supported (and I don't see the point
        // of adding new ones).
        if (!rangeHeader.startsWith("bytes")) {
            response.sendError
                (HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
            throw new WebdavException(
                     HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
        }
        rangeHeader = rangeHeader.substring(6);


        // Vector which will contain all the ranges which are successfully
        // parsed.
        Vector result = new Vector();
        StringTokenizer commaTokenizer = new StringTokenizer(rangeHeader, ",");

        // Parsing the range list
        while (commaTokenizer.hasMoreTokens()) {
            String rangeDefinition = commaTokenizer.nextToken();

            Range currentRange = new Range();
            currentRange.fileLength = fileLength;

            int dashPos = rangeDefinition.indexOf('-');

            if (dashPos == -1) {
                response.sendError
                    (HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                throw new WebdavException(
                         HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
            }

            if (dashPos == 0) {

                try {
                    long offset = Long.parseLong(rangeDefinition);
                    currentRange.start = fileLength + offset;
                    currentRange.end = fileLength - 1;
                } catch (NumberFormatException e) {
                    response.sendError(
                        HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                    throw new WebdavException(
                         HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                }

            } else {

                try {
                    currentRange.start = Long.parseLong
                        (rangeDefinition.substring(0, dashPos));
                    if (dashPos < rangeDefinition.length() - 1)
                        currentRange.end = Long.parseLong
                            (rangeDefinition.substring
                                 (dashPos + 1, rangeDefinition.length()));
                    else
                        currentRange.end = fileLength - 1;
                } catch (NumberFormatException e) {
                    response.sendError(
                      HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                    throw new WebdavException(
                       HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                }

            }

            currentRange.length = (currentRange.end - currentRange.start + 1);
            if (!currentRange.validate()) {
                response.sendError
                    (HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                throw new WebdavException(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
            }

            result.addElement(currentRange);
        }
View Full Code Here

            }
            resp.setStatus(WebdavStatus.SC_OK);
        } catch (Exception e) {
            int statusCode = getErrorCode( (Exception)e );
            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.