You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Anton Koscejev (JIRA)" <ji...@apache.org> on 2015/07/07 16:13:05 UTC

[jira] [Commented] (CAMEL-8941) Restlet supports binary files only with media type application/octet-stream

    [ https://issues.apache.org/jira/browse/CAMEL-8941?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14616753#comment-14616753 ] 

Anton Koscejev commented on CAMEL-8941:
---------------------------------------

After some initial testing It seems that for binary stream content a better solution would be to rely on Representation type, e.g.: 
{code}
if (entity instanceof StreamRepresentation) {
    exchange.getOut().setBody(response.getEntity().getStream());
}
{code}

However, I'm not sure if that's always correct (or perhaps only for cases when Transfer-encoding = chunked).

> Restlet supports binary files only with media type application/octet-stream 
> ----------------------------------------------------------------------------
>
>                 Key: CAMEL-8941
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8941
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-restlet
>    Affects Versions: 2.15.2
>            Reporter: Anton Koscejev
>
> The camel-restlet component populates Camel Exchange from Restlet Response via DefaultRestletBinding. However, it only properly reads binary contents if media type is "application/octet-stream". In all other cases it reads contents as String, even if contents are binary. For example, if the contents are of type "audio/wave" - a normal .wav file returned by a REST service - they would be read as a String, which results in an unplayable file.
> See code extract:
> {code}
> if (mediaType != null && mediaType.equals(MediaType.APPLICATION_OCTET_STREAM)) {
>     exchange.getOut().setBody(response.getEntity().getStream());
> } else if (response.getEntity() instanceof Representation) {
>     Representation representationDecoded = new DecodeRepresentation(response.getEntity());
>     exchange.getOut().setBody(representationDecoded.getText());
> } else {
>     // get content text by default
>     String text = response.getEntity().getText();
>     LOG.debug("Populate exchange from Restlet response: {}", text);
>     exchange.getOut().setBody(text);
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)