apache-camelenterprise-integration

camel dynamic uri parameter


i want to implement the content enricher pattern with camel like this:

from("direct:x").enrich(dynamicUri,new MyAggregatorStrategy()).to("direct:y")

The dynamic uri is based on each message which comes from the direct:x channel. So let's say there is an xml item coming in with the value a then the uri should be like http://someurl?q=a but the dynamicUri can only be a resource channel identifier.

I found some discussion on this here but i don't really understand it and the "HttpProducer.HTTP_URI" is not available in my workspace. Which camel package do I need for this and how do I do this? A processor maybe, but how?


Solution

  • What version of Camel are you using?

    Many of those constant names for keys has been moved to to org.apache.camel.Exchange class in Camel 2.0 onwards. So take a look at this class for the HTTP_URI constant. That's also what's listed on the wiki page http://camel.apache.org/http

    The Content Enricher doesn't support a dynamic URI, but some Camel components allow to set an uri as a header; such as the camel-http. Which mean in your case you can provide the uri as a header using the constant Exchange.HTTP_URI.

    However that said, the Recipient List EIP pattern in Camel actually supports to evaluate the URI fully dynamic, and it also supports aggregation. http://camel.apache.org/recipient-list.html

    So you could implement the solution like this:

    from("direct:x")
        .recipientList(header("dynamicUriHeader")).aggregationStrategy(new MyOwnAggregationStrategy())
        .to("direct:y");