Hi

You can write a java bean with a method that enrichs with data from the file.
public String enrichMe(@Header("id") String id) {

And then use some stax / xml / xpath api to find the selection to enrich.


Mind that the xpath from the JDK works only in-memory so if you want
to use that, then maybe look for alternatives like
http://camel.apache.org/vtd-xml

Or camel-stax
http://camel.apache.org/stax.html

Or depending how you xml file is structured you can also use
java.util.Scanner to scan for the part where the id is located.

In the pollEnrich(file) you can in the aggregation strategy, also use
the above from java code. And you can get the file handle using

File file = newExchange.getIn().getBody(File.class);




On Sat, May 4, 2013 at 11:53 PM, ihullu <[email protected]> wrote:
> I would like to do the following:
>
> 1. read a csv file
> 2. split it per line
> 3. per line enrich it with data coming from a xml source
> 4. per line execute a REST call to store the line
>
> As I have a pure Java background an no Spring experience I used the Java
> DSL.
>
> This is what I created so far:
>
>        from("direct:start")
>            .to("log: IN ==>")
>            .split(body().tokenize("\n")).streaming()
>            .unmarshal().bindy(BindyType.Csv,
> Product.class.getPackage().getName())
>            .bean(Transform.class)
>            .to("log: JAXB ==>")
>            .setHeader("id", simple("${body.id}")).log("id =
> ${in.header.id}")
>            .pollEnrich("file:resource?fileName=PRD-onetrail.prd",new
> AggregationStrategy())
>            //.to("log: END ==>")
>            //.to("mock:result")
>            ;
>
> The input is:
>
>       String inMsg = "0196-SJCLPAD2SGG\t112\n" +
>                          "0434-SJDJFHRDFID\t3\n";
>
>
>
> I am stuck at the Enrich part. It has the xml file as an input and uses the
> Aggregation class to do the enrichment. The problem is that it consumes the
> entire xml file. In the AggregationStrategy class I can browse through the
> file and select the correct element by matching on the id field. This does
> not sound very nice to me because the xml file is rather big. I do not want
> to have the entire file in memory.
>
> I was actually looking for something like this. I want to do a
> lookup/selection based on the body.id field in the XML file
> (PRD-ontrail.prd) prior to the the polEnrich and enrich it with some
> additional fields.
>
> So
>
> Read File -> Split per line -> create Product Bean -> Add header
> --------------------
>
> |                                    |-> enrich
>
> V                                   |
>
> Select element from XML--------
>
> using header/id
>
> I hope this is clear what I want.
>
> Can somebody help me figure this out?
>
> Regards
> Izaak
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/splitter-enricher-aggregator-tp5732020.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to