camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mike_hoffy <>
Subject Camel CSV Component Not Outputting Headers Correctly
Date Sun, 18 Jan 2015 16:18:20 GMT
I have the following 2.14.1 route:

                           "/o:Order/o:OrderType/o:FulfillmentCenter = '"
                                 + "'", Boolean.class, namespace)
                     .csv().to("file://" +

My aggregation strategy correlates XML where the fulfillmentcenter element's
text is of a certain value. This works correctly. My message translator then
takes the exchange and processes it:

       public List<Map&lt;String, Object>> processAggregate(List orders)
throws Exception {"Processing the aggregate");
      List<Map&lt;String, Object>> results = new ArrayList<Map&lt;String,

      // 1 - Add the header first
      Map<String, Object> header = new HashMap<String, Object>();
      header.put("orderNumber", "Order Number");
      header.put("firstName", "First Name");
      header.put("lastName", "Last Name");

      try {
         if (orders != null) {
            // 2 - Add each order ID
            for (int i = 0; i < orders.size(); i++) {
               com.pluralsight.orderfulfillment.generated.Order order =
unmarshallOrder((String) orders
               Map<String, Object> row = new HashMap<String, Object>();
               row.put("firstName", order.getOrderType().getFirstName());
               row.put("lastname", order.getOrderType().getLastName());
      } catch (Exception e) {
               "An error occurred while trying to process messages for the
abc fulfillment center: "
                     + e.getMessage(), e);
         throw e;
      return results;

As you can see, I'm accepting the list of orders as the parameter from the
body of the exchange. First, I add a header to the list of maps I plan to
return. I then unmarshal each XML from the input list and build maps to add
to the return list. 

Once message processing is complete, I marshall the results into CSV and
then send the contents to a file. 

The content that results in the body below is:

Last Name,Order Number,First Name

I expected the header to be in the correct sequence; however, its not. Also,
an extra comma is output to the left. Now, if I don't add the map for the
header, I get the following:


Here are my questions:

1) Is marshalling the csv then sending the exchange to a file an accepted
approach? Or should I be using some other component in between the csv and
file components. 
2) How do I maintain the order of elements in a row. For instance, I want to
make sure that the columns are order number, first name, last name; however,
the map keys are not the way I would want to assure order. Any guidance
would be appreciated. 

Let me know if there is anything else I can provide. Thank you in advance
for your help. 

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message