Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-1513

camel-csv : mutliple messages lead to repeated values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0-M1
    • 1.6.1, 2.0-M2
    • camel-core
    • None

    Description

      I have this config :

      <route>
        <from uri="direct:msgIn"/>
        <marshal><csv /></marshal>
        <to uri="file://msgs?fileName=messages.csv" />
      </route>
      

      I send Map objects with this :

      ProducerTemplate template = context.createProducerTemplate();
      
      Map msg1 = new HashMap();
      msg1.put("A", 1);
      msg1.put("B", 1);
      Map msg2 = new HashMap();
      msg2.put("A", 2);
      msg2.put("B", 2);
      template.sendBody("direct:msgIn", msg1);
      template.sendBody("direct:msgIn", msg2);
      

      This produces the following result :

      1,1
      2,2,2,2
      

      instead of

      1,1
      2,2
      

      The more messages are pumped into the CSV marshaller, the more the values are repeated. This is because the marshal method in CsvDataFormat keeps adding columns to the config even if they are already present :

      CsvDataFormat.java
        ........
              CSVConfig conf = getConfig();
              // lets add fields
              Set set = map.keySet();
              for (Object value : set) {
                  if (value != null) {
                      String text = value.toString();
                      CSVField field = new CSVField(text);
                      conf.addField(field);
                  }
              }
              CSVWriter writer = new CSVWriter(conf);
      
        .......
      

      I think the marshal method should perform something like

      if (config == null) {
          config = createConfig();
          // lets add fields
          Set set = map.keySet();
          for (Object value : set) {
              if (value != null) {
           ..............
      }
      

      Attachments

        1. camel-csv.patch
          8 kB
          Julien Faissolle

        Activity

          People

            davsclaus Claus Ibsen
            jfe Julien Faissolle
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: