Camel recipient list aggregation strategy returns encoded values

Viewed 155

In an aggregation strategy where we are trying to combine multiple response bodies, we are getting "encoded?" values back when reading the body with exchange.getIn().getBody(). Here I am setting up multiple URLs that will be hit to retrieve data from using a recipientList:

.recipientList(header("DynamicCommaSeparatedURLs"))
.aggregationStrategy(new EmployeeResponseAggregationStrategy()).parallelProcessing(true);

In the aggregation code, I need to combine all the response and return merged response bodies:

public class EmployeeResponseAggregationStrategy implements AggregationStrategy {
  public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    String uri = newExchange.getProperty(Exchange.RECIPIENT_LIST_ENDPOINT, String.class);
    System.out.println(uri);
    if (oldExchange == null) {
      return newExchange;
    } else {
      String jsonString = oldExchange.getIn().getBody(String.class);
      //expecting json here
      System.out.println(jsonString);
      return oldExchange;
    }
  }
}

My issue

The print line (System.out.println(jsonString);) returns this: c8Ot��C�|�X<D�L�䠍�g.����=� �rc4�

Where I am expecting this as in Postman response to the same URL: response

Do not know what I am doing wrong as I am using similar functionality to aggregate other multicast responses.

1 Answers

Did you take a look to the http headers get from the http call response like Exchange.CONTENT_ENCODING ? I guess it send you the current encoding. If postman can read the response, that means your service send how to do it. If it is right, you should decode your response before the aggregation.

.convertBodyTo(String.class, "UTF-8") 

It could do the job.

Related