Examples of AbderaClient


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

        return addComment(resourcePath, (org.wso2.carbon.registry.core.Comment) comment);
    }

    public String addComment(String resourcePath, org.wso2.carbon.registry.core.Comment comment)
            throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        Entry entry = abdera.getFactory().newEntry();
        entry.setId("tag:commentID"); // TODO - generate real ID
        entry.setTitle("Comment");
        entry.setUpdated(comment.getCreatedTime());
        entry.addAuthor(comment.getUser());
        entry.setContent(comment.getText());
        ClientResponse resp =
                abderaClient.post(baseURI + APPConstants.ATOM +
                        encodeURL(resourcePath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_COMMENTS),
                        entry,
                        getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("Adding comment for resourcePath + " + resourcePath + " succeeded." +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
            return resp.getLocation().toString().substring(baseURI.length());
        } else {
            String msg = "Adding comment for resourcePath + " + resourcePath + " 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 void editComment(String commentPath, String text) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        Entry entry = abdera.getFactory().newEntry();
        entry.setContent(text);
        ClientResponse resp = abderaClient.put(baseURI + APPConstants.ATOM +
                encodeURL(commentPath),
                entry,
                getAuthorization());

        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("Editing comment for resourcePath + " + commentPath + " succeeded." +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "Editing comment for resourcePath + " + commentPath + " 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 org.wso2.carbon.registry.core.Comment[] getComments(String resourcePath)
            throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        resourcePath = encodeURL(resourcePath);
        if (resourcePath.indexOf(";version:") > -1) {
            int index = resourcePath.lastIndexOf(";version:");
            resourcePath = resourcePath.substring(0, index).replace(":", "%3A") +
                    resourcePath.substring(index);
        } else {
            resourcePath = resourcePath.replace(":", "%3A");
        }
        ClientResponse clientResponse =
                abderaClient.get(baseURI + APPConstants.ATOM +
                        resourcePath + RegistryConstants.URL_SEPARATOR +
                        APPConstants.PARAMETER_COMMENTS,
                        getAuthorization());
        Document introspection = clientResponse.getDocument();
        Element element = introspection.getRoot();
        Feed feed = (Feed) element;
        org.wso2.carbon.registry.core.Comment[] comments = getCommentsFromFeed(feed);
        abderaClient.teardown();

        return comments;
    }
View Full Code Here

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

        }
        return comments;
    }

    public void rateResource(String resourcePath, int rating) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ByteArrayInputStream is = new ByteArrayInputStream(Integer.toString(rating).getBytes());
        ClientResponse resp = abderaClient.post(baseURI + APPConstants.ATOM +
                encodeURL(resourcePath +
                        RegistryConstants.URL_SEPARATOR +
                        APPConstants.PARAMETER_RATINGS),
                is,
                getAuthorization());
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            if (log.isDebugEnabled()) {
                log.debug("rating resource + " + resourcePath + " succeeded." +
                        ", Response Status: " + resp.getStatus() +
                        ", Response Type: " + resp.getType());
            }
            abderaClient.teardown();
        } else {
            String msg = "rating resource + " + resourcePath + " 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

            throw new RegistryException(msg);
        }
    }

    public float getAverageRating(String resourcePath) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse clientResponse =
                abderaClient.get(baseURI + APPConstants.ATOM +
                        encodeURL(resourcePath +
                                RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_RATINGS),
                        getAuthorization());

        if (clientResponse.getStatus() != 200) {
            // throw RegistryException
            String msg = "Getting average rating failed. Path: " + resourcePath +
                    ", Response Status: " + clientResponse.getStatus() +
                    ", Response Type: " + clientResponse.getType();
            abderaClient.teardown();
            log.error(msg);
            throw new RegistryException(msg);
        }

        Document introspection = clientResponse.getDocument();
        if (introspection.getRoot() instanceof Feed) {
            Feed feed = (Feed) introspection.getRoot();
            String floatValue = feed.getSimpleExtension(APPConstants.QN_AVERAGE_RATING);
            abderaClient.teardown();
            return Float.parseFloat(floatValue);
        }
        return 0;
    }
View Full Code Here

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

        }
        return 0;
    }

    public int getRating(String path, String userName) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse clientResponse =
                abderaClient.get(baseURI + APPConstants.ATOM +
                        encodeURL(path + RegistryConstants.URL_SEPARATOR +
                                APPConstants.PARAMETER_RATINGS + ":" + userName),
                        getAuthorization());
        Document introspection =
                clientResponse.getDocument();
        Entry entry = (Entry) introspection.getRoot();
        String intValue = entry.getContent();
        abderaClient.teardown();
        return Integer.parseInt(intValue);
    }
View Full Code Here

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

        abderaClient.teardown();
        return Integer.parseInt(intValue);
    }

    public Collection executeQuery(String path, Map parameters) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        RequestOptions requestOptions = getAuthorization();
        if (path == null) {
            path = "/";
        }
        ClientResponse resp = abderaClient.get(baseURI + APPConstants.ATOM +
                encodeURL(path + RegistryConstants.URL_SEPARATOR +
                        APPConstants.PARAMETER_QUERY) + "?" +
                buildQueryString(parameters),
                requestOptions);
        Document introspection = resp.getDocument();
        Feed feed = (Feed) introspection.getRoot();
        Collection c = createResourceFromFeed(feed);
        abderaClient.teardown();
        return c;
    }
View Full Code Here

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

        collection.setAuthorUserName(username);
        return collection;
    }

    public Resource get(String path) throws RegistryException {
        AbderaClient abderaClient = new AbderaClient(abdera);
        ClientResponse clientResponse;
        String encodedPath;
        // If the request is to fetch all comments for a given path, then encode ":" as well to
        // avoid confusion with versioned paths.
        if (path.endsWith(RegistryConstants.URL_SEPARATOR + APPConstants.PARAMETER_COMMENTS)) {
            encodedPath = encodeURL(path);
            if (encodedPath.indexOf(";version:") > -1) {
                int index = encodedPath.lastIndexOf(";version:");
                encodedPath = encodedPath.substring(0, index).replace(":", "%3A") +
                        encodedPath.substring(index);
            } else {
                encodedPath = encodedPath.replace(":", "%3A");
            }
        } else {
            encodedPath = encodeURL(path);
        }
        if (!cache.isResourceCached(path)) {
            clientResponse =
                    abderaClient.get(baseURI + "/atom" + encodedPath, getAuthorization());
        } else {
            clientResponse =
                    abderaClient.get(baseURI + "/atom" + encodedPath,
                            getAuthorizationForCaching(path));
        }
        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());
        }

        if (clientResponse.getStatus() == 304) {
            abderaClient.teardown();
            /*do caching here */
            log.debug(
                    "Cached resource returned since no modification has been done on the resource");
            return cache.getCachedResource(path);
        }
        String eTag = clientResponse.getHeader("ETag");
        Element introspection = clientResponse.getDocument().getRoot();
        ResourceImpl resource;
        if (introspection instanceof Feed) {
            // 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);
        } else {
            Entry entry = (Entry) introspection;
            resource = createResourceFromEntry(entry);
        }
        /* if the resource is not Get before  add it to cache before adding it check the max cache
  or if the resource is modified then new resource is replacing the current resource in the cache
   * size configured in registry.xml */
        if (!cache.cacheResource(path, resource, eTag,
                RegistryConstants.MAX_REG_CLIENT_CACHE_SIZE)) {
            log.debug("Max Cache size exceeded the configured Cache size");
        }


        abderaClient.teardown();
//        resource.setPath(path);
        return resource;
    }
View Full Code Here

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

        return notificationUrl;
    }

    public static String getAnnouncementHtml(String url) {
        Abdera abdera = new Abdera();
        AbderaClient client = new AbderaClient(abdera);
        ClientResponse resp = client.get(url);
        Feed feed;
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            Document<Feed> respDoc = resp.getDocument();
            feed = respDoc.getRoot();
        } else {
View Full Code Here

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

    private AbderaClient client;

    public APPClientHostObject() {
        super();
        abdera = new Abdera();
        client = new AbderaClient(abdera);
        options = client.getDefaultRequestOptions();
    }
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.