Package org.restlet.resource

Examples of org.restlet.resource.ClientResource


    protected void setUp() throws Exception {
        super.setUp();
        Finder finder = new Finder();
        finder.setTargetClass(MyResource5.class);

        this.clientResource = new ClientResource("http://local");
        this.clientResource.setNext(finder);
    }
View Full Code Here


    protected void setUp() throws Exception {
        super.setUp();
        Finder finder = new Finder();
        finder.setTargetClass(MyServerResource12.class);

        this.clientResource = new ClientResource("http://local");
        this.clientResource.setNext(finder);
        this.myResource = clientResource.wrap(MyResource12.class);
    }
View Full Code Here

     * Test POST, PUT and GET using the ClientResource class
     *
     * @throws Exception
     */
    public void testWithClientResource() throws Exception {
        ClientResource sampleResource = new ClientResource(uri);
        List<Preference<MediaType>> m = new ArrayList<Preference<MediaType>>();
        m.add(new Preference<MediaType>(MediaType.APPLICATION_XML));
        sampleResource.getClientInfo().setAcceptedMediaTypes(m);

        Sample sample = new Sample(IN_STRING);
        sample = sampleResource.post(sample, Sample.class);
        assertEquals(HELLO_OUT_STRING, sample.getVal());

        sampleResource.put(sample);
        assertTrue(sampleResource.getStatus().isSuccess());

        sample = sampleResource.put(sample, Sample.class);
        assertEquals(HELLO_OUT_STRING, sample.getVal());

        sample = sampleResource.get(Sample.class);
        assertEquals(IN_STRING, sample.getVal());
    }
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();
        Finder finder = new Finder();
        finder.setTargetClass(MyResource4.class);

        this.clientResource = new ClientResource("http://local");
        this.clientResource.setNext(finder);
    }
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();
        Finder finder = new Finder();
        finder.setTargetClass(MyServerResource1.class);

        this.clientResource = new ClientResource("http://local");
        this.clientResource.setNext(finder);
        this.myResource = clientResource.wrap(MyResource1.class);
    }
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();
        Finder finder = new Finder();
        finder.setTargetClass(MyResource7.class);

        this.clientResource = new ClientResource("http://local");
        this.clientResource.setNext(finder);
    }
View Full Code Here

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

            // Use XPath to find the interesting parts of the data structure
            String expr = "/ResultSet/Result/Title";
            for (Node node : document.getNodes(expr)) {
View Full Code Here

        assertEquals(MediaType.APPLICATION_ATOM, representation.getMediaType());
    }

    public void testRepresentationToObject() throws IOException {
        ConverterService cs = new ConverterService();
        ClientResource cr = new ClientResource(
                "clap://class/org/restlet/test/ext/atom/entry.xml");
        Representation representation = cr.get();
        Object object = cs.toObject(representation);
        assertTrue(object instanceof Feed);
    }
View Full Code Here

            getLogger().info("After Redirecting to : " + redirRef.toUri());
            // return true;
            // return null;
        } else {
            getLogger().info("Came back after SNS code = " + code);
            ClientResource tokenResource = new CookieCopyClientResource(
                    params.getBaseRef() + params.getAccessTokenPath());

            Form form = new Form();
            form.add(OAuthServerResource.GRANT_TYPE,
                    OAuthServerResource.GrantType.authorization_code.name());
            String redir = request.getResourceRef().getHostIdentifier()
                    + request.getResourceRef().getPath();
            form.add(OAuthServerResource.REDIR_URI, redir);

            if (basicSecret) {
                ChallengeResponse authentication = new ChallengeResponse(
                        ChallengeScheme.HTTP_BASIC);
                authentication.setDigestAlgorithm("NONE");
                String basic = params.getClientId() + ':'
                        + params.getClientSecret();
                authentication.setRawValue(Base64.encode(basic.getBytes(),
                        false));
                tokenResource.setChallengeResponse(authentication);
            } else {
                form.add(OAuthServerResource.CLIENT_ID, params.getClientId());
                form.add(OAuthServerResource.CLIENT_SECRET,
                        params.getClientSecret());
            }

            form.add(OAuthServerResource.CODE, code);
            getLogger().info(
                    "Sending access form : " + form.getQueryString() + " to : "
                            + tokenResource.getReference());

            try {
                Representation input = form.getWebRepresentation();
                Representation body = tokenResource.post(input);

                if (tokenResource.getStatus().isSuccess()) {
                    // Store away the user
                    OAuthUser authUser = OAuthUser.createJson(body);

                    if (authUser != null) {
                        request.getClientInfo().setUser(authUser);
                        request.getClientInfo().setAuthenticated(true);
                        getLogger().info(
                                "storing to context = : " + getContext());
                        // continue in the filter chain
                        auth = true;
                    }
                }

                getLogger().info("Before sns release");
                body.release();
            } catch (ResourceException re) {
                getLogger().warning("Could not find token resource.");
            }
            tokenResource.release();
        }
        return auth;
    }
View Full Code Here

        this.responseLogTemplate = (getLogFormat() == null) ? null
                : new Template(getLogFormat());

        if (getLogPropertiesRef() != null) {
            Representation logProperties = new ClientResource(getContext(),
                    getLogPropertiesRef()).get();

            if (logProperties != null) {
                LogManager.getLogManager().readConfiguration(
                        logProperties.getStream());
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.