camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julien Faissolle (JIRA)" <j...@apache.org>
Subject [jira] Updated: (CAMEL-1513) camel-csv : mutliple messages lead to repeated values
Date Thu, 09 Apr 2009 07:48:34 GMT

     [ https://issues.apache.org/activemq/browse/CAMEL-1513?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Julien Faissolle updated CAMEL-1513:
------------------------------------

    Attachment: camel-csv.patch

Here is a patch for this issue along with unit tests. The behavior is now by default to add
new fields only if they have not already been set by previous messages. Thus, the field order
stays consistent. The field addition is synchronized to avoid concurrency problems. The new
property _autogenColumns_ can be set to false in order to disable the automatic generation
of fields. Disabling automatic generation is especially useful in the case of a custom CSVConfig.


> camel-csv : mutliple messages lead to repeated values
> -----------------------------------------------------
>
>                 Key: CAMEL-1513
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1513
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.0-M1
>            Reporter: Julien Faissolle
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 2.0.0
>
>         Attachments: camel-csv.patch
>
>
> I have this config : 
> {code:xml}
> <route>
>   <from uri="direct:msgIn"/>
>   <marshal><csv /></marshal>
>   <to uri="file://msgs?fileName=messages.csv" />
> </route>
> {code}
> I send Map objects with this :
> {code:java}
> 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);
> {code}
> This produces the following result :
> {code}
> 1,1
> 2,2,2,2
> {code}
> instead of 
> {code}
> 1,1
> 2,2
> {code}
> 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 :
> {code:java|title=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);
>   .......
> {code}
> I think the marshal method should perform something like
> {code:java}
> if (config == null) {
>     config = createConfig();
>     // lets add fields
>     Set set = map.keySet();
>     for (Object value : set) {
>         if (value != null) {
>      ..............
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message