It could be much easier if you implement a DataFormat[1] yourself. Then you could pass the "CONVERT_BODY_TO_RSSURL" as the message header and tell the DataFormat to do the job for you. [1]https://cwiki.apache.org/CAMEL/data-format.html
Willem ---------------------------------- Apache Camel, Apache CXF committer Open Source Integration http://www.fusesource.com Blog http://willemjiang.blogspot.com Tiwtter http://twitter.com/willemjiang hussainpirosha wrote: > > Hi , > > How can we evaluate an expression/substitute a variable for building a URI > at runtime. Consider the routes below : > > // Route 1 : This reads a text file containing RSS URLs and passes each > URL read to an endpoint. > > from("file://c:?fileName=listOfRssUrls.txt&noop=true").process(new > Processor() > { > > public void process(Exchange exchange) throws Exception { > > if(logger.isInfoEnabled()) > logger.info("Reading RSS URL's from file"); > > File rssUrlFile = > exchange.getIn().getBody(File.class); > FileInputStream fis = new > FileInputStream(rssUrlFile); > DataInputStream in = new DataInputStream(fis); > BufferedReader br = new BufferedReader(new > InputStreamReader(in)); > String rssUrl = null; > List<String> urlLst = new ArrayList<String>(); > > StringBuilder listOfRssUrls = new > StringBuilder(); > while((rssUrl = br.readLine()) != null) { > urlLst.add(rssUrl); > > listOfRssUrls.append(rssUrl).append(";"); > } > > exchange.getOut().setBody(listOfRssUrls); > > if(logger.isInfoEnabled()) > logger.info("Read number of URL's > :"+urlLst.size()); > > } > > }).split(body(String.class).tokenize(";")).to("direct:processRssUrl"); > > > // Route 2 : This should use the URL passed in route 1 to fetch the RSS > feed. Can we convert the body to String and use it form a URI at runtime ? > or can we access some variable/header property at run time to build the > URI ? > > from("direct:processRssUrl").from("rss:{CONVERT_BODY_TO_RSSURL}?splitEntries=true&consumer.initialDelay=0&consumer.delay=2"). > filter(). > method("feedFilterBean", "titleContainsQuery"). > process(new SomeProcessor()); > > Tried to use the > PropertyComponent(org.apache.camel.component.properties.PropertiesComponent) > available in 2.3 version but found that it substitutes the properties > while configuring the routes, not while running them. > > Thanks, > Hussain > > -- View this message in context: http://camel.465427.n5.nabble.com/How-to-evaluate-an-expression-substitute-a-variable-for-building-URI-s-at-runtime-tp1618587p1657686.html Sent from the Camel - Users mailing list archive at Nabble.com.