I am splitting a file into lines using a tokenizer:
.split().tokenize("\n", 1)
However, some of the files I need to process will contain a header line, which will need to be processed differently to the normal lines. Is there an easy way to read the first line, process that, then split the remaining lines?
Using Split. The following example shows how to take a request from the direct:a endpoint, then split into sub messages, which each are sent to the direct:b endpoint. The example splits the message body using a tokenizer to split into lines using the new-line character as separator.
end() is needed to avoid anything outside the split block from being included. The desired behavior was to split the body, route each part using a routingslip to a different endpoint. Once the split block was complete, then continue processing with the exchange (and body) being as it was before the split.
You can do something like this. It will use a content based router EIP, then different sub routes for processing.
from(A)
.split().tokenize("\n",1)
.choice()
.when(simple("${property.CamelSplitIndex} > 0"))
.to("direct:processLine")
.otherwise()
.to("direct:processHeader");
from("direct:processLine")
.bean(processLineBean)
.to(B);
from("direct:processHeader")
.bean(processHeaderBean)
.to(B);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With