Package org.restlet

Examples of org.restlet.Client


            component.start();

            // Allow extensions tunneling
            freemarkerApplication.getTunnelService().setExtensionsTunnel(true);
            velocityApplication.getTunnelService().setExtensionsTunnel(true);
            Client client = new Client(Protocol.HTTP);
            Response response = client.handle(new Request(Method.GET,
                    "http://localhost:" + TEST_PORT + "/freemarker/"
                            + testFileFm1.getName()));

            if (response.isEntityAvailable()) {
                assertEquals("Method=GET/Authority=localhost:" + TEST_PORT,
                        response.getEntity().getText());
            }

            response = client.handle(new Request(Method.GET,
                    "http://localhost:" + TEST_PORT + "/freemarker/"
                            + testFileFm2.getName()));
            assertTrue(response.getStatus().isSuccess());

            if (response.isEntityAvailable()) {
                assertEquals("Method=${m}/Authority=${ra}", response
                        .getEntity().getText());
            }

            response = client.handle(new Request(Method.GET,
                    "http://localhost:" + TEST_PORT + "/velocity/"
                            + testFileVl1.getName()));

            if (response.isEntityAvailable()) {
                assertEquals("Method=GET/Path=/velocity/testVl1", response
                        .getEntity().getText());
            }

            response = client.handle(new Request(Method.GET,
                    "http://localhost:" + TEST_PORT + "/velocity/"
                            + testFileVl2.getName()));
            assertTrue(response.getStatus().isSuccess());

            if (response.isEntityAvailable()) {
                assertEquals("Method=${m}/Path=${rp}", response.getEntity()
                        .getText());
            }

            // Now, let's stop the component!
            component.stop();
            client.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here


*/
public class PostPutTestCase extends BaseConnectorsTestCase {

    @Override
    protected void call(String uri) throws Exception {
        Client client = new Client(Protocol.HTTP);
        testCall(client, Method.POST, uri);
        testCall(client, Method.PUT, uri);
        client.stop();
    }
View Full Code Here

     * @throws IOException
     * @throws NoSuchAlgorithmException
     */
    @Test
    public void testGet() throws IOException, NoSuchAlgorithmException {
        Client client = new Client(Protocol.HTTP);

        // Test partial Get.
        Request request = new Request(Method.PUT, "http://localhost:"
                + TEST_PORT + "/");
        StringRepresentation rep = new StringRepresentation("0123456789");
        try {
            DigesterRepresentation digester = new DigesterRepresentation(rep);
            // Such representation computes the digest while
            // consuming the wrapped representation.
            digester.exhaust();
            // Set the digest with the computed one
            digester.setDigest(digester.computeDigest());
            request.setEntity(digester);

            Response response = client.handle(request);

            assertEquals(Status.SUCCESS_OK, response.getStatus());
            digester = new DigesterRepresentation(response.getEntity());
            digester.exhaust();
            assertTrue(digester.checkDigest());

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

    }

    @Override
    protected void call(String uri) throws Exception {
        final Request request = new Request(Method.GET, uri);
        Client c = new Client(Protocol.HTTP);
        final Response r = c.handle(request);

        assertEquals(r.getStatus().getDescription(), Status.SUCCESS_OK, r
                .getStatus());
        assertEquals("Hello world", r.getEntity().getText());
        c.stop();
    }
View Full Code Here

        // helper = new org.restlet.ext.httpclient.HttpClientHelper(null);
        // helper = new org.restlet.ext.net.HttpClientHelper(null);
        Engine.getInstance().getRegisteredClients().add(0, helper);
        Engine.setLogLevel(Level.FINE);

        Client client = new Client(new Context(), Protocol.HTTP);
        // client.getContext().getParameters().add("persistingConnections",
        // "false");
        client.getContext().getParameters().add("tracing", "false");
        client.getContext().getParameters().add("minThreads", "1");
        client.getContext().getParameters().add("lowThreads", "30");
        client.getContext().getParameters().add("maxThreads", "40");
        client.getContext().getParameters().add("maxQueued", "20");
        client.getContext().getParameters().add("directBuffers", "false");
        client.start();

        // String uri =
        // "http://www.restlet.org/downloads/2.1/restlet-jse-2.1snapshot.zip";
        String uri = "http://127.0.0.1:9999/";
        int iterations = 1000;
View Full Code Here

    }

    @Override
    protected void call(String uri) throws Exception {
        final Request request = new Request(Method.GET, uri);
        Client c = new Client(Protocol.HTTP);
        final Response r = c.handle(request);
        assertEquals(Status.SUCCESS_OK, r.getStatus());
        c.stop();
    }
View Full Code Here

            }
        };

        component.getDefaultHost().attach(application);

        Client client = new Client(new Context(), Protocol.HTTP);
        Request request = new Request(Method.GET, uri);
        Response response = client.handle(request);
        Representation entity = response.getEntity();

        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("abc", entity.getText());
        assertEquals(getClass().getName(), entity.getDisposition()
                .getFilename());
        client.stop();
    }
View Full Code Here

    }

    @Override
    protected void call(String uri) throws Exception {
        final Request request = new Request(Method.GET, uri);
        final Client client = new Client(Protocol.HTTPS);
        client.setContext(new Context());
        configureSslClientParameters(client.getContext());
        final Response r = client.handle(request);

        assertEquals(r.getStatus().getDescription(), Status.SUCCESS_OK,
                r.getStatus());
        assertEquals("Hello world", r.getEntity().getText());

        Thread.sleep(200);
        client.stop();
    }
View Full Code Here

     * Tests partial Get requests.
     *
     * @throws Exception
     */
    public void testGet() throws Exception {
        Client client = new Client(Protocol.HTTP);

        // Test partial Get.
        Request request = new Request(Method.GET, "http://localhost:"
                + TEST_PORT + "/testGet");
        Response response;

        response = client.handle(request);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("1234567890", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(10, response.getEntity().getAvailableSize());

        request = new Request(Method.GET, "http://localhost:" + TEST_PORT
                + "/testGet");
        request.setRanges(Arrays.asList(new Range(0, 10)));
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("1234567890", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(10, response.getEntity().getAvailableSize());
        assertEquals(0, response.getEntity().getRange().getIndex());
        assertEquals(10, response.getEntity().getRange().getSize());

        request.setRanges(Arrays.asList(new Range(Range.INDEX_FIRST, 2)));
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("12", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(2, response.getEntity().getAvailableSize());
        assertEquals(0, response.getEntity().getRange().getIndex());
        assertEquals(2, response.getEntity().getRange().getSize());

        request.setRanges(Arrays.asList(new Range(2, 2)));
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("34", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(2, response.getEntity().getAvailableSize());
        assertEquals(2, response.getEntity().getRange().getIndex());
        assertEquals(2, response.getEntity().getRange().getSize());

        request.setRanges(Arrays.asList(new Range(2, 7)));
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("3456789", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(7, response.getEntity().getAvailableSize());
        assertEquals(2, response.getEntity().getRange().getIndex());
        assertEquals(7, response.getEntity().getRange().getSize());

        request.setRanges(Arrays.asList(new Range(Range.INDEX_LAST, 7)));
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("4567890", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(7, response.getEntity().getAvailableSize());
        assertEquals(3, response.getEntity().getRange().getIndex());
        assertEquals(7, response.getEntity().getRange().getSize());

        request.setRanges(Arrays.asList(new Range(2, Range.SIZE_MAX)));
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("34567890", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(8, response.getEntity().getAvailableSize());
        assertEquals(2, response.getEntity().getRange().getIndex());
        assertEquals(8, response.getEntity().getRange().getSize());

        client.stop();
    }
View Full Code Here

     * Tests conditional ranges requests.
     *
     * @throws Exception
     */
    public void testConditionalRanges() throws Exception {
        Client client = new Client(Protocol.HTTP);

        // Test partial Get.
        Request request = new Request(Method.GET, "http://localhost:"
                + TEST_PORT + "/testGet");
        Response response = client.handle(request);
        Tag entityTag = response.getEntity().getTag();

        request.setRanges(Arrays.asList(new Range(1, Range.SIZE_MAX)));
        request.getConditions().setRangeTag(entityTag);
        response = client.handle(request);
        assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
        assertEquals("234567890", response.getEntity().getText());
        assertEquals(10, response.getEntity().getSize());
        assertEquals(9, response.getEntity().getAvailableSize());
        assertEquals(1, response.getEntity().getRange().getIndex());
        assertEquals(9, response.getEntity().getRange().getSize());

        entityTag = new Tag(entityTag.getName() + "-test");
        request.setRanges(Arrays.asList(new Range(1, Range.SIZE_MAX)));
        request.getConditions().setRangeTag(entityTag);
        response = client.handle(request);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("1234567890", response.getEntity().getText());
        client.stop();
    }
View Full Code Here

TOP

Related Classes of org.restlet.Client

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.