camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1154684 - in /camel/trunk/components/camel-bindy/src: main/java/org/apache/camel/dataformat/bindy/ main/java/org/apache/camel/dataformat/bindy/kvp/ test/java/org/apache/camel/dataformat/bindy/fix/
Date Sun, 07 Aug 2011 10:31:56 GMT
Author: davsclaus
Date: Sun Aug  7 10:31:56 2011
New Revision: 1154684

URL: http://svn.apache.org/viewvc?rev=1154684&view=rev
Log:
CAMEL-4311: Fixed issue with bindy in key value mode when using @OneToMany in multi threded
unmarshalling. Thanks to Surya for the patch.

Modified:
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest.java

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java?rev=1154684&r1=1154683&r2=1154684&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
Sun Aug  7 10:31:56 2011
@@ -51,9 +51,6 @@ public class BindyKeyValuePairFactory ex
     private Map<Integer, KeyValuePairField> keyValuePairFields = new LinkedHashMap<Integer,
KeyValuePairField>();
     private Map<Integer, Field> annotatedFields = new LinkedHashMap<Integer, Field>();
     private Map<String, Integer> sections = new HashMap<String, Integer>();
-
-    private Map<String, List<Object>> lists = new HashMap<String, List<Object>>();
-
     private String keyValuePairSeparator;
     private String pairSeparator;
     private boolean messageOrdered;
@@ -117,11 +114,17 @@ public class BindyKeyValuePairFactory ex
         }
     }
 
-    /**
-     * 
-     */
+    @Override
     public void bind(List<String> data, Map<String, Object> model, int line)
throws Exception {
 
+        // Map to hold the model @OneToMany classes while binding
+        Map<String, List<Object>> lists = new HashMap<String, List<Object>>();
+
+        bind(data, model, line, lists);
+    }
+
+    public void bind(List<String> data, Map<String, Object> model, int line,
Map<String, List<Object>> lists) throws Exception {
+
         Map<Integer, List<String>> results = new HashMap<Integer, List<String>>();
 
         LOG.debug("Key value pairs data : {}", data);
@@ -169,14 +172,14 @@ public class BindyKeyValuePairFactory ex
             if (obj != null) {
 
                 // Generate model from key value map
-                generateModelFromKeyValueMap(clazz, obj, results, line);
+                generateModelFromKeyValueMap(clazz, obj, results, line, lists);
 
             }
         }
 
     }
 
-    private void generateModelFromKeyValueMap(Class clazz, Object obj, Map<Integer, List<String>>
results, int line) throws Exception {
+    private void generateModelFromKeyValueMap(Class clazz, Object obj, Map<Integer, List<String>>
results, int line, Map<String, List<Object>> lists) throws Exception {
 
         for (Field field : clazz.getDeclaredFields()) {
 
@@ -388,7 +391,7 @@ public class BindyKeyValuePairFactory ex
                         lists.put(cl.getName(), new ArrayList<Object>());
                     }
 
-                    generateModelFromKeyValueMap(cl, null, results, line);
+                    generateModelFromKeyValueMap(cl, null, results, line, lists);
 
                     // Add list of objects
                     field.set(obj, lists.get(cl.getName()));
@@ -632,4 +635,5 @@ public class BindyKeyValuePairFactory ex
         }
     }
 
+
 }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java?rev=1154684&r1=1154683&r2=1154684&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
(original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
Sun Aug  7 10:31:56 2011
@@ -21,6 +21,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Scanner;
@@ -79,6 +80,9 @@ public class BindyKeyValuePairDataFormat
 
         // Pojos of the model
         Map<String, Object> model;
+        
+        // Map to hold the model @OneToMany classes while binding
+        Map<String, List<Object>> lists = new HashMap<String, List<Object>>();
 
         InputStreamReader in = new InputStreamReader(inputStream);
 
@@ -117,7 +121,7 @@ public class BindyKeyValuePairDataFormat
                 if (result.size() > 0) {
                     // Bind data from message with model classes
                     // Counter is used to detect line where error occurs
-                    factory.bind(result, model, count);
+                    factory.bind(result, model, count, lists);
 
                     // Link objects together
                     factory.link(model);

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest.java?rev=1154684&r1=1154683&r2=1154684&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest.java
(original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest.java
Sun Aug  7 10:31:56 2011
@@ -33,9 +33,11 @@ public class BindyComplexOneToManyKeyVal
 
         String message = "8=FIX 4.19=2034=135=049=INVMGR56=BRKR" + "1=BE.CHM.00111=CHM0001-0158=this
is a camel - bindy test" + "22=448=BE000124567854=1"
                          + "22=548=BE000987654354=2" + "22=648=BE000999999954=3" +
"10=220";
+        String message2 = "8=FIX 4.19=2034=135=049=INVMGR56=BRKR" + "1=BE.CHM.00111=CHM0001-0158=this
is a camel - bindy test10=220";
 
-        result.expectedMessageCount(1);
+        result.expectedMessageCount(2);
         template.sendBody(message);
+        template.sendBody(message2);
 
         result.assertIsSatisfied();
 



Mime
View raw message