camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: CSV file
Date Wed, 10 Oct 2007 10:47:52 GMT
On 10/10/2007, borgel <> wrote:
> I am trying to use Camel in a project. I am going to do exactly the same
> thing as in the etl example, except i have to read csv files (comma
> separated), instead of xml. Do you have a suggestion how to do that?
> I guess i can't do:
> from("file:src/data?noop=true").convertBodyTo(PersonDocument.class)
> directly?
> I was therefore thinking of something like:
> from("file:src/data?noop=true").process(csvToXml).convertBodyTo(PersonDocument.class).
> Do i actually have to go through the PersonDocument.class at all? Can't i
> just create a transformer that takes a String (content of csv file) and
> return a CustomerEntity?

So you could just use the bean integration to implement your
transformation; get the DSL to invoke your transform as a bean...

  from("file:src/data?noop=true").bean(new MyTransformerBean());

or even call a specific named method from a bean defined in your
registry (JNDI or Spring XML etc)

  from("file:src/data?noop=true").beanRef("csvToXmlBean", "convert");

Then your convert method could be like this

public class MyTransformerBean {

  // adding a parameter annotation so that Camel knows ot invoke
  // this method by default - in case we add more public methods later
  public List<PersonDocument> convert(@Body Reader reader) {... }


Incidentally I've added support for pluggable data formats now; so we
could define a CsvFormat that is capable of reading & writing CSVs...

The CSV format could either use a Map for each row; or could use a
specific bean type; then use introspection to get/set each cell value?


Open Source SOA

View raw message