Package org.apache.abdera.protocol.server.context

Examples of org.apache.abdera.protocol.server.context.ResponseContextException


  public InputStream getMediaStream(Node entry) throws ResponseContextException {
    try {
      Value value = getValueOrNull(entry, MEDIA);
      return (value != null) ? value.getStream() : null;
    } catch (RepositoryException e) {
      throw new ResponseContextException(500, e);
    }
   
  }
View Full Code Here


        String path = resource.getPath();
        final Registry registry;
        try {
            registry = getSecureRegistry(request);
        } catch (RegistryException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }

        final String[] splitPath = (String[]) request.getAttribute(RequestContext.Scope.REQUEST,
                "splitPath");
        final String text = content.getText();
        if (splitPath != null) {
            if ("comments".equals(splitPath[1])) {
                // Comment post
                org.wso2.carbon.registry.core.Comment comment =
                        new org.wso2.carbon.registry.core.Comment(text);
                try {
                    registry.editComment(path, text);
                    String commentPath = registry.addComment(path, comment);
                    comment.setPath(commentPath);
                } catch (RegistryException e) {
                    throw new ResponseContextException(new StackTraceResponseContext(e));
                }
                return comment;
            }
        }

        String name = request.getSlug();
        if (name == null) {
            if (title != null) {
                // Following code replaces spaces with "_". Commenting out Sanitizer.sanitize and
                // doing the same thing other
                // replacing spaces with "_".
                // slug = Sanitizer.sanitize(slug, "-", sanitizePattern);
                name = title.replaceAll(sanitizePattern, "-");
            } else {
                name = generateResourceName();
            }
        } else {
            // name = Sanitizer.sanitize(name, "-", sanitizePattern);
        }

        if (!path.endsWith("/")) {
            path += "/";
        }

        if (APPConstants.IMPORT_MEDIA_TYPE.equals(request.getContentType().toString())) {
            // This is an import.
            String importURL = request.getParameter("importURL");
            String suggestedPath = request.getSlug();
            String location;
            try {
                final Registry secureRegistry = getSecureRegistry(request);
                location = secureRegistry.importResource(suggestedPath,
                        importURL,
                        new ResourceImpl());
                return secureRegistry.get(location);
            } catch (RegistryException e) {
                throw new ResponseContextException(new StackTraceResponseContext(e));
            }
        }

        Entry entry;
        try {
            entry = (Entry) request.getDocument().getRoot();
        } catch (IOException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }

        Resource ret;
        try {
            ret = registry.newResource();
            fillResourceFromEntry(entry, ret);


            registry.put(path + name, ret);
        } catch (Exception e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }
        ((ResourceImpl) ret).setPath(path + name);
        return ret;
    }
View Full Code Here

        // If this isn't atom, it's a media entry
        Object content;
        try {
            content = entry.getContent();
        } catch (RegistryException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }
        return (!MimeTypeHelper.isAtom(entry.getMediaType()) && !(content instanceof Number) &&
                !(content instanceof String));
    }
View Full Code Here

        if (resource instanceof Collection) {
            try {
                feed.addSimpleExtension(APPConstants.QN_CHILD_COUNT,
                        "" + ((Collection) resource).getChildCount());
            } catch (RegistryException e) {
                throw new ResponseContextException(new StackTraceResponseContext(e));
            }
        }
        if (resource.getCreatedTime() != null) {
            feed.addSimpleExtension(new QName(APPConstants.NAMESPACE, "createdTime"),
                    String.valueOf(resource.getCreatedTime().getTime()));
View Full Code Here

                try {
                    resource = getSecureRegistry(request).get(resource.getPath() +
                            RegistryConstants.URL_SEPARATOR +
                            "comments");
                } catch (RegistryException e) {
                    throw new ResponseContextException(new StackTraceResponseContext(e));
                }
            }
        }

        if (resource instanceof Collection) {
View Full Code Here

                              RequestContext request) throws ResponseContextException {
        final Registry registry;
        try {
            registry = getSecureRegistry(request);
        } catch (RegistryException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }

        String path = ((ResourceTarget) request.getTarget()).getResource().getPath();

        final String[] splitPath = (String[]) request.getAttribute(RequestContext.Scope.REQUEST,
                "splitPath");
        if (splitPath != null) {
            if ("comments".equals(splitPath[1])) {
                if (!mimeType.toString().equals("text/plain")) {
                    throw new ResponseContextException(
                            "Can only post Atom or text/plain to comments!", 400);
                }
                // Comment post
                org.wso2.carbon.registry.core.Comment comment;
                try {
                    comment = new org.wso2.carbon.registry.core.Comment(readToString(inputStream));
                } catch (IOException e) {
                    throw new ResponseContextException(new StackTraceResponseContext(e));
                }
                try {
                    String commentPath = registry.addComment(path, comment);
                    comment.setPath(commentPath);
                    comment.setParentPath(path + RegistryConstants.URL_SEPARATOR + "comments");
                } catch (RegistryException e) {
                    throw new ResponseContextException(new StackTraceResponseContext(e));
                }
                return comment;
            }
        }

        if (!path.endsWith("/")) {
            path += "/";
        }
        slug = getGoodSlug(path, slug, request);
        path = path + slug;
        boolean isCollection = "app/collection".equals(mimeType.toString());
        Resource ret;
        try {
            ret = isCollection ? registry.newCollection() : registry.newResource();
        } catch (RegistryException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }
        ret.setMediaType(mimeType.toString());

        try {

            if (!isCollection) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                try {
                    while (inputStream.available() > 0) {
                        int amount = inputStream.read(buffer, 0, 1024);
                        bos.write(buffer, 0, amount);
                    }
                } catch (IOException e) {
                    // nothing here
                }
                String content = new String(bos.toByteArray());
                ret.setContent(content);
            }

            registry.put(path, ret);
        } catch (RegistryException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }
        return ret;
    }
View Full Code Here

     */
    public InputStream getMediaStream(Resource entry) throws ResponseContextException {
        try {
            return new ByteArrayInputStream((byte[]) entry.getContent());
        } catch (RegistryException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }
    }
View Full Code Here

    private Integer getIdFromResourceName(String resourceName) throws ResponseContextException
    {
        int idx = resourceName.indexOf("-");
        if (idx == -1)
        {
            throw new ResponseContextException(404);
        }
        Integer id = new Integer(resourceName.substring(0, idx));
        return id;
    }
View Full Code Here

    }

    private Integer getIdFromResourceName(String resourceName) throws ResponseContextException {
        int idx = resourceName.indexOf("-");
        if (idx == -1) {
            throw new ResponseContextException(404);
        }
        Integer id = new Integer(resourceName.substring(0, idx));
        return id;
    }
View Full Code Here

            transactionStart(transaction, request);
            response = processor.process(request, wm, adapter);
            response = response != null ? response : processExtensionRequest(request, adapter);
        } catch (Throwable e) {
            if (e instanceof ResponseContextException) {
                ResponseContextException rce = (ResponseContextException)e;
                if (rce.getStatusCode() >= 400 && rce.getStatusCode() < 500) {
                    // don't report routine 4xx HTTP errors
                    log.info(e);
                } else {
                    log.error(e);
                }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.server.context.ResponseContextException

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.