Package org.restlet.data

Examples of org.restlet.data.Form


     */
    public void testSI() throws IOException, ResourceException {
        Method method = AnnotatedResource9TestCase.SI;

        String text = "text";
        Form form = new Form();
        form.add("key", "value");

        client = new Client(Protocol.HTTP);
        Request request = new Request(method, "http://localhost:8111/test");
        Response response = client.handle(request);
        assertTrue(response.getStatus().isSuccess());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(text, MediaType.TEXT_PLAIN);
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        assertEquals("si-html+txt", response.getEntity().getText());

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(form.getWebRepresentation());
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        assertEquals("si-string+form", response.getEntity().getText());

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(text, MediaType.TEXT_PLAIN);
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        assertEquals("si-string+text", response.getEntity().getText());

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(form.getWebRepresentation());
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        assertEquals("si-html+form", response.getEntity().getText());
    }
View Full Code Here


     */
    public void testSNI() throws IOException, ResourceException {
        Method method = AnnotatedResource9TestCase.SNI;

        String text = "text";
        Form form = new Form();
        form.add("key", "value");

        client = new Client(Protocol.HTTP);
        Request request = new Request(method, "http://localhost:8111/test");
        Response response = client.handle(request);
        assertTrue(response.getStatus().isSuccess());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(text, MediaType.TEXT_PLAIN);
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        assertEquals("sni-html+txt", response.getEntity().getText());

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(form.getWebRepresentation());
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        assertEquals("sni-html+form", response.getEntity().getText());
View Full Code Here

     */
    public void testUSI() throws IOException, ResourceException {
        Method method = AnnotatedResource9TestCase.USI;

        String text = "text";
        Form form = new Form();
        form.add("key", "value");

        client = new Client(Protocol.HTTP);
        Request request = new Request(method, "http://localhost:8111/test");
        Response response = client.handle(request);
        assertTrue(response.getStatus().isSuccess());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(text, MediaType.TEXT_PLAIN);
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        assertEquals("usi-string+text", response.getEntity().getText());

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(form.getWebRepresentation());
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        assertEquals("usi-string+form", response.getEntity().getText());

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(text, MediaType.TEXT_PLAIN);
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        assertEquals("usi-string+text", response.getEntity().getText());

        request = new Request(AnnotatedResource9TestCase.USI,
                "http://localhost:8111/test");
        request.setEntity(form.getWebRepresentation());
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        assertEquals("usi-string+form", response.getEntity().getText());

        request = new Request(AnnotatedResource9TestCase.USI,
                "http://localhost:8111/test");
        request.setEntity(form.getWebRepresentation());
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        assertEquals("usi-string+form", response.getEntity().getText());
View Full Code Here

     */
    public void testUSNI() throws IOException, ResourceException {
        Method method = AnnotatedResource9TestCase.USNI;

        String text = "text";
        Form form = new Form();
        form.add("key", "value");

        client = new Client(Protocol.HTTP);
        Request request = new Request(method, "http://localhost:8111/test");
        Response response = client.handle(request);
        assertTrue(response.getStatus().isSuccess());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_PLAIN));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_PLAIN, response.getEntity().getMediaType());
        response.getEntity().release();

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(text, MediaType.TEXT_PLAIN);
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        assertEquals("usni-html+txt", response.getEntity().getText());

        request = new Request(method, "http://localhost:8111/test");
        request.setEntity(form.getWebRepresentation());
        request.getClientInfo().getAcceptedMediaTypes()
                .add(new Preference<MediaType>(MediaType.TEXT_HTML));
        response = client.handle(request);
        assertEquals(MediaType.TEXT_HTML, response.getEntity().getMediaType());
        assertEquals("usni-html+form", response.getEntity().getText());
View Full Code Here

        Series<Parameter> result = null;

        if ((getHelped() != null) && (getHelped().getContext() != null)) {
            result = getHelped().getContext().getParameters();
        } else {
            result = new Form();
        }

        return result;
    }
View Full Code Here

        result = clientResource.post(input, MediaType.APPLICATION_JSON);
        assertNotNull(result);
        assertEquals("root=true3", result.getText());
        assertEquals(MediaType.APPLICATION_JSON, result.getMediaType());

        Form inputForm = new Form();
        inputForm.add("root", "true");
        result = clientResource.post(inputForm, MediaType.APPLICATION_JSON);
        assertNotNull(result);
        assertEquals("root=true3", result.getText());
        assertEquals(MediaType.APPLICATION_JSON, result.getMediaType());
View Full Code Here

                        MediaType.TEXT_PLAIN);

                // -----------------------
                // Adding response headers
                // -----------------------
                headers = new Form();

                // Non-standard headers are allowed
                headers.add("X-Test", "Test value");

                // Standard HTTP headers are forbidden. If you happen to add one
View Full Code Here

        if (item == null) {
            item = new Item(itemName);
        }

        // Update the description.
        Form form = new Form(entity);
        item.setDescription(form.getFirstValue("description"));

        if (getItems().putIfAbsent(item.getName(), item) == null) {
            setStatus(Status.SUCCESS_CREATED);
        } else {
            setStatus(Status.SUCCESS_OK);
View Full Code Here

        request.setChallengeResponse(new ChallengeResponse(
                ChallengeScheme.HTTP_AWS_S3, "44CF9590006BF252F707",
                "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV"));

        // Add some extra headers
        final Series<Parameter> extraHeaders = new Form();
        extraHeaders.add("X-Amz-Meta-Author", "foo@bar.com");
        extraHeaders.add("X-Amz-Magic", "abracadabra");

        // For the test we hard coded a special date header. Normally you don't
        // need this as the
        // HTTP client connector will automatically provide an accurate Date
        // header and use it
View Full Code Here

    @Post
    public Representation acceptItem(Representation entity) {
        Representation result = null;
        // Parse the given representation and retrieve pairs of
        // "name=value" tokens.
        Form form = new Form(entity);
        String itemName = form.getFirstValue("name");
        String itemDescription = form.getFirstValue("description");

        // Register the new item if one is not already registered.
        if (!getItems().containsKey(itemName)
                && getItems().putIfAbsent(itemName,
                        new Item(itemName, itemDescription)) == null) {
View Full Code Here

TOP

Related Classes of org.restlet.data.Form

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.