Package org.restlet.representation

Examples of org.restlet.representation.Representation


                                    .toString());
                            if (contextResponse.getStatus().isSuccess()
                                    && (contextResponse.getEntity() != null)) {
                                filePath = ref.toString(false, false)
                                        .substring(rootLength);
                                Representation rep = contextResponse
                                        .getEntity();

                                if (filePath.startsWith("/")) {
                                    rep.setLocationRef(baseRef + filePath);
                                } else {
                                    rep.setLocationRef(baseRef + "/" + filePath);
                                }

                                resultSet.add(rep);
                            }
                        }
View Full Code Here


     *            The high-level request.
     * @return the status of the communication
     */
    public Status sendRequest(Request request) {
        Status result = null;
        Representation entity = request.isEntityAvailable() ? request
                .getEntity() : null;

        // Get the connector service to callback
        org.restlet.service.ConnectorService connectorService = ConnectorHelper
                .getConnectorService();
        if (connectorService != null) {
            connectorService.beforeSend(entity);
        }

        try {
            if (entity != null) {

                // In order to workaround bug #6472250
                // (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6472250),
                // it is very important to reuse that exact same "requestStream"
                // reference when manipulating the request stream, otherwise
                // "insufficient data sent" exceptions will occur in
                // "fixedLengthMode"
                OutputStream requestStream = getRequestEntityStream();
                java.nio.channels.WritableByteChannel requestChannel = getRequestEntityChannel();

                if (requestChannel != null) {
                    entity.write(requestChannel);
                    requestChannel.close();
                } else if (requestStream != null) {
                    entity.write(requestStream);
                    requestStream.flush();
                    requestStream.close();
                }
            }

            // Now we can access the status code, this MUST happen after closing
            // any open request stream.
            result = new Status(getStatusCode(), null, getReasonPhrase(), null);
        } catch (IOException ioe) {
            getHelper()
                    .getLogger()
                    .log(Level.FINE,
                            "An error occured during the communication with the remote HTTP server.",
                            ioe);
            result = new Status(Status.CONNECTOR_ERROR_COMMUNICATION, ioe);
        } finally {
            if (entity != null) {
                entity.release();
            }

            // Call-back after writing
            if (connectorService != null) {
                connectorService.afterSend(entity);
View Full Code Here

        return result;
    }

    @Override
    public Representation handle() {
        Representation result = null;

        if (this.directoryRedirection) {
            if (this.originalRef != null) {
                if (this.originalRef.hasQuery()) {
                    redirectSeeOther(this.originalRef.getPath() + "/?"
View Full Code Here

     * @return The encoded representation or the original one if no encoding
     *         supported by the client.
     */
    public Representation encode(ClientInfo client,
            Representation representation) {
        Representation result = representation;
        final Encoding bestEncoding = getBestEncoding(client);

        if (bestEncoding != null) {
            result = new EncodeRepresentation(bestEncoding, representation);
        }
View Full Code Here

     * Returns a Reader wrapping the given entity stream, with respect to the
     * {@link CharacterSet} of the entity of the current {@link Request}, or
     * UTF-8 if no character set was given or if it is not available
     */
    static Reader getReader(InputStream entityStream) {
        final Representation entity = Request.getCurrent().getEntity();
        CharacterSet cs;
        if (entity != null) {
            cs = entity.getCharacterSet();
            if (cs == null) {
                cs = Util.JAX_RS_DEFAULT_CHARACTER_SET;
            }
        } else {
            cs = Util.JAX_RS_DEFAULT_CHARACTER_SET;
View Full Code Here

            Annotation[] annotations, MediaType mediaType) {

        // Convert the object into a representation
        Variant targetVariant = new Variant(new org.restlet.data.MediaType(
                mediaType.toString()));
        Representation representation = getConverterService().toRepresentation(
                object, targetVariant, null);
        return (representation == null) ? -1 : representation.getSize();
    }
View Full Code Here

    public Object readFrom(Class<Object> type, Type genericType,
            Annotation[] annotations, MediaType mediaType,
            MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
            throws IOException {

        Representation sourceRepresentation = new InputRepresentation(
                entityStream, new org.restlet.data.MediaType(
                        mediaType.toString()));
        return getConverterService().toObject(sourceRepresentation, type, null);
    }
View Full Code Here

            OutputStream entityStream) throws IOException {

        // Convert the object into a representation
        Variant targetVariant = new Variant(new org.restlet.data.MediaType(
                mediaType.toString()));
        Representation representation = getConverterService().toRepresentation(
                object, targetVariant, null);

        // Copy entity headers (NOT SUPPORTED)
        // Series<Parameter> entityHeaders = new Form();
        // HttpServerAdapter.addEntityHeaders(representation, entityHeaders);
        //
        // for (Parameter header : entityHeaders) {
        // httpHeaders.add(header.getName(), header.getValue());
        // }

        // Write the representation
        if (representation != null) {
            representation.write(entityStream);
        }
    }
View Full Code Here

        clientResource = null;
        super.tearDown();
    }

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

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

    }

    @Override
    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));
View Full Code Here

TOP

Related Classes of org.restlet.representation.Representation

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.