camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1226387 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/util/ components/camel-ftp/src/main/java/org/apache/camel/compon...
Date Mon, 02 Jan 2012 10:47:53 GMT
Author: davsclaus
Date: Mon Jan  2 10:47:53 2012
New Revision: 1226387

URL: http://svn.apache.org/viewvc?rev=1226387&view=rev
Log:
CAMEL-4850: Fixed NPE in ftp consumer if using empty starting directory with just two slashes.

Added:
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpTwoSlashesIssueTest.java
      - copied, changed from r1226365, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDeleteFileTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=1226387&r1=1226386&r2=1226387&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Mon Jan  2 10:47:53 2012
@@ -279,7 +279,12 @@ public class GenericFile<T> implements W
             parent = path.getParent();
         } else {
             String name = getRelativeFilePath();
-            File path = new File(endpointPath, name);
+            File path;
+            if (name != null) {
+                path = new File(endpointPath, name);
+            } else {
+                path = new File(endpointPath);
+            }
             parent = path.getParent();
         }
         return normalizePathToProtocol(parent);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java?rev=1226387&r1=1226386&r2=1226387&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java Mon Jan  2 10:47:53
2012
@@ -130,13 +130,25 @@ public final class FileUtil {
      * Strip any trailing separators
      */
     public static String stripTrailingSeparator(String name) {
-        if (name == null) {
-            return null;
+        if (ObjectHelper.isEmpty(name)) {
+            return name;
         }
-        while (name.endsWith("/") || name.endsWith(File.separator)) {
-            name = name.substring(0, name.length() - 1);
+        
+        String s = name;
+        
+        // there must be some leading text, as we should only remove trailing separators

+        while (s.endsWith("/") || s.endsWith(File.separator)) {
+            s = s.substring(0, s.length() - 1);
+        }
+        
+        // if the string is empty, that means there was only trailing slashes, and no leading
text
+        // and so we should then return the original name as is
+        if (ObjectHelper.isEmpty(s)) {
+            return name;
+        } else {
+            // return without trailing slashes
+            return s;
         }
-        return name;
     }
 
     /**

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java?rev=1226387&r1=1226386&r2=1226387&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java Mon Jan 
2 10:47:53 2012
@@ -75,6 +75,11 @@ public class FileUtilTest extends TestCa
         assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar/"));
         assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar//"));
         assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar///"));
+
+        assertEquals("/foo", FileUtil.stripTrailingSeparator("/foo"));
+        assertEquals("/foo", FileUtil.stripTrailingSeparator("/foo/"));
+        assertEquals("/", FileUtil.stripTrailingSeparator("/"));
+        assertEquals("//", FileUtil.stripTrailingSeparator("//"));
     }
 
     public void testStripPath() {

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java?rev=1226387&r1=1226386&r2=1226387&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
Mon Jan  2 10:47:53 2012
@@ -52,8 +52,8 @@ public class FtpComponent extends Remote
     }
 
     /**
-     * get the base uri part before the options as they can be non URI valid such as the
expression using $ chars
-     * and the URI constructor will regard $ as an illegal character and we dont want to
enforce end users to
+     * Get the base uri part before the options as they can be non URI valid such as the
expression using $ chars
+     * and the URI constructor will regard $ as an illegal character and we don't want to
enforce end users to
      * to escape the $ for the expression (file language)
      */
     protected String getBaseUri(String uri) {

Copied: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpTwoSlashesIssueTest.java
(from r1226365, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDeleteFileTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpTwoSlashesIssueTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpTwoSlashesIssueTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDeleteFileTest.java&r1=1226365&r2=1226387&rev=1226387&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDeleteFileTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpTwoSlashesIssueTest.java
Mon Jan  2 10:47:53 2012
@@ -27,12 +27,12 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Unit test to test delete option.
+ * Issue with using 2 slashes
  */
-public class FromFtpDeleteFileTest extends FtpServerTestSupport {
+public class FromFtpTwoSlashesIssueTest extends FtpServerTestSupport {
 
     protected String getFtpUrl() {
-        return "ftp://admin@localhost:" + getPort() + "/deletefile?password=admin&binary=false&delete=true";
+        return "ftp://admin@localhost:" + getPort() + "//?password=admin";
     }
 
     @Override
@@ -45,17 +45,9 @@ public class FromFtpDeleteFileTest exten
     @Test
     public void testPollFileAndShouldBeDeleted() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("Hello World this file will be deleted");
+        mock.expectedBodiesReceived("Hello World");
 
         mock.assertIsSatisfied();
-
-        Thread.sleep(500);
-
-        // assert the file is deleted
-        File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt");
-        file = file.getAbsoluteFile();
-        assertFalse("The file should have been deleted", file.exists());
     }
 
     private void prepareFtpServer() throws Exception {
@@ -63,7 +55,7 @@ public class FromFtpDeleteFileTest exten
         // test that we can pool and store as a local file
         Endpoint endpoint = context.getEndpoint(getFtpUrl());
         Exchange exchange = endpoint.createExchange();
-        exchange.getIn().setBody("Hello World this file will be deleted");
+        exchange.getIn().setBody("Hello World");
         exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
         Producer producer = endpoint.createProducer();
         producer.start();
@@ -71,7 +63,7 @@ public class FromFtpDeleteFileTest exten
         producer.stop();
 
         // assert file is created
-        File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt");
+        File file = new File(FTP_ROOT_DIR + "/hello.txt");
         file = file.getAbsoluteFile();
         assertTrue("The file should exists", file.exists());
     }



Mime
View raw message