Package org.apache.slide.webdav

Examples of org.apache.slide.webdav.WebdavException


                                             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 {

            // Then we must get object contents ...

            ObjectNode object = 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) {

                    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
                    resp.setHeader("ETag", revisionDescriptor.getETag() );
                    resp.setHeader
                        ("Content-Language", revisionDescriptor.getContentLanguage());
                    resp.addHeader
                        ("Last-Modified",
                         revisionDescriptor.getLastModified().toString());

                    if ( ((ranges == null) || (ranges.isEmpty()))
                        && (req.getHeader("Range") == null) ) {

                        resp.setContentType
                            (revisionDescriptor.getContentType());
                        resp.setContentLength
                            ((int) revisionDescriptor.getContentLength());

                        // Copy the input stream to our output stream
                        // (if requested)
                        if (printContent) {
                            resp.setBufferSize(output);
                            copy(resourceInfo, is, os);
                        }

                    } else {

                        if ((ranges == null) || (ranges.isEmpty()))
                            return;

                        // 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) {
                                resp.setBufferSize(output);
                                copy(resourceInfo, is, os, range);
                            }

                        } else {

                            resp.setContentType
                                ("multipart/byteranges; boundary="
                                     + mimeSeparation);

                            if (printContent) {
                                resp.setBufferSize(output);
                                copy(resourceInfo, is, os,
                                     ranges.elements(),
                                     revisionDescriptor.getContentType());
                            }

                        }

                    }

                } else {
                    resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
                }

            } else {
                resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
            }

        } catch (Exception e) {
            int statusCode = getErrorCode( e );
            sendError( statusCode, e );
            throw new WebdavException( statusCode );
        }

    }
View Full Code Here

            // is already set.
        } catch (Exception ex) {
            token.getLogger().log(ex,LOG_CHANNEL,Logger.ERROR);
            int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
            sendError( statusCode, ex );
            throw new WebdavException( statusCode );
        } finally {
            if (transactionIsStarted && methodNeedsTransactionSupport()) {
                // Something went wrong, we are here and the TA is still open
                try {
                    token.rollback();
View Full Code Here

                }
            }
            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() );
            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();
            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("<collection/>");
       
        // 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 (!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 {
            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);
        }
       
    }
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.