camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAMEL-1513) camel-csv : mutliple messages lead to repeated values
Date Sat, 04 Apr 2009 18:23:34 GMT

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

Claus Ibsen commented on CAMEL-1513:
------------------------------------

Julien, well spotted

Do you care to try to create a patch?
http://camel.apache.org/support.html

And please add an unit test demonstrating this bug is fixed.

The problem is indeed the fact that CSVConfig is not created on each operation.

So the CSVConfig should *not* be a shared instance. It should be created on each invocation.



> 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