0
votes

Here is my route:

def.convertBodyTo(String.class).split()
                    .method(splittingProcessor, "split")
                    .aggregationStrategy(myAggregationStrategy)
                    .bean(myProcessor, "aMethod")
                    .end();

I am trying to send one exchange to more than two different HTTP endpoints.

Here is my aggregation strategy:

    @Override 
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { 
    Message inMsg = newExchange.getIn();
    String body = inMsg.getBody(String.class);

    String oldBody= "";
    if (oldExchange == null) {
        return newExchange;
    }
    else {
        oldBody = oldExchange.getIn().getBody(String.class);
        oldExchange.getIn().setBody(oldBody + " "+body);
        return oldExchange;
    }
} 

but

body is always equal to "" and inMsg is "[Body is instance of java.io.InputStream]"

convertBodyTo(String.class) does not work either (at least the way I am using it).

What am I doing wrong?

PS. streamCaching() on the route or setStreamCache(true) on the context also do not work.

EDIT 1:

Camel Version: 2.12.13

In aMethod I am using a ProducerTemplate to send the exchange to an HTTP Endpoint:

    exchange = producerTemplate.send(uri, exchange);

and after that I do some processing to the exchange body.

I have noticed that the same thing works if I use the direct component.

1
What version of Camel do you use?, and what do you do in the aMethod of your myProcessor - Claus Ibsen
Please see my edit #1. - ampofila

1 Answers

0
votes

I think the problem is reported in this Camel ticket: https://issues.apache.org/jira/browse/CAMEL-7787

As a workaround for this bug, you use a custom processor, then you can just convert the message body to a String there, so the stream is read into memory and can be safely used in the aggregation strategy.