Package org.restlet.resource

Examples of org.restlet.resource.ClientResource


            Reference meRef = new Reference("me");
            meRef.addQueryParameter(OAuthServerResource.ACCESS_TOKEN,
                    accessToken);

            ClientResource graphResource = new ClientResource(FB_GRAPH);
            ClientResource meResource = graphResource.getChild(meRef);
            JsonRepresentation meRepr = meResource
                    .get(JsonRepresentation.class);
            if (meResource.getResponse().getStatus().isSuccess()) {
                JSONObject me;
                try {
                    me = meRepr.getJsonObject();
                    String id = me.get("id").toString();
                    log.info("Your ID = " + id);
                    accessTokens.put(id, accessToken);
                    // TODO Set Cookie
                    return true;
                } catch (JSONException e) {
                    log.log(Level.WARNING, "Failed in parsing the me object.",
                            e);
                }
            }
            meRepr.release();
            meResource.release();
            graphResource.release();
        }

        return false;
    }
View Full Code Here


     * @return A Properties instance loaded from the given URI.
     * @throws IOException
     */
    public static Properties getProperties(String propertiesUri)
            throws IOException {
        ClientResource resource = new ClientResource(propertiesUri);
        try {
            resource.get();
        } catch (Exception e) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Cannot access to the configuration file: \"");
            stringBuilder.append(propertiesUri);
            stringBuilder.append("\"");
            throw new IllegalArgumentException(stringBuilder.toString());
        }

        Properties properties = new Properties();
        properties.load(resource.getResponseEntity().getStream());
        return properties;
    }
View Full Code Here

* @author Jerome Louvel
*/
public class Part09b {
    public static void main(String[] args) throws Exception {
        // Prepare the request
        ClientResource resource = new ClientResource("http://localhost:8111/");

        // Add the client authentication to the call
        ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
        ChallengeResponse authentication = new ChallengeResponse(scheme,
                "scott", "tiger");
        resource.setChallengeResponse(authentication);

        // Send the HTTP GET request
        resource.get();

        if (resource.getStatus().isSuccess()) {
            // Output the response entity on the JVM console
            resource.getResponseEntity().write(System.out);
        } else if (resource.getStatus()
                .equals(Status.CLIENT_ERROR_UNAUTHORIZED)) {
            // Unauthorized access
            System.out
                    .println("Access authorized by the server, check your credentials");
        } else {
            // Unexpected status
            System.out.println("An unexpected status was returned: "
                    + resource.getStatus());
        }
    }
View Full Code Here

* @author Jerome Louvel
*/
public class Part02b {
    public static void main(String[] args) throws Exception {
        // Create the client resource
        ClientResource resource = new ClientResource("http://www.restlet.org");

        // Customize the referrer property
        resource.setReferrerRef("http://www.mysite.org");

        // Write the response entity on the console
        resource.get().write(System.out);
    }
View Full Code Here

public class FirstResourceClientMain {

    public static void main(String[] args) throws IOException,
            ResourceException {
        // Define our Restlet client resources.
        ClientResource itemsResource = new ClientResource(
                "http://localhost:8111/firstResource/items");
        ClientResource itemResource = null;

        // Create a new item
        Item item = new Item("item1", "this is an item.");
        try {
            Representation r = itemsResource.post(getRepresentation(item));
            itemResource = new ClientResource(r.getLocationRef());
        } catch (ResourceException e) {
            System.out.println("Error  status: " + e.getStatus());
            System.out.println("Error message: " + e.getMessage());
        }
        // Consume the response's entity which releases the connection
        itemsResource.getResponseEntity().exhaust();

        if (itemResource != null) {
            // Prints the representation of the newly created resource.
            get(itemResource);

            // Prints the list of registered items.
            get(itemsResource);

            // Update the item
            item.setDescription("This is an other description");
            itemResource.put(getRepresentation(item));

            // Prints the list of registered items.
            get(itemsResource);

            // delete the item
            itemResource.delete();

            // Print the list of registered items.
            get(itemsResource);
        }
    }
View Full Code Here

                            final String echoMessage = ECHO_TEST_MSG;
                            final Reference echoRef = new LocalReference(
                                    selfBase + "/echo/" + echoMessage);
                            String echoCopy = null;
                            try {
                                ClientResource r = new ClientResource(echoRef);
                                echoCopy = r.get().getText();
                            } catch (Exception e) {
                                e.printStackTrace();
                                fail("Error getting internal reference to "
                                        + echoRef);
                            }
View Full Code Here

    private MediaType type;

    public StaticHtmlPage(String uri) {
        Reference ref = new Reference(uri);
        // TODO could check that it is CLAP and ends .html
        ClientResource local = new ClientResource(ref);
        Representation tmpPage = local.get();
        try {
            page = tmpPage.getText();
        } catch (IOException e) {
            page = e.getLocalizedMessage();
        }
        type = tmpPage.getMediaType();
        tmpPage.release();
        local.release();
    }
View Full Code Here

* @author Jerome Louvel
*/
public class Part02a {
    public static void main(String[] args) throws Exception {
        // Outputting the content of a Web page
        new ClientResource("http://www.restlet.org").get().write(System.out);
    }
View Full Code Here

                    }

                });
                router.attach("/testB", new Restlet(getContext()) {
                    public void handle(Request request, Response response) {
                        ClientResource resource = new ClientResource(
                                "riap://component/app/testA");
                        try {
                            response.setEntity(resource.get().getText(),
                                    MediaType.TEXT_PLAIN);
                        } catch (Exception e) {
                        }
                    }

                });
                return router;
            }
        };

        // Attach the private application
        component.getInternalRouter().attach("/app", app);

        try {
            component.start();

            ClientResource res = new ClientResource(
                    "riap://component/app/testA");
            Representation rep = res.get();
            assertEquals("hello, world", rep.getText());

            rep = null;
            res = new ClientResource("riap://component/app/testB");
            rep = res.get();
            assertEquals("hello, world", rep.getText());

            component.stop();
        } catch (Exception e) {
            fail(e.getMessage());
View Full Code Here

        server.getContext().getParameters().add("directBuffers", "false");
        server.getContext().getParameters().add("workerThreads", "true");
        server.getContext().getParameters().add("pooledConnections", "true");
        server.getContext().getParameters().add("maxIoIdleTimeMs", "3000000");

        final ClientResource fr = new ClientResource(
                "file://C/TEST/restlet-jse-2.0.5-ff.zip");

        // server.setNext(HelloServerResource.class);
        server.setNext(new Restlet() {
            @Override
            public void handle(Request request, Response response) {
                fr.put(request.getEntity());

                // try {
                // response.setEntity(new InputRepresentation(
                // new FileInputStream("C://TEST/contacts2.txt")));
                // } catch (FileNotFoundException e) {
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.