Looks like there's a bug in file*
org.apache.camel.component.restlet.DefaultRestletBinding.java*


*Method starts at line number 292*
public void populateExchangeFromRestletResponse(Exchange exchange, Response
response) throws Exception {
        for (Map.Entry<String, Object> entry :
response.getAttributes().entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (!headerFilterStrategy.applyFilterToExternalHeaders(key,
value, exchange)) {
                exchange.getOut().setHeader(key, value);
                LOG.debug("Populate exchange from Restlet response header:
{} value: {}", key, value);
            }
        }

        // set response code
        int responseCode = response.getStatus().getCode();
        exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE,
responseCode);

        // set restlet response as header so end user have access to it if
needed
        exchange.getOut().setHeader(RestletConstants.RESTLET_RESPONSE,
response);

        if (response.getEntity() != null) {
            // get content type
            MediaType mediaType = response.getEntity().getMediaType();
            if (mediaType != null) {
                LOG.debug("Setting the Content-Type to be {}", 
mediaType.toString());
                exchange.getOut().setHeader(Exchange.CONTENT_TYPE,
mediaType.toString());
            }
            if (mediaType != null &&
mediaType.equals(MediaType.APPLICATION_OCTET_STREAM)) {
                exchange.getOut().setBody(response.getEntity().getStream());
            } *else {
                // get content text
  Line 320              String text = response.getEntity().getText(); 
  Line 321                 LOG.debug("Populate exchange from Restlet
response: {}", text);
  Line 322                 exchange.getOut().setBody(text);
            }*
        }

        // preserve headers from in by copying any non existing headers
        // to avoid overriding existing headers with old values
        MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(),
false);
    }

The bolded else part above gets the text from the entity in the Response and 
sets it on the OUT Message of the Exchange. But, at this point the
response.getEntity() is of type InputRepresentation with MediaType.TEXT_XML
and GZIP encoded, so why not pass the entity along as is? When its converted
to a  String its tampered and lost (remember its encoded type is GZIP). 

*To make it work,* we could change the code to something like:
replace lines 320 - 322 with
  *exchange.getOut().setBody(response.getEntity());*

*
On the client side, decode the response  *
InputRepresentation representation =
(InputRepresentation)resultEndpoint.getExchanges().get(0).getIn().getBody();
 Representation representationDecoded=  new
DecodeRepresentation(representation);
String decodedString = representationDecoded.getText(); // will contain the
decoded response








--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-Restlet-2-14-0-DecodeRepresentation-tp5759382p5759484.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to