Package org.restlet.resource

Examples of org.restlet.resource.ClientResource


        fmc.setDefaultEncoding(CharacterSet.UTF_8.getName());

        // Generate classes
        String rootTemplates = "clap://class/org/restlet/ext/odata/internal/templates";
        Representation complexTmpl = new StringRepresentation(
                new ClientResource(rootTemplates + "/complexType.ftl").get()
                        .getText());
        Representation entityTmpl = new StringRepresentation(
                new ClientResource(rootTemplates + "/entityType.ftl").get()
                        .getText());
        Representation serviceTmpl = new StringRepresentation(
                new ClientResource(rootTemplates + "/service.ftl").get()
                        .getText());

        for (Schema schema : metadata.getSchemas()) {
            if ((schema.getEntityTypes() != null && !schema.getEntityTypes()
                    .isEmpty())
View Full Code Here


     */
    public void execute() throws Exception {
        if (!isExecuted()) {
            String targetUri = createTargetUri();

            ClientResource resource = service.createResource(new Reference(
                    targetUri));

            Metadata metadata = (Metadata) service.getMetadata();
            if (metadata == null) {
                throw new Exception(
                        "Can't execute the query without the service's metadata.");
            }

            Representation result = null;
            try {
                result = resource.get(MediaType.APPLICATION_ATOM);
            } catch (ResourceException e) {
                getLogger().warning(
                        "Can't execute the query for the following reference: "
                                + targetUri + " due to " + e.getMessage());
                throw e;
            }

            if (resource.getStatus().isSuccess()) {
                // Guess the type of query based on the URI structure
                switch (guessType(targetUri)) {
                case TYPE_ENTITY_SET:
                    FeedContentHandler<T> feedContentHandler = new FeedContentHandler<T>(
                            entityClass, entityType, metadata, getLogger());
                    setFeed(new Feed(result, feedContentHandler));
                    this.count = feedContentHandler.getCount();
                    this.entities = feedContentHandler.getEntities();
                    break;
                case TYPE_ENTITY:
                    EntryContentHandler<T> entryContentHandler = new EntryContentHandler<T>(
                            entityClass, entityType, metadata, getLogger());
                    Feed feed = new Feed();
                    feed.getEntries().add(
                            new Entry(result, entryContentHandler));
                    setFeed(feed);
                    entities = new ArrayList<T>();
                    if (entryContentHandler.getEntity() != null) {
                        entities.add(entryContentHandler.getEntity());
                    }
                    break;
                case TYPE_UNKNOWN:
                    // Guess the type of query based on the returned
                    // representation
                    Representation rep = new StringRepresentation(result
                            .getText());
                    String string = rep.getText().substring(0,
                            Math.min(100, rep.getText().length()));
                    if (string.contains("<feed")) {
                        feedContentHandler = new FeedContentHandler<T>(
                                entityClass, entityType, metadata, getLogger());
                        setFeed(new Feed(rep, feedContentHandler));
                        this.count = feedContentHandler.getCount();
                        this.entities = feedContentHandler.getEntities();
                    } else if (string.contains("<entry")) {
                        entryContentHandler = new EntryContentHandler<T>(
                                entityClass, entityType, metadata, getLogger());
                        feed = new Feed();
                        feed.getEntries().add(
                                new Entry(rep, entryContentHandler));
                        setFeed(feed);
                        entities = new ArrayList<T>();
                        if (entryContentHandler.getEntity() != null) {
                            entities.add(entryContentHandler.getEntity());
                        }
                    }
                default:
                    // Can only guess entity and entity set, a priori.
                    // TODO May we go a step further by analyzing the metadata
                    // of the data services?
                    // Do we support only those two types?
                    // Another way is to guess from the result representation.
                    // Sometimes, it returns a set, an entity, or a an XML
                    // representation of a property.
                    break;
                }
            }

            service.setLatestRequest(resource.getRequest());
            service.setLatestResponse(resource.getResponse());

            setExecuted(true);
        }
    }
View Full Code Here

            if (guessType(targetUri) == TYPE_ENTITY) {
                targetUri = targetUri.substring(0, targetUri.lastIndexOf("("));
            }
            targetUri += "/$count";

            ClientResource resource = service.createResource(new Reference(
                    targetUri));

            try {
                Representation result = resource.get();
                count = Integer.parseInt(result.getText());
            } catch (Exception e) {
                getLogger().warning(
                        "Cannot parse count value due to: " + e.getMessage());
            }
View Full Code Here

            // return true;
            // return null;
        } else {
            getLogger().info("Came back after SNS code = " + code);

            ClientResource graphResource = new ClientResource(
                    params.getBaseRef());

            ClientResource tokenResource = graphResource.getChild(params
                    .getAccessTokenPath());
            // ClientResource tokenResource = graphResource
            // .getChild("OAuth2Provider/access_token");
            Form form = new Form();
            form.add("type", "web_server");
            form.add("client_id", params.getClientId());
            // form.add("redirect_uri", redirectUri);
            // form.add("redirect_uri",
            // request.getResourceRef().getBaseRef().toUri().toString());
            String redir = request.getResourceRef().getHostIdentifier()
                    + request.getResourceRef().getPath();
            form.add("redirect_uri", redir);
            form.add("client_secret", params.getClientSecret());
            form.add("code", code);

            Representation body = tokenResource.post(form
                    .getWebRepresentation());
            if (tokenResource.getStatus().isSuccess()) {
                Form answer = new Form(body);
                getLogger().info(
                        "Got answer on AccessToken = " + answer.toString());
                accessToken = answer.getFirstValue("access_token");
                getLogger()
                        .info("AccessToken in changed OldOauthProxy = "
                                + accessToken);
                request.getClientInfo().setUser(
                        new User(accessToken, accessToken.toCharArray()));
                request.getClientInfo().setAuthenticated(true);
                auth = true;
            }
            getLogger().info("Before graph release");
            body.release();
            tokenResource.release();
            graphResource.release();
        }
        return auth;
    }
View Full Code Here

    }

    protected static ArrayList<MarketPlacePluginResume> retrieveResumes() {
        ArrayList<MarketPlacePluginResume> pluginList = new ArrayList<MarketPlacePluginResume>();
        try {
            ClientResource cr = new ClientResource(DRUPALSCHEMA + "://" + DRUPALPATH + "/rest/node?parameters[type]=plugin");
            Representation test2 = cr.get();
            String jsonData2;
            jsonData2 = test2.getText();
            Gson gson = new Gson();
            Type collectionType = new TypeToken<ArrayList<MarketPlacePluginResume>>() {
            }.getType();
View Full Code Here

        return pluginPackageList;

    }

    public static IPluginPackage retrievePluginPackage(String uri) {
        ClientResource cr = new ClientResource(uri);
        Gson gson;
        try {
            String jsonData = cr.get().getText();
            gson = new Gson();
            Type collectionType = new TypeToken<MarketPlacePlugin2>() {
            }.getType();
            return gson.fromJson(jsonData, collectionType);
        } catch (IOException ex) {
View Full Code Here

     * @param password Drupal Valid password for the previous username
     * @return String the drupal Json response
     */
    public static String login(String username, String password) {

        ClientResource cr = new ClientResource(DRUPALPATH + "/rest/user/login");
        String jsonData = "{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}";
        JsonRepresentation jsonRep = new JsonRepresentation(jsonData);
        cr.setMethod(Method.POST);
        Representation rep = cr.post(jsonRep);
        Response resp = cr.getResponse();
        if (resp.getStatus().isSuccess()) {
            try {
                return resp.getEntity().getText();

            } catch (IOException e) {
View Full Code Here

     *
     *
     * @return the nid of the created plugin, "" if it has not been created
     */
    public static String postTaxonomyGetTree(String vocabularyNumber) {
        ClientResource cr2 = new ClientResource(DRUPALPATH + "/rest/taxonomy_vocabulary/getTree");
        String text = "{\"vid\":\"" + vocabularyNumber + "\"}";

        cr2.setMethod(Method.POST);
        Representation rep2 = cr2.post(new JsonRepresentation(text));
        Response resp = cr2.getResponse();
        String jsonResponse = "";
        String nid = "";
        if (resp.getStatus().isSuccess()) {
            try {
                jsonResponse = resp.getEntity().getText();
View Full Code Here

     * representation
     */
    public static String postTaxonomySelectNodes(String taxonomyTreeNumber, int page) {
        //plugin post                
        try {
            ClientResource cr2 = new ClientResource(DRUPALPATH + "/rest/taxonomy_term/selectNodes?page=" + page);
            //String text = "{\"tids\":\""+taxonomyTreeNumber+"\",\"pager\":false}";       
            String text = "{\"tids\":\"" + taxonomyTreeNumber + "\"}";
            cr2.setMethod(Method.POST);
            JsonRepresentation jsonRepresentation = new JsonRepresentation(text);
            if (jsonRepresentation != null) {
                Representation rep2 = cr2.post(jsonRepresentation);
                Response resp = cr2.getResponse();
                String jsonResponse = "";
                String nid = "";
                if (resp.getStatus().isSuccess()) {
                    try {
                        jsonResponse = resp.getEntity().getText();
View Full Code Here

     * @param plugin Plugin to be posted on the Drupal site
     * @return the nid of the created plugin, "" if it has not been created
     */
    public static String postPlugin(CookieSetting cS, MarketPlacePlugin plugin) {
        //plugin post                
        ClientResource cr2 = new ClientResource(DRUPALPATH + "/rest/node");
        cr2.getRequest().getCookies().add(cS);
        String pluginData = plugin.toJson();
//        String pluginData = "{\"node\":"
//                + "{\"type\":\"plugin\","
//                + "\"title\":\""+plugin.getTitle()+"\","
//                + "\"language\":\"und\","
//                //+ "\"field_category\":[{\"value\":\""+plugin.getField_category()+"\"}],"
//                + "\"field_category\":{\"0\":{\"value\":\""+plugin.getField_category()+"\"}},"
//                + "\"field_plugin_category\":{\"0\":{\"value\":\"151\"}},"
//                + "\"field_developer\":{\"0\":{\"uid\":{\"uid\":\"gpulido\"}}},"
//                + "\"field_status\":[{\"value\":\""+plugin.getField_status()+"\"}],"
//                + "\"field_os\":{\"value\":{\"Linux\":\"Linux\",\"Windows\":\"Windows\"}},"
//                + "\"taxonomy\":{\"tags\":{\"2\":\"modbus gabriel\"}},"
//                + "\"field_description\":[{\"value\":\"Test of autocreated plugin.\"}],"
//                + "\"field_file\":{\"0\":{\"fid\":\"318\",\"data\":{\"description\":\"FileNameDescription\"}}},"
//                + "\"body\":{\"und\":{\"0\":{\"value\":\"This is the body of my node\"}}}"
//                + "}"
//                + "}";

        cr2.setMethod(Method.POST);

        Representation rep2 = cr2.post(new JsonRepresentation(pluginData));
        Response resp = cr2.getResponse();
        String jsonResponse = "";
        String nid = "";
        if (resp.getStatus().isSuccess()) {
            try {
                jsonResponse = resp.getEntity().getText();
View Full Code Here

TOP

Related Classes of org.restlet.resource.ClientResource

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.