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] Commented: (CAMEL-1513) camel-csv : mutliple messages lead to repeated values
Date Mon, 06 Apr 2009 06:44:34 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-1513?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=51036#action_51036
] 

Julien Faissolle commented on CAMEL-1513:
-----------------------------------------

Ok, I'll work on it. But I don't think the CSVConfig should be automatically created on each
invocation because it would forbid providing one's own CSVConfig instance through setConfig().
Note that manually assigning a CSVConfig doesn't work as it should because of the current
bug.

> 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
>
>
> 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