-
onException()
DeadLetterChannel
doTry()
-
CasvFormat
maps
csvFormat
process
setBody
CsvDataFormat csvDataFormat = new CsvDataFormat().setUseMaps(true);
from("file:" + rootDir + "/test/")
.log(LoggingLevel.INFO,"Start processing ${file:name}")
.unmarshal().pgp(pgpFileName,pgpUserId,pgpPassword)
.process(exchange -> { /* just to get csv header */
InputStream inputStream = exchange.getIn().getBody(InputStream.class);
try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))){
String header = bufferedReader.readLine();
exchange.getIn().setHeader("CSV_HEADER",header);
csvDataFormat.setHeader(header.split(",")); //<- this does not work, so had to add in body below!
System.out.println("csvHeader is : " + header);// + " ? " + Arrays.asList(csvDataFormat.getHeader()));
}
})
.split(body().tokenize("\n")).shareUnitOfWork()
.parallelProcessing().streaming()
.setBody(exchange -> exchange.getIn().getHeader("CSV_HEADER") + "\n" + exchange.getIn().getBody())
.doTry()
.unmarshal(csvDataFormat)
.process(requestFileService)
.doCatch(IOException.class)
//TODO: custom processing here...
.process(exchange -> log.error("caught in dotry: " + exchange.getIn().getBody())).stop()
.end()//end try/catch
.choice()
.when(simple("${property." + Exchange.SPLIT_COMPLETE + "} == true"))
.log(LoggingLevel.INFO, "Finished processing ${file:name}")
.end();