You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/05/06 11:07:02 UTC

[1/4] git commit: CAMEL-7415 fixed the issue that lazyLoad with CSV blows up on last line

Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x 7354064dd -> f001fcae3
  refs/heads/camel-2.13.x a032bc143 -> 77be8b49f


CAMEL-7415 fixed the issue that lazyLoad with CSV blows up on last line


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/738002ec
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/738002ec
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/738002ec

Branch: refs/heads/camel-2.12.x
Commit: 738002ec6af73a46ada5c5ab5d395d669b8395d9
Parents: 7354064
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue May 6 14:59:57 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue May 6 16:50:45 2014 +0800

----------------------------------------------------------------------
 .../camel/processor/UnmarshalProcessor.java     | 10 ++++--
 .../dataformat/csv/CsvUnmarshalStreamTest.java  | 38 ++++++++++++++++++++
 2 files changed, 45 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/738002ec/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
index c248fe1..934fd2a 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
@@ -17,6 +17,7 @@
 package org.apache.camel.processor;
 
 import java.io.InputStream;
+import java.util.Iterator;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.AsyncProcessor;
@@ -55,6 +56,7 @@ public class UnmarshalProcessor extends ServiceSupport implements AsyncProcessor
         ObjectHelper.notNull(dataFormat, "dataFormat");
 
         InputStream stream = null;
+        Object result = null;
         try {
             stream = exchange.getIn().getMandatoryBody(InputStream.class);
 
@@ -62,7 +64,7 @@ public class UnmarshalProcessor extends ServiceSupport implements AsyncProcessor
             Message out = exchange.getOut();
             out.copyFrom(exchange.getIn());
 
-            Object result = dataFormat.unmarshal(exchange, stream);
+            result = dataFormat.unmarshal(exchange, stream);
             if (result instanceof Exchange) {
                 if (result != exchange) {
                     // it's not allowed to return another exchange other than the one provided to dataFormat
@@ -79,9 +81,11 @@ public class UnmarshalProcessor extends ServiceSupport implements AsyncProcessor
             exchange.setOut(null);
             exchange.setException(e);
         } finally {
-            IOHelper.close(stream, "input stream");
+            // The Iterator will close the stream itself
+            if (!(result instanceof Iterator)) {
+                IOHelper.close(stream, "input stream");
+            }
         }
-
         callback.done(true);
         return true;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/738002ec/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
index 355cd1e..f41a570 100644
--- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
+++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.dataformat.csv;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.camel.EndpointInject;
@@ -38,6 +42,7 @@ public class CsvUnmarshalStreamTest extends CamelTestSupport {
     @SuppressWarnings("unchecked")
     @Test
     public void testCsvUnMarshal() throws Exception {
+        result.reset();
         result.expectedMessageCount(EXPECTED_COUNT);
 
         String message = "";
@@ -58,6 +63,39 @@ public class CsvUnmarshalStreamTest extends CamelTestSupport {
         }
     }
     
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testCsvUnMarshalWithFile() throws Exception {
+        result.reset();
+        result.expectedMessageCount(EXPECTED_COUNT);
+
+        
+        template.sendBody("direct:start", new MyFileInputStream(new File("src/test/resources/data.csv")));
+
+        assertMockEndpointsSatisfied();
+
+        for (int i = 0; i < EXPECTED_COUNT; ++i) {
+            List<String> body = result.getReceivedExchanges().get(i)
+                    .getIn().getBody(List.class);
+            assertEquals(2, body.size());
+            assertEquals(String.valueOf(i), body.get(0));
+            assertEquals(String.format("%d\n%d", i, i), body.get(1));
+        }
+    }
+    
+    class MyFileInputStream extends FileInputStream {
+
+        public MyFileInputStream(File file) throws FileNotFoundException {
+            super(file);
+        }
+        
+        public void close() throws IOException {
+            // Use this to find out how camel close the FileInputStream
+            super.close();
+        }
+        
+    }
+    
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {


[3/4] git commit: CAMEL-7415 Added the missing file of data.csv

Posted by ni...@apache.org.
CAMEL-7415 Added the missing file of data.csv


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/77be8b49
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/77be8b49
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/77be8b49

Branch: refs/heads/camel-2.13.x
Commit: 77be8b49f0d73136920adb40785b0988962dec49
Parents: 6275600
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue May 6 17:04:37 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue May 6 17:06:12 2014 +0800

----------------------------------------------------------------------
 components/camel-csv/src/test/resources/data.csv | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/77be8b49/components/camel-csv/src/test/resources/data.csv
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/resources/data.csv b/components/camel-csv/src/test/resources/data.csv
new file mode 100644
index 0000000..241a679
--- /dev/null
+++ b/components/camel-csv/src/test/resources/data.csv
@@ -0,0 +1,6 @@
+0|"0
+0"
+1|"1
+1"
+2|"2
+2"
\ No newline at end of file


[4/4] git commit: CAMEL-7415 Added the missing file of data.csv

Posted by ni...@apache.org.
CAMEL-7415 Added the missing file of data.csv


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f001fcae
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f001fcae
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f001fcae

Branch: refs/heads/camel-2.12.x
Commit: f001fcae3dfa782139cb3d20ce3d9b241d69af5f
Parents: 738002e
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue May 6 17:04:37 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue May 6 17:06:24 2014 +0800

----------------------------------------------------------------------
 components/camel-csv/src/test/resources/data.csv | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f001fcae/components/camel-csv/src/test/resources/data.csv
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/resources/data.csv b/components/camel-csv/src/test/resources/data.csv
new file mode 100644
index 0000000..241a679
--- /dev/null
+++ b/components/camel-csv/src/test/resources/data.csv
@@ -0,0 +1,6 @@
+0|"0
+0"
+1|"1
+1"
+2|"2
+2"
\ No newline at end of file


[2/4] git commit: CAMEL-7415 fixed the issue that lazyLoad with CSV blows up on last line

Posted by ni...@apache.org.
CAMEL-7415 fixed the issue that lazyLoad with CSV blows up on last line


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/62756005
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/62756005
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/62756005

Branch: refs/heads/camel-2.13.x
Commit: 6275600501d3a7967606c0e91b42dcb802e27324
Parents: a032bc1
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue May 6 14:59:57 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue May 6 17:05:57 2014 +0800

----------------------------------------------------------------------
 .../camel/processor/UnmarshalProcessor.java     | 10 ++++--
 .../dataformat/csv/CsvUnmarshalStreamTest.java  | 38 ++++++++++++++++++++
 2 files changed, 45 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/62756005/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
index c248fe1..934fd2a 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
@@ -17,6 +17,7 @@
 package org.apache.camel.processor;
 
 import java.io.InputStream;
+import java.util.Iterator;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.AsyncProcessor;
@@ -55,6 +56,7 @@ public class UnmarshalProcessor extends ServiceSupport implements AsyncProcessor
         ObjectHelper.notNull(dataFormat, "dataFormat");
 
         InputStream stream = null;
+        Object result = null;
         try {
             stream = exchange.getIn().getMandatoryBody(InputStream.class);
 
@@ -62,7 +64,7 @@ public class UnmarshalProcessor extends ServiceSupport implements AsyncProcessor
             Message out = exchange.getOut();
             out.copyFrom(exchange.getIn());
 
-            Object result = dataFormat.unmarshal(exchange, stream);
+            result = dataFormat.unmarshal(exchange, stream);
             if (result instanceof Exchange) {
                 if (result != exchange) {
                     // it's not allowed to return another exchange other than the one provided to dataFormat
@@ -79,9 +81,11 @@ public class UnmarshalProcessor extends ServiceSupport implements AsyncProcessor
             exchange.setOut(null);
             exchange.setException(e);
         } finally {
-            IOHelper.close(stream, "input stream");
+            // The Iterator will close the stream itself
+            if (!(result instanceof Iterator)) {
+                IOHelper.close(stream, "input stream");
+            }
         }
-
         callback.done(true);
         return true;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/62756005/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
index 355cd1e..f41a570 100644
--- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
+++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.dataformat.csv;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.camel.EndpointInject;
@@ -38,6 +42,7 @@ public class CsvUnmarshalStreamTest extends CamelTestSupport {
     @SuppressWarnings("unchecked")
     @Test
     public void testCsvUnMarshal() throws Exception {
+        result.reset();
         result.expectedMessageCount(EXPECTED_COUNT);
 
         String message = "";
@@ -58,6 +63,39 @@ public class CsvUnmarshalStreamTest extends CamelTestSupport {
         }
     }
     
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testCsvUnMarshalWithFile() throws Exception {
+        result.reset();
+        result.expectedMessageCount(EXPECTED_COUNT);
+
+        
+        template.sendBody("direct:start", new MyFileInputStream(new File("src/test/resources/data.csv")));
+
+        assertMockEndpointsSatisfied();
+
+        for (int i = 0; i < EXPECTED_COUNT; ++i) {
+            List<String> body = result.getReceivedExchanges().get(i)
+                    .getIn().getBody(List.class);
+            assertEquals(2, body.size());
+            assertEquals(String.valueOf(i), body.get(0));
+            assertEquals(String.format("%d\n%d", i, i), body.get(1));
+        }
+    }
+    
+    class MyFileInputStream extends FileInputStream {
+
+        public MyFileInputStream(File file) throws FileNotFoundException {
+            super(file);
+        }
+        
+        public void close() throws IOException {
+            // Use this to find out how camel close the FileInputStream
+            super.close();
+        }
+        
+    }
+    
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {