I´m trying to split an ArrayList and writing each element to it´s own file using Apache Camel like in this simplified example:
from(\"timer://poll?period=10000\"
After you called split function, your route is divided in 3 ways, each method or route executed after that is applied on each process way.
In each process way, split method add CamelSplitIndex property.
So this code should work
from("timer://poll?period=10000").process(new Processor(){
public void process(Exchange exchange){
ArrayList list = new ArrayList();
list.add("one");
list.add("two");
list.add("three");
exchange.getIn().setBody(list, ArrayList.class);
}
}).split(body()).log(body().toString()).to("file:some/dir?fileName=${header.CamelSplitIndex}");
This is second example with xml file and xpath.
We suppose that you want to explose xml for each node order with an element name inside:
Order 1
Order 2
We suppose that we want to explode this xml file in 2 files
from("file://repo-source").split(xpath("//orders/order")).setHeader("orderName", xpath("/order/name").stringResult()).to("file://repo?fileName=${header.orderName}.xml");