Reputation: 1
@Override
public void configure(){
rest("/camel/loss-events")
.get("/csv-download")
.to("direct:generateCsv");
CsvDataFormat csv = new CsvDataFormat();
csv.setDelimiter(getCsvParameterDelimiter().charAt(0));
from("direct:generateCsv")
.process(exchange -> {
List<LossEvent> lossEventList= Optional.ofNullable(bean.getLossEventEList()).orElse(Collections.emptyList());
List<String[]> csvData = new ArrayList<>();
csvData.add(getHeaders());
csvData.addAll(convertLossEventsToCsvRows(lossEventList));
exchange.setProperty("csvData", csvData);
exchange.getIn().setBody(csvData);
})
.marshal().csv()
.setHeader("Content-Type", constant("text/csv; charset=UTF-8"))
.setHeader("Content-Disposition", constant("attachment; filename=Loss_Events.csv"))
.to("stream:out");
}
I tried to generate the csv file based on a certain delimiter that i retrieve from my database. I debugged and the csvParameterDelimiter() retrieves a semicolon ';' of char type which is what i want. When i marshal it seems that the default attributes of CsvDataFormat are set instead of the ones i am trying to set.
Upvotes: 0
Views: 41
Reputation: 5668
Looking at your method calls, I think you are not passing in your csv object with the correct delimeter being set to the marshall call. Take a look at
...
.marshal().csv(). // this is very well creating a new default instance
...
This should be changed to something like
...
marshal(csv). # the name of your CSVDataFormat instance
...
so that the marshaller uses your csv instance
Upvotes: 0