Package org.restlet.representation

Examples of org.restlet.representation.StringRepresentation


        clientInfo.setAcceptedLanguages(acceptedLanguages);

        final Request request = new Request(Method.POST, createReference(
                HttpHeaderTestService.class, "language"));
        request.setClientInfo(clientInfo);
        request.setEntity(new StringRepresentation("entity", Language.ENGLISH));
        final Response response = accessServer(request);

        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("en", response.getEntity().getText());
    }
View Full Code Here


        sb.append("</p>\n");
        sb.append("</body>\n");
        sb.append("</html>\n");

        return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML);
    }
View Full Code Here

        clientResource = null;
        super.tearDown();
    }

    public void testGet() throws IOException, ResourceException {
        Representation input = new StringRepresentation("<root/>",
                MediaType.APPLICATION_XML);
        Representation result = clientResource.post(input,
                MediaType.APPLICATION_XML);
        assertNotNull(result);
        assertEquals("<root/>1", result.getText());
        assertEquals(MediaType.APPLICATION_XML, result.getMediaType());

        input = new StringRepresentation("<root/>", MediaType.APPLICATION_XML);
        result = clientResource.post(input, MediaType.APPLICATION_JSON);
        assertNotNull(result);
        assertEquals("<root/>2", result.getText());
        assertEquals(MediaType.APPLICATION_JSON, result.getMediaType());

        input = new StringRepresentation("root=true",
                MediaType.APPLICATION_WWW_FORM);
        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());

        input = new StringRepresentation("[root]", MediaType.APPLICATION_JSON);
        result = clientResource.post(input, MediaType.APPLICATION_JSON);
        assertNotNull(result);
        assertEquals("[root]2", result.getText());
        assertEquals(MediaType.APPLICATION_JSON, result.getMediaType());
View Full Code Here

                        + request.getResourceRef() + '\n' + "Base URI:      "
                        + request.getResourceRef().getBaseRef() + '\n'
                        + "Remaining part: "
                        + request.getResourceRef().getRemainingPart() + '\n'
                        + "Method name:   " + request.getMethod() + '\n';
                response.setEntity(new StringRepresentation(message,
                        MediaType.TEXT_PLAIN));
            }
        };

        // Set the component roots
View Full Code Here

            if (target.isAssignableFrom(source.getClass())) {
                result = source;
            } else if (String.class.isAssignableFrom(target)) {
                result = source.getText();
            } else if (StringRepresentation.class.isAssignableFrom(target)) {
                result = new StringRepresentation(source.getText(),
                        source.getMediaType());
            } else if (EmptyRepresentation.class.isAssignableFrom(target)) {
                result = null;
            } else if (File.class.isAssignableFrom(target)) {
                if (source instanceof FileRepresentation) {
View Full Code Here

    public Representation toRepresentation(Object source, Variant target,
            UniformResource resource) throws IOException {
        Representation result = null;

        if (source instanceof String) {
            result = new StringRepresentation((String) source,
                    MediaType.getMostSpecific(target.getMediaType(),
                            MediaType.TEXT_PLAIN));
        } else if (source instanceof File) {
            result = new FileRepresentation((File) source,
                    MediaType.getMostSpecific(target.getMediaType(),
View Full Code Here

public class MyResource2 extends ServerResource {

    @Get
    public Representation represent() {
        return new StringRepresentation("<content/>", MediaType.TEXT_XML);
    }
View Full Code Here

            log.info("OpenID : " + response.keyValueFormEncoding());
            responseText = response.keyValueFormEncoding();
        } else if (Method.GET.equals(getMethod())) {
            // Could be a discovery request
            sendXRDSLocation();
            return new StringRepresentation("XRDS Discovery Information");
        } else {
            // --- error response ---
            response = DirectError.createDirectError("Unknown request");
            responseText = response.keyValueFormEncoding();
        }

        // return the result to the user
        return new StringRepresentation(responseText);
    }
View Full Code Here

        String result = myResource.store(newBean);
        assertEquals("Done", result);

        // Attempt to send an unknown entity
        try {
            clientResource.put(new StringRepresentation("wxyz",
                    MediaType.APPLICATION_GNU_ZIP));
        } catch (ResourceException re) {
            assertEquals(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE, re.getStatus());
        }
    }
View Full Code Here

        clientResource = null;
        super.tearDown();
    }

    public void testGet() throws IOException, ResourceException {
        Representation input = new StringRepresentation("[\"root\"]",
                MediaType.APPLICATION_JSON);
        Representation result = clientResource.post(input);
        assertNotNull(result);
        assertEquals("[\"root\"]1", result.getText());
        assertEquals(MediaType.APPLICATION_XML, result.getMediaType());

        input = new StringRepresentation("<root/>", MediaType.APPLICATION_XML);
        result = clientResource.post(input);
        assertNotNull(result);
        assertEquals("<root/>2", result.getText());
        assertEquals(MediaType.APPLICATION_XML, result.getMediaType());
    }
View Full Code Here

TOP

Related Classes of org.restlet.representation.StringRepresentation

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.