Package org.restlet.resource

Examples of org.restlet.resource.ClientResource


            System.err.println("You need to pass a term to search");
        } else {
            // Fetch a resource: a JSON document full of search results
            String term = Reference.encode(args[0]);
            String uri = BASE_URI + "?appid=restbook&output=json&query=" + term;
            Representation entity = new ClientResource(uri).get();
            JSONObject json = new JsonRepresentation(entity).getJsonObject();

            // Navigate within the JSON document to display the titles
            JSONObject resultSet = json.getJSONObject("ResultSet");
            JSONArray results = resultSet.getJSONArray("Result");
View Full Code Here


            cr.setParameters(parameters);
            resp.getChallengeRequests().add(cr);
            resp.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        } else {
            getLogger().info("Found Access Token " + accessToken);
            ClientResource authResource = new CookieCopyClientResource(
                    validateRef);

            JSONObject request;
            try {
                request = createValidationRequest(accessToken, req);
                // Representation repr = this.createJsonRepresentation(request);
                Representation repr = new JsonStringRepresentation(request);
                getLogger().info("Posting to validator... json = " + request);
                // RETRIEVE JSON...WORKAROUND TO HANDLE ANDROID
                Representation r = authResource.post(repr);
                getLogger().info("After posting to validator...");
                repr.release();
                getLogger().info(
                        "Got Respose from auth resource OK "
                                + r.getClass().getCanonicalName());
                JsonRepresentation returned = new JsonRepresentation(r);

                // GET OBJECT
                JSONObject response = returned.getJsonObject();
                boolean authenticated = response.getBoolean("authenticated");

                if (response.has("tokenOwner"))
                    this.setUser(req, response, accessToken);

                String error = null;
                if (response.has("error"))
                    error = response.getString("error");

                getLogger().info("In Auth Filer -> " + authenticated);

                // Clean-up
                returned.release();
                r.release();
                authResource.release();

                if (authenticated)
                    return true;

                // handle any errors:
                handleError(error, resp);

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                if (authResource != null) {
                    authResource.getResponse().release();
                    authResource.release();
                }
            }
        }

        return false;
View Full Code Here

        if (args.length != 2) {
            System.err
                    .println("You need to pass your del.icio.us user name and password");
        } else {
            // Create a authenticated request
            ClientResource resource = new ClientResource(
                    "https://api.del.icio.us/v1/posts/recent");
            resource.setChallengeResponse(new ChallengeResponse(
                    ChallengeScheme.HTTP_BASIC, args[0], args[1]));

            // Fetch a resource: an XML document with your recent posts
            Representation entity = resource.get();
            DomRepresentation document = new DomRepresentation(entity);

            // Use XPath to find the interesting parts of the data structure
            for (Node node : document.getNodes("/posts/post")) {
                NamedNodeMap attrs = node.getAttributes();
View Full Code Here

        System.out.println(resource.getStatus() + " : "
                + resource.getLocationRef());
    }

    public static void deleteUser(String userName, String password) {
        ClientResource resource = getAuthenticatedResource(
                getUserUri(userName), userName, password);
        resource.delete();
        System.out.println(resource.getStatus() + " : "
                + resource.getLocationRef());
    }
View Full Code Here

     *            The password.
     * @return The authenticated resource to use.
     */
    public static ClientResource getAuthenticatedResource(String uri,
            String login, String password) {
        ClientResource result = new ClientResource(uri);
        result.setChallengeResponse(new ChallengeResponse(
                ChallengeScheme.HTTP_BASIC, login, password));
        return result;
    }
View Full Code Here

        form.add("bookmark[long_description]", longDescription);
        form.add("bookmark[restrict]", Boolean.toString(restrict));

        // Create an authenticated resource as a bookmark is in
        // the user's private area
        ClientResource resource = getAuthenticatedResource(getBookmarkUri(
                userName, uri), userName, password);
        resource.put(form.getWebRepresentation());

        System.out.println(resource.getStatus());
    }
View Full Code Here

        Form form = new Form();
        form.add("user[password]", password);
        form.add("user[full_name]", fullName);
        form.add("user[email]", email);

        ClientResource resource = new ClientResource(getUserUri(userName));
        resource.put(form.getWebRepresentation());
        System.out.println(resource.getStatus());
    }
View Full Code Here

* @author Jerome Louvel
*/
public class LuceneTestCase extends RestletTestCase {

    public void testTika() throws Exception {
        ClientResource r = new ClientResource(
                "clap://system/org/restlet/test/ext/lucene/LuceneTestCase.rtf");

        Representation rtfSample = r.get();
        // rtfSample.write(System.out);

        // Prepare a SAX content handler
        SAXTransformerFactory factory = ((SAXTransformerFactory) TransformerFactory
                .newInstance());
View Full Code Here

        super.tearDown();
    }

    @Test
    public void testDigest() throws Exception {
        ClientResource cr = new ClientResource("http://localhost:" + port + "/");

        // Try unauthenticated request
        try {
            cr.get();
        } catch (ResourceException re) {
            assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, cr.getStatus());

            ChallengeRequest c1 = null;
            for (ChallengeRequest challengeRequest : cr.getChallengeRequests()) {
                if (ChallengeScheme.HTTP_DIGEST.equals(challengeRequest
                        .getScheme())) {
                    c1 = challengeRequest;
                    break;
                }
            }
            assertEquals(ChallengeScheme.HTTP_DIGEST, c1.getScheme());

            String realm = c1.getRealm();
            assertEquals("TestRealm", realm);

            // String opaque = c1.getParameters().getFirstValue("opaque");
            // String qop = c1.getParameters().getFirstValue("qop");
            // assertEquals(null, opaque);
            // assertEquals("auth", qop);

            // Try authenticated request
            cr.getRequest().setMethod(Method.GET);
            ChallengeResponse c2 = new ChallengeResponse(c1, cr.getResponse(),
                    "scott", "tiger".toCharArray());
            cr.setChallengeResponse(c2);
            cr.get();
            assertTrue(cr.getStatus().isSuccess());
        }
    }
View Full Code Here

        Map<String, Object> map = new TreeMap<String, Object>();
        map.put("value", "myValue");

        // Representation approach
        Reference ref = LocalReference.createFileReference(testFile);
        ClientResource r = new ClientResource(ref);
        Representation templateFile = r.get();
        TemplateRepresentation tr = new TemplateRepresentation(templateFile,
                map, MediaType.TEXT_PLAIN);
        final String result = tr.getText();
        assertEquals("Value=myValue", result);
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.