Repository: camel
Updated Branches:
  refs/heads/ftpfix 91f6eb36f -> 7d312e25c


Fixed camel-ftp to work with splitter loading the remote file content and not 
its directory listing


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

Branch: refs/heads/ftpfix
Commit: 2cc260d59bf633dae20fe20faeaffa9df1d43078
Parents: 91f6eb3
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed Sep 7 14:49:54 2016 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Sep 7 14:49:54 2016 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/camel/WrappedFile.java |  7 +++++
 .../org/apache/camel/util/ObjectHelper.java     | 10 ++++--
 .../file/remote/FtpConsumerFileSplitTest.java   | 33 ++++++--------------
 3 files changed, 24 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2cc260d5/camel-core/src/main/java/org/apache/camel/WrappedFile.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/WrappedFile.java 
b/camel-core/src/main/java/org/apache/camel/WrappedFile.java
index 856a15a..9b1d768 100644
--- a/camel-core/src/main/java/org/apache/camel/WrappedFile.java
+++ b/camel-core/src/main/java/org/apache/camel/WrappedFile.java
@@ -28,4 +28,11 @@ public interface WrappedFile<T> {
      */
     T getFile();
 
+    /**
+     * Gets the content of the file.
+     *
+     * @return the content of the file.
+     */
+    Object getBody();
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2cc260d5/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
index 1a18a4b..0f10eaf 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -1805,9 +1805,15 @@ public final class ObjectHelper {
      */
     public static Scanner getScanner(Exchange exchange, Object value) {
         if (value instanceof WrappedFile) {
-            // generic file is just a wrapper for the real file so call again 
with the real file
             WrappedFile<?> gf = (WrappedFile<?>) value;
-            return getScanner(exchange, gf.getFile());
+            Object body = gf.getBody();
+            if (body != null) {
+                // we have loaded the file content into the body so use that
+                value = body;
+            } else {
+                // generic file is just a wrapper for the real file so call 
again with the real file
+                return getScanner(exchange, gf.getFile());
+            }
         }
 
         String charset = exchange.getProperty(Exchange.CHARSET_NAME, 
String.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/2cc260d5/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
index 3f2bf76..6cba739 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
@@ -30,42 +30,27 @@ import org.junit.Test;
 public class FtpConsumerFileSplitTest extends FtpServerTestSupport {
 
     private String getFtpUrl() {
-        return "ftp://admin@localhost:"; + getPort() + 
"/incoming/?password=admin"
-                + "&recursive=false";
-    }
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        prepareFtpServer();
+        return "ftp://admin@localhost:"; + getPort() + 
"/incoming/?password=admin&delete=true";
     }
 
     @Test
     public void testFtpRoute() throws Exception {
         MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-        resultEndpoint.expectedMessageCount(3);
-        resultEndpoint.expectedBodiesReceived("line1","line2");
-        resultEndpoint.assertIsSatisfied();
-
-        // assert the file
-        File file = new File("target/ftptest/textexample.txt");
-        assertTrue("The text file should exists", file.exists());
-    }
+        resultEndpoint.expectedBodiesReceived("line1","line2","line3");
 
-    private void prepareFtpServer() throws Exception {
-        // prepares the FTP Server by creating a file on the server that we 
want to unit
-        // test that we can pool and store as a local file
         template.sendBodyAndHeader(getFtpUrl(), new 
File("src/test/data/ftptextfile/textexample.txt"), Exchange.FILE_NAME, 
"textexample.txt");
+
+        resultEndpoint.assertIsSatisfied();
     }
-    
+
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
                 from(getFtpUrl())
-                .log("${body}")
-                .split(body().tokenize("\n"))
-                .to("mock:result");
+                    .to("log:file")
+                    .split(body().tokenize("\n"))
+                        .to("log:line")
+                        .to("mock:result");
             }
         };
     }

Reply via email to