Examples of AbderaClient


Examples of org.apache.abdera.protocol.client.AbderaClient

            throws RegistryException {
        throw new UnsupportedOperationException();
    }

    public void removeComment(String commentPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        String resourcePath = commentPath.substring(0, commentPath.indexOf(";comments:"));
        int commentId = Integer.parseInt(
                commentPath.substring(commentPath.indexOf(";comments:") + ";comments:".length()));
        ClientResponse resp = abderaClient.delete(baseURI + APPConstants.ATOM +
                encodeURL(resourcePath +
                        RegistryConstants.URL_SEPARATOR) +
                        "comment:" + commentId,
                getAuthorization());

        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("Removing comment: " + commentId + " for resourcePath + " + resourcePath +
                        " succeeded." + ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "Removing comment: " + commentId + " for resourcePath + " + resourcePath +
                        " succeeded." + ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }

    }
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

            throws org.wso2.carbon.registry.api.RegistryException {
        return importResource(suggestedPath, sourceURL, (Resource) resource);
    }

    public Collection get(String path, int start, int pageSize) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse clientResponse =
                abderaClient.get(baseURI + "/atom" + encodeURL(path) +
                        "?start=" + start + "&pageLen=" + pageSize, getAuthorization());
        if (clientResponse.getType() == Response.ResponseType.CLIENT_ERROR ||
                clientResponse.getType() == Response.ResponseType.SERVER_ERROR) {
            if (clientResponse.getStatus() == 404) {
                abderaClient.teardown();
                throw new ResourceNotFoundException(path);
            }
            abderaClient.teardown();
            throw new RegistryException(clientResponse.getStatusText());
        }
        Element introspection = clientResponse.getDocument().getRoot();
        if (!(introspection instanceof Feed)) {
            abderaClient.teardown();
            throw new RegistryException("Got " + introspection.getQName() +
                    " when expecting <feed>!");
        }
        CollectionImpl resource;
        // This is a collection
        Feed feed = (Feed) introspection;
        String state = feed.getSimpleExtension(new QName(APPConstants.NAMESPACE, "state"));
        if (state != null && state.equals("Deleted")) {
            abderaClient.teardown();
            throw new ResourceNotFoundException(path);
        }
        resource = createResourceFromFeed(feed);
        abderaClient.teardown();
        return resource;
    }
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

        resource.setContent(content1);
        return resource;
    }

    public boolean resourceExists(String path) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse response = abderaClient.head(baseURI + APPConstants.ATOM + encodeURL(path),
                getAuthorization());
        boolean exists = (response.getType() == Response.ResponseType.SUCCESS);
        abderaClient.teardown();
        return exists;
    }
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

        String parentPath = idx > 1 ? suggestedPath.substring(0, idx) : "/";

        // Does the resource already exist?  If so this is an update (PUT) not a create (POST)
        boolean alreadyExists = resourceExists(suggestedPath);

        AbderaClient abderaClient = new AbderaClient(abdera);
        final Factory factory = abdera.getFactory();
        boolean isCollection = resource instanceof Collection;

        ExtensibleElement element;
        if (isCollection) {
            Feed feed = factory.newFeed();
            feed.setId(baseURI + APPConstants.ATOM + encodeURL(suggestedPath));
//            feed.setId(encodeURL(suggestedPath));
            feed.setTitle(suggestedPath);
            feed.setSubtitle(resource.getDescription());
            feed.addAuthor(username);
            feed.setUpdated(new Date());
            element = feed;
        } else {
            Entry entry = factory.newEntry();
            entry.setId(baseURI + APPConstants.ATOM + encodeURL(suggestedPath));
//            entry.setId(encodeURL(suggestedPath));
            entry.setTitle(suggestedPath);
            entry.setSummary(resource.getDescription());
            entry.addAuthor(username);
            entry.setUpdated(new Date());
            Object content = resource.getContent();
            if (content != null && content instanceof byte[]) {
                ByteArrayInputStream in = new ByteArrayInputStream((byte[]) content);
                entry.setContent(in);
            } else if (content instanceof InputStream) {
                entry.setContent((InputStream) content);
            } else {
                entry.setContent((String) content);
            }
            element = entry;
        }
        java.util.Properties properties = resource.getProperties();
        addPropertyExtensionElement(properties, factory, element,
                PropertyExtensionFactory.PROPERTIES,
                PropertyExtensionFactory.PROPERTY);
        final String mediaType = resource.getMediaType();
        if (mediaType != null && mediaType.length() > 0) {
            element.addSimpleExtension(new QName(APPConstants.NAMESPACE, "mediaType"), mediaType);
        }
        element.addSimpleExtension(new QName(APPConstants.NAMESPACE, "parentPath"),
                resource.getParentPath());
        if (((ResourceImpl) resource).isContentModified()) {
            element.addSimpleExtension(new QName(APPConstants.NAMESPACE, "contentModified"),
                    "true");
        }

        RequestOptions requestOptions = getAuthorization();
        requestOptions.setSlug(relativePath);

        ClientResponse resp;
        if (!alreadyExists) {
            resp = abderaClient.post(baseURI + APPConstants.ATOM + encodeURL(parentPath),
                    element, requestOptions);
        } else {
            resp = abderaClient.put(baseURI + APPConstants.ATOM + encodeURL(suggestedPath),
                    element, requestOptions);
        }
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
//                log.debug(Messages.getMessage("resource.add", suggestedPath));
            }
        } else if (resp.getStatus() == 401) {
            abderaClient.teardown();
            String msg = "User is not authorized to add the resource to " + suggestedPath;
            log.error(msg);
            throw new RegistryException(msg);
        } else {
            String msg = "Add resource fail. Suggested Path: " + suggestedPath +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
//        ResourceImpl impl = (ResourceImpl)resource;
//        impl.setPath(resultPath);
//        // todo - fix this to use util routine?
//        int i = resultPath.lastIndexOf('/');
//        impl.setParentPath(i == 0 ? "/" : resultPath.substring(0, i));
        abderaClient.teardown();
        return suggestedPath;
    }
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

        if (Pattern.matches("\\p{Alnum}*[~!@#$%^&*()\\+=\\-;<>\\s?\\[\\]{},/\\\\\"\',]+\\p{Alnum}*",
                relativePath)) {
            throw new RegistryException("Invalid characters have been used in the resource name.");
        }
        AbderaClient abderaClient = new AbderaClient(abdera);
        final Factory factory = abdera.getFactory();
        Entry entry = factory.newEntry();
        entry.setId(baseURI + APPConstants.ATOM + encodeURL(suggestedPath));
        entry.setTitle(suggestedPath);
        entry.setSummary(resource.getDescription());
        entry.addAuthor(username);
        entry.setUpdated(new Date());
        java.util.Properties properties = resource.getProperties();
        addPropertyExtensionElement(properties, factory, entry,
                PropertyExtensionFactory.PROPERTIES,
                PropertyExtensionFactory.PROPERTY);
        final String mediaType = resource.getMediaType();
        if (mediaType != null && mediaType.length() > 0) {
            entry.addSimpleExtension(new QName(APPConstants.NAMESPACE, "mediaType"), mediaType);
        }
        entry.addSimpleExtension(new QName(APPConstants.NAMESPACE, "parentPath"), resource.getParentPath());
        if (((ResourceImpl) resource).isContentModified()) {
            entry.addSimpleExtension(new QName(APPConstants.NAMESPACE, "contentModified"), "true");
        }
        RequestOptions opts = getAuthorization();
        opts.setSlug(suggestedPath);
        opts.setContentType(resource.getMediaType());
        ClientResponse response =
                abderaClient.post(baseURI + APPConstants.ATOM + "?importURL=" +
                        encodeURL(sourceURL + RegistryConstants.URL_SEPARATOR +
                                APPConstants.IMPORT_MEDIA_TYPE),
                        entry,
                        opts);
        if (response.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource at " + sourceURL + " imported." +
                        ", Response Status: " + response.getStatus() +
                        ", Response Type: " + response.getType());
            }
            abderaClient.teardown();
            return response.getLocation().toString();
        } else {
            String msg = "failed to import resource at " + sourceURL + "." +
                    ", Response Status: " + response.getStatus() +
                    ", Response Type: " + response.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
    }
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

            throw new RegistryException(msg);
        }
    }

    public void delete(String path) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse resp = abderaClient.delete(baseURI + APPConstants.ATOM + encodeURL(path),
                getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource at " + path + " deleted" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource at " + path + " delete failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
    }
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

        }
    }


    public String rename(String currentPath, String newPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream(newPath.getBytes());
        ClientResponse resp =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(currentPath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_RENAME),
                        is,
                        getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource rename " + currentPath + " to " + newPath + "  succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource rename from " + currentPath + " to " + newPath + " failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
        return newPath;
    }
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

        }
        return newPath;
    }

    public String move(String currentPath, String newPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream(newPath.getBytes());
        ClientResponse resp =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(currentPath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_MOVE),
                        is,
                        getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource move  from " + currentPath + " to " + newPath + " succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource move from " + currentPath + " to " + newPath + " failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
        // TODO - should pull real result path from the server response.
        return newPath;
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

        // TODO - should pull real result path from the server response.
        return newPath;
    }

    public String copy(String sourcePath, String targetPath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream(targetPath.getBytes());
        ClientResponse resp =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(sourcePath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_COPY),
                        is,
                        getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("resource copy from " + sourcePath + " to " + targetPath + " succeeded" +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "resource copy from " + sourcePath + " to " + targetPath + "  failed" +
                    ", Response Status: " + resp.getStatus() +
                    ", Response Type: " + resp.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }
        // TODO - should pull real result path from the server response.
        return targetPath;
View Full Code Here

Examples of org.apache.abdera.protocol.client.AbderaClient

        // TODO - should pull real result path from the server response.
        return targetPath;
    }

    public void createVersion(String path) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream("createVersion".getBytes());
        ClientResponse clientResponse =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(path + RegistryConstants.URL_SEPARATOR +
                                APPConstants.CHECKPOINT),
                        is,
                        getAuthorization());
        final int status = clientResponse.getStatus();
        if (status < 200 || status > 299) {
            RegistryException e;
            if (status == 404) {
                e = new ResourceNotFoundException(path);
            } else {
                e = new RegistryException("Response Status: " + clientResponse.getStatusText());
            }
            abderaClient.teardown();
            throw e;
        }
        abderaClient.teardown();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.