camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7409 Camel ZipIterator should not eat up the IOException
Date Mon, 05 May 2014 02:40:54 GMT
CAMEL-7409 Camel ZipIterator should not eat up the IOException


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

Branch: refs/heads/master
Commit: 37fdb57c85748b125158500f29342cd89fc612d9
Parents: 8b78f5c
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon May 5 10:36:48 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon May 5 10:40:14 2014 +0800

----------------------------------------------------------------------
 .../camel/dataformat/zipfile/ZipIterator.java      | 11 +++++++----
 .../zipfile/ZipSplitterRouteIssueTest.java         | 17 +++++++++++++++--
 2 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/37fdb57c/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
index dc8b714..d54029e 100644
--- a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
+++ b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
@@ -25,6 +25,7 @@ import java.util.zip.ZipInputStream;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultMessage;
 import org.apache.camel.util.IOHelper;
 import org.slf4j.Logger;
@@ -70,9 +71,9 @@ class ZipIterator implements Iterator<Message> {
                 }                
             }
             return availableDataInCurrentEntry;            
-        } catch (IOException e) {
-            LOGGER.warn("Fail hasNext()", e);
-            return false;            
+        } catch (IOException exception) {
+            //Just wrap the IOException as CamelRuntimeException
+            throw new RuntimeCamelException(exception);      
         }
     }
 
@@ -106,7 +107,9 @@ class ZipIterator implements Iterator<Message> {
                 } else {
                     LOGGER.trace("close zipInputStream");
                 }
-            } catch (IOException ignore) {
+            } catch (IOException exception) {
+                //Just wrap the IOException as CamelRuntimeException
+                throw new RuntimeCamelException(exception);
             }
         }        
         

http://git-wip-us.apache.org/repos/asf/camel/blob/37fdb57c/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
index 8e69e57..6f5dacb 100644
--- a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
+++ b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
@@ -38,17 +38,30 @@ public class ZipSplitterRouteIssueTest extends CamelTestSupport {
 
         assertMockEndpointsSatisfied();
     }
+    
+    @Test
+    public void testSplitterWithWrongFile() throws Exception {
+        getMockEndpoint("mock:entry").expectedMessageCount(0);
+        getMockEndpoint("mock:errors").expectedMessageCount(1);
+        //Send a file which is not exit
+        template.sendBody("seda:decompressFiles", new File("src/test/resources/data"));
+        
+        assertMockEndpointsSatisfied();
+        
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:errors"));
+                
                 from("seda:decompressFiles")
                     .split(new ZipSplitter()).streaming().shareUnitOfWork()
                         .log("we are splitting")
-                        .to("mock:entry")
-                        .to("file:target/zip/?fileName=decompressed.txt&fileExist=Append");
+                        .to("mock:entry");
+                        //.to("file:target/zip/?fileName=decompressed.txt&fileExist=Append");
             }
         };
     }


Mime
View raw message