camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1159326 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/ components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/
Date Thu, 18 Aug 2011 17:45:15 GMT
Author: davsclaus
Date: Thu Aug 18 17:45:15 2011
New Revision: 1159326

URL: http://svn.apache.org/viewvc?rev=1159326&view=rev
Log:
CAMEL-4352: Fixed issue with ftp consumer using done file and stepwise=true.

Added:
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedStepwiseTest.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedTest.java
      - copied, changed from r1159180, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameStepwiseTest.java
      - copied, changed from r1159180, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=1159326&r1=1159325&r2=1159326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
Thu Aug 18 17:45:15 2011
@@ -418,7 +418,7 @@ public abstract class GenericFileConsume
      *
      * @param file        the file
      * @param isDirectory whether the file is a directory or a file
-     * @return <tt>true</tt> if the remote file is matched, <tt>false</tt>
if not
+     * @return <tt>true</tt> if the file is matched, <tt>false</tt>
if not
      */
     protected boolean isMatched(GenericFile<T> file, boolean isDirectory) {
         String name = file.getFileNameOnly();
@@ -478,9 +478,7 @@ public abstract class GenericFileConsume
                 return false;
             }
 
-            // the file is only valid if the done file exist
-            if (!operations.existsFile(doneFileName)) {
-                log.trace("Done file: {} does not exist", doneFileName);
+            if (!isMatched(file, doneFileName)) {
                 return false;
             }
         }
@@ -489,6 +487,24 @@ public abstract class GenericFileConsume
     }
 
     /**
+     * Strategy to perform file matching based on endpoint configuration in terms of done
file name.
+     *
+     * @param file         the file
+     * @param doneFileName the done file name
+     * @return <tt>true</tt> if the file is matched, <tt>false</tt>
if not
+     */
+    protected boolean isMatched(GenericFile<T> file, String doneFileName) {
+        // the file is only valid if the done file exist
+        if (!operations.existsFile(doneFileName)) {
+            log.trace("Done file: {} does not exist", doneFileName);
+            return false;
+        }
+
+        // assume matched
+        return true;
+    }
+
+    /**
      * Is the given file already in progress.
      *
      * @param file the file

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java?rev=1159326&r1=1159325&r2=1159326&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
Thu Aug 18 17:45:15 2011
@@ -19,8 +19,10 @@ package org.apache.camel.component.file.
 import java.io.IOException;
 
 import org.apache.camel.Processor;
+import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.file.GenericFileConsumer;
 import org.apache.camel.component.file.GenericFileOperationFailedException;
+import org.apache.camel.util.FileUtil;
 
 /**
  * Base class for remote file consumers.
@@ -143,4 +145,15 @@ public abstract class RemoteFileConsumer
     protected String remoteServer() {
         return ((RemoteFileEndpoint) endpoint).remoteServerInformation();
     }
+
+    @Override
+    protected boolean isMatched(GenericFile<T> file, String doneFileName) {
+        // ftp specific as we need to cater for stepwise
+        if (getEndpoint().getConfiguration().isStepwise()) {
+            // stepwise enabled, so done file should always be without path
+            doneFileName = FileUtil.stripPath(doneFileName);
+        }
+
+        return super.isMatched(file, doneFileName);
+    }
 }

Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedStepwiseTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedStepwiseTest.java?rev=1159326&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedStepwiseTest.java
(added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedStepwiseTest.java
Thu Aug 18 17:45:15 2011
@@ -0,0 +1,28 @@
+/**
+ * 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.component.file.remote;
+
+/**
+ * @version 
+ */
+public class FtpConsumerDoneFileNameFixedStepwiseTest extends FtpConsumerDoneFileNameFixedTest
{
+
+    protected String getFtpUrl() {
+        return "ftp://admin@localhost:" + getPort() + "/done?password=admin&initialDelay=0&delay=100&stepwise=true";
+    }
+
+}

Copied: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedTest.java
(from r1159180, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java&r1=1159180&r2=1159326&rev=1159326&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameFixedTest.java
Thu Aug 18 17:45:15 2011
@@ -25,7 +25,7 @@ import org.junit.Test;
 /**
  * @version 
  */
-public class FtpConsumerDoneFileNameTest extends FtpServerTestSupport {
+public class FtpConsumerDoneFileNameFixedTest extends FtpServerTestSupport {
 
     protected String getFtpUrl() {
         return "ftp://admin@localhost:" + getPort() + "/done?password=admin&initialDelay=0&delay=100&stepwise=false";
@@ -47,7 +47,7 @@ public class FtpConsumerDoneFileNameTest
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
 
         // write the done file
-        template.sendBodyAndHeader(getFtpUrl(), "", Exchange.FILE_NAME, "done");
+        template.sendBodyAndHeader(getFtpUrl(), "", Exchange.FILE_NAME, "fin.dat");
 
         assertMockEndpointsSatisfied();
 
@@ -55,7 +55,7 @@ public class FtpConsumerDoneFileNameTest
         Thread.sleep(1000);
 
         // done file should be deleted now
-        File file = new File(FTP_ROOT_DIR + "done/done").getAbsoluteFile();
+        File file = new File(FTP_ROOT_DIR + "done/fin.dat").getAbsoluteFile();
         assertFalse("Done file should be deleted: " + file, file.exists());
     }
 
@@ -64,7 +64,7 @@ public class FtpConsumerDoneFileNameTest
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from(getFtpUrl() + "&doneFileName=done")
+                from(getFtpUrl() + "&doneFileName=fin.dat")
                     .convertBodyTo(String.class)
                     .to("mock:result");
             }

Copied: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameStepwiseTest.java
(from r1159180, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameStepwiseTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameStepwiseTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java&r1=1159180&r2=1159326&rev=1159326&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameStepwiseTest.java
Thu Aug 18 17:45:15 2011
@@ -16,59 +16,13 @@
  */
 package org.apache.camel.component.file.remote;
 
-import java.io.File;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
 /**
  * @version 
  */
-public class FtpConsumerDoneFileNameTest extends FtpServerTestSupport {
+public class FtpConsumerDoneFileNameStepwiseTest extends FtpConsumerDoneFileNameTest {
 
     protected String getFtpUrl() {
-        return "ftp://admin@localhost:" + getPort() + "/done?password=admin&initialDelay=0&delay=100&stepwise=false";
-    }
-
-    @Test
-    public void testDoneFileName() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(0);
-
-        template.sendBodyAndHeader(getFtpUrl(), "Hello World", Exchange.FILE_NAME, "hello.txt");
-
-        // wait a bit and it should not pickup the written file as there are no done file
-        Thread.sleep(1000);
-
-        assertMockEndpointsSatisfied();
-
-        resetMocks();
-
-        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
-
-        // write the done file
-        template.sendBodyAndHeader(getFtpUrl(), "", Exchange.FILE_NAME, "done");
-
-        assertMockEndpointsSatisfied();
-
-        // give time for done file to be deleted
-        Thread.sleep(1000);
-
-        // done file should be deleted now
-        File file = new File(FTP_ROOT_DIR + "done/done").getAbsoluteFile();
-        assertFalse("Done file should be deleted: " + file, file.exists());
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from(getFtpUrl() + "&doneFileName=done")
-                    .convertBodyTo(String.class)
-                    .to("mock:result");
-            }
-        };
+        return "ftp://admin@localhost:" + getPort() + "/done?password=admin&initialDelay=0&delay=100&stepwise=true";
     }
 
 }

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java?rev=1159326&r1=1159325&r2=1159326&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDoneFileNameTest.java
Thu Aug 18 17:45:15 2011
@@ -47,7 +47,7 @@ public class FtpConsumerDoneFileNameTest
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
 
         // write the done file
-        template.sendBodyAndHeader(getFtpUrl(), "", Exchange.FILE_NAME, "done");
+        template.sendBodyAndHeader(getFtpUrl(), "", Exchange.FILE_NAME, "hello.dat");
 
         assertMockEndpointsSatisfied();
 
@@ -55,7 +55,7 @@ public class FtpConsumerDoneFileNameTest
         Thread.sleep(1000);
 
         // done file should be deleted now
-        File file = new File(FTP_ROOT_DIR + "done/done").getAbsoluteFile();
+        File file = new File(FTP_ROOT_DIR + "done/hello.dat").getAbsoluteFile();
         assertFalse("Done file should be deleted: " + file, file.exists());
     }
 
@@ -64,7 +64,7 @@ public class FtpConsumerDoneFileNameTest
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from(getFtpUrl() + "&doneFileName=done")
+                from(getFtpUrl() + "&doneFileName=${file:name.noext}.dat")
                     .convertBodyTo(String.class)
                     .to("mock:result");
             }



Mime
View raw message