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:58:16 GMT
CAMEL-7409 Camel ZipIterator should not eat up the IOException

Conflicts:
	components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java


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

Branch: refs/heads/camel-2.12.x
Commit: 7354064ddbc0f06a3ba711d5abef8f685fa59c4f
Parents: 7f28056
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:57:52 2014 +0800

----------------------------------------------------------------------
 .../camel/dataformat/zipfile/ZipIterator.java   |  11 +--
 .../zipfile/ZipSplitterRouteIssueTest.java      |  69 +++++++++++++++++++
 .../camel-zipfile/src/test/resources/data.zip   | Bin 0 -> 540 bytes
 3 files changed, 76 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7354064d/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/7354064d/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
new file mode 100644
index 0000000..6f5dacb
--- /dev/null
+++ b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipSplitterRouteIssueTest.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dataformat.zipfile;
+
+import java.io.File;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ZipSplitterRouteIssueTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/zip");
+        super.setUp();
+    }
+
+    @Test
+    public void testSplitter() throws Exception {
+        getMockEndpoint("mock:entry").expectedMessageCount(2);
+
+        template.sendBody("seda:decompressFiles", new File("src/test/resources/data.zip"));
+
+        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");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7354064d/components/camel-zipfile/src/test/resources/data.zip
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/test/resources/data.zip b/components/camel-zipfile/src/test/resources/data.zip
new file mode 100644
index 0000000..fa6e598
Binary files /dev/null and b/components/camel-zipfile/src/test/resources/data.zip differ


Mime
View raw message