THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block |
---|
CsvDataFormat csv = new CsvDataFormat(); csv.setDelimiter("|"); from("direct:start") .unmarshal(csv) .to("bean:myCsvHandler?method=doHandleCsv"); |
Using autogenColumns, configRef and strategyRef attributes inside XML DSL
Available as of Camel 2.9.2 / 2.10
You can customize the CSV Data Format to make use of your own CVSConfig and/or CVSStrategy. Also note that the default value for autogenColumns is true. The following example should illustrates this.
Code Block | ||||
---|---|---|---|---|
| ||||
<route>
<from uri="direct:start" />
<marshal>
<!-- make use of a strategy other than the default one which is 'org.apache.commons.csv.CSVStrategy.DEFAULT_STRATEGY' -->
<csv autogenColumns="false" delimiter="|" configRef="csvConfig" strategyRef="excelStrategy" />
</marshal>
<convertBodyTo type="java.lang.String" />
<to uri="mock:result" />
</route>
<bean id="csvConfig" class="org.apache.commons.csv.writer.CSVConfig">
<property name="fields">
<list>
<bean class="org.apache.commons.csv.writer.CSVField">
<property name="name" value="orderId" />
</bean>
<bean class="org.apache.commons.csv.writer.CSVField">
<property name="name" value="amount" />
</bean>
</list>
</property>
</bean>
<bean id="excelStrategy" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField" value="org.apache.commons.csv.CSVStrategy.EXCEL_STRATEGY" />
</bean>
|
Dependencies
To use CSV in your camel routes you need to add the a dependency on camel-csv which implements this data format.
...