You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/06/26 11:52:48 UTC
svn commit: r958207 - 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/compone...
Author: davsclaus
Date: Sat Jun 26 09:52:48 2010
New Revision: 958207
URL: http://svn.apache.org/viewvc?rev=958207&view=rev
Log:
CAMEL-2860: Fixed issue with setting starting directory from URI on ftp component to be able to accept absolute path.
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerAbsolutePathTest.java
- copied, changed from r958186, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryAsAbsolutePathTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.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/RemoteFileConfiguration.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java?rev=958207&r1=958206&r2=958207&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java Sat Jun 26 09:52:48 2010
@@ -22,14 +22,17 @@ import org.apache.camel.util.FileUtil;
public class GenericFileConfiguration {
- private String directory;
+ protected String directory;
public boolean needToNormalize() {
return true;
}
public void configure(URI uri) {
- setDirectory(uri.getPath());
+ String path = uri.getPath();
+ // strip tailing slash which the uri path may append
+ path = FileUtil.stripFirstLeadingSeparator(path);
+ setDirectory(path);
}
public String getDirectory() {
@@ -47,9 +50,6 @@ public class GenericFileConfiguration {
if (this.directory == null) {
this.directory = "";
}
-
- // strip tailing slash
- this.directory = FileUtil.stripTrailingSeparator(this.directory);
}
public String toString() {
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=958207&r1=958206&r2=958207&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 Sat Jun 26 09:52:48 2010
@@ -90,6 +90,19 @@ public final class FileUtil {
}
/**
+ * Strip first leading separator
+ */
+ public static String stripFirstLeadingSeparator(String name) {
+ if (name == null) {
+ return null;
+ }
+ if (name.startsWith("/") || name.startsWith(File.separator)) {
+ name = name.substring(1);
+ }
+ return name;
+ }
+
+ /**
* Strip any trailing separators
*/
public static String stripTrailingSeparator(String 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=958207&r1=958206&r2=958207&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 Sat Jun 26 09:52:48 2010
@@ -37,8 +37,20 @@ public class FileUtilTest extends TestCa
assertEquals(null, FileUtil.stripLeadingSeparator(null));
assertEquals("foo", FileUtil.stripLeadingSeparator("foo"));
assertEquals("foo/bar", FileUtil.stripLeadingSeparator("foo/bar"));
- assertEquals("foo", FileUtil.stripLeadingSeparator("foo"));
+ assertEquals("foo/", FileUtil.stripLeadingSeparator("foo/"));
assertEquals("foo/bar", FileUtil.stripLeadingSeparator("/foo/bar"));
+ assertEquals("foo/bar", FileUtil.stripLeadingSeparator("//foo/bar"));
+ assertEquals("foo/bar", FileUtil.stripLeadingSeparator("///foo/bar"));
+ }
+
+ public void testStripFirstLeadingSeparator() {
+ assertEquals(null, FileUtil.stripFirstLeadingSeparator(null));
+ assertEquals("foo", FileUtil.stripFirstLeadingSeparator("foo"));
+ assertEquals("foo/bar", FileUtil.stripFirstLeadingSeparator("foo/bar"));
+ assertEquals("foo/", FileUtil.stripFirstLeadingSeparator("foo/"));
+ assertEquals("foo/bar", FileUtil.stripFirstLeadingSeparator("/foo/bar"));
+ assertEquals("/foo/bar", FileUtil.stripFirstLeadingSeparator("//foo/bar"));
+ assertEquals("//foo/bar", FileUtil.stripFirstLeadingSeparator("///foo/bar"));
}
public void testStripTrailingSeparator() {
@@ -47,8 +59,10 @@ public class FileUtilTest extends TestCa
assertEquals("foo/bar", FileUtil.stripTrailingSeparator("foo/bar"));
assertEquals("foo", FileUtil.stripTrailingSeparator("foo/"));
assertEquals("foo/bar", FileUtil.stripTrailingSeparator("foo/bar/"));
- assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar/"));
assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar"));
+ assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar/"));
+ assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar//"));
+ assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar///"));
}
public void testStripPath() {
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java?rev=958207&r1=958206&r2=958207&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java Sat Jun 26 09:52:48 2010
@@ -20,6 +20,7 @@ import java.net.URI;
import org.apache.camel.component.file.GenericFileConfiguration;
import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.ObjectHelper;
/**
* Configuration of the FTP server
@@ -55,15 +56,6 @@ public abstract class RemoteFileConfigur
setPort(uri.getPort());
}
- @Override
- public void setDirectory(String directory) {
- // let super do its work first
- super.setDirectory(directory);
-
- // for FTP we must not start with a / root, so skip it if its there
- super.setDirectory(FileUtil.stripLeadingSeparator(getDirectory()));
- }
-
/**
* Returns human readable server information for logging purpose
*/
Copied: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerAbsolutePathTest.java (from r958186, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryAsAbsolutePathTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerAbsolutePathTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerAbsolutePathTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryAsAbsolutePathTest.java&r1=958186&r2=958207&rev=958207&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryAsAbsolutePathTest.java (original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerAbsolutePathTest.java Sat Jun 26 09:52:48 2010
@@ -16,59 +16,39 @@
*/
package org.apache.camel.component.file.remote;
-import java.io.File;
-
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
-import org.apache.camel.util.FileUtil;
import org.junit.Before;
import org.junit.Test;
/**
* @version $Revision$
*/
-public class FtpConsumerLocalWorkDirectoryAsAbsolutePathTest extends FtpServerTestSupport {
-
- private String base;
+public class FtpConsumerAbsolutePathTest extends FtpServerTestSupport {
protected String getFtpUrl() {
- base = new File("target/lwd").getAbsolutePath();
- return "ftp://admin@localhost:" + getPort() + "/lwd/?password=admin&delay=5000&noop=true&localWorkDirectory=" + base;
+ return "ftp://admin@localhost:" + getPort() + "///foo?password=admin&delay=5000";
}
@Override
@Before
public void setUp() throws Exception {
deleteDirectory("target/lwd");
- deleteDirectory("target/out");
super.setUp();
prepareFtpServer();
}
@Test
- public void testLocalWorkDirectory() throws Exception {
+ public void testAbsolutePath() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
mock.expectedMessageCount(1);
assertMockEndpointsSatisfied();
-
- // give test some time to close file resources
- Thread.sleep(6000);
-
- // now the lwd file should be deleted
- File local = new File("target/lwd/hello.txt").getAbsoluteFile();
- assertFalse("Local work file should have been deleted", local.exists());
-
- // and the out file should exists
- File out = new File("target/out/hello.txt").getAbsoluteFile();
- assertTrue("file should exists", out.exists());
- assertEquals("Hello World", IOConverter.toString(out, null));
}
private void prepareFtpServer() throws Exception {
@@ -83,19 +63,16 @@ public class FtpConsumerLocalWorkDirecto
producer.process(exchange);
producer.stop();
}
-
+
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from(getFtpUrl()).process(new Processor() {
public void process(Exchange exchange) throws Exception {
- File body = exchange.getIn().getBody(File.class);
- assertNotNull(body);
- assertTrue("Should be absolute path", body.isAbsolute());
- assertTrue("Local work file should exists", body.exists());
- assertEquals(FileUtil.normalizePath(base + "/hello.txt"), body.getPath());
+ String body = exchange.getIn().getBody(String.class);
+ assertEquals("Hello World", body);
}
- }).to("mock:result", "file://target/out");
+ }).to("mock:result");
}
};
}
Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java?rev=958207&r1=958206&r2=958207&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java (original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java Sat Jun 26 09:52:48 2010
@@ -141,36 +141,36 @@ public class UriConfigurationTest extend
@Test
public void testRemoteFileEndpointFiles() {
assertRemoteFileEndpointFile("ftp://hostname/foo/bar", "foo/bar");
- assertRemoteFileEndpointFile("ftp://hostname/foo/bar/", "foo/bar");
- assertRemoteFileEndpointFile("ftp://hostname/foo/", "foo");
+ assertRemoteFileEndpointFile("ftp://hostname/foo/bar/", "foo/bar/");
+ assertRemoteFileEndpointFile("ftp://hostname/foo/", "foo/");
assertRemoteFileEndpointFile("ftp://hostname/foo", "foo");
assertRemoteFileEndpointFile("ftp://hostname/", "");
assertRemoteFileEndpointFile("ftp://hostname", "");
- assertRemoteFileEndpointFile("ftp://hostname//", "");
- assertRemoteFileEndpointFile("ftp://hostname//foo/bar", "foo/bar");
- assertRemoteFileEndpointFile("ftp://hostname//foo/bar/", "foo/bar");
- assertRemoteFileEndpointFile("sftp://user@hostname:123//foo/bar?password=secret", "foo/bar");
+ assertRemoteFileEndpointFile("ftp://hostname//", "/");
+ assertRemoteFileEndpointFile("ftp://hostname//foo/bar", "/foo/bar");
+ assertRemoteFileEndpointFile("ftp://hostname//foo/bar/", "/foo/bar/");
+ assertRemoteFileEndpointFile("sftp://user@hostname:123//foo/bar?password=secret", "/foo/bar");
assertRemoteFileEndpointFile("sftp://user@hostname:123?password=secret", "");
assertRemoteFileEndpointFile("sftp://hostname/foo/bar", "foo/bar");
- assertRemoteFileEndpointFile("sftp://hostname/foo/bar/", "foo/bar");
- assertRemoteFileEndpointFile("sftp://hostname/foo/", "foo");
+ assertRemoteFileEndpointFile("sftp://hostname/foo/bar/", "foo/bar/");
+ assertRemoteFileEndpointFile("sftp://hostname/foo/", "foo/");
assertRemoteFileEndpointFile("sftp://hostname/foo", "foo");
assertRemoteFileEndpointFile("sftp://hostname/", "");
assertRemoteFileEndpointFile("sftp://hostname", "");
- assertRemoteFileEndpointFile("sftp://hostname//", "");
- assertRemoteFileEndpointFile("sftp://hostname//foo/bar", "foo/bar");
- assertRemoteFileEndpointFile("sftp://hostname//foo/bar/", "foo/bar");
- assertRemoteFileEndpointFile("ftps://user@hostname:123//foo/bar?password=secret", "foo/bar");
+ assertRemoteFileEndpointFile("sftp://hostname//", "/");
+ assertRemoteFileEndpointFile("sftp://hostname//foo/bar", "/foo/bar");
+ assertRemoteFileEndpointFile("sftp://hostname//foo/bar/", "/foo/bar/");
+ assertRemoteFileEndpointFile("ftps://user@hostname:123//foo/bar?password=secret", "/foo/bar");
assertRemoteFileEndpointFile("ftps://user@hostname:123?password=secret", "");
assertRemoteFileEndpointFile("ftps://hostname/foo/bar", "foo/bar");
- assertRemoteFileEndpointFile("ftps://hostname/foo/bar/", "foo/bar");
- assertRemoteFileEndpointFile("ftps://hostname/foo/", "foo");
+ assertRemoteFileEndpointFile("ftps://hostname/foo/bar/", "foo/bar/");
+ assertRemoteFileEndpointFile("ftps://hostname/foo/", "foo/");
assertRemoteFileEndpointFile("ftps://hostname/foo", "foo");
assertRemoteFileEndpointFile("ftps://hostname/", "");
assertRemoteFileEndpointFile("ftps://hostname", "");
- assertRemoteFileEndpointFile("ftps://hostname//", "");
- assertRemoteFileEndpointFile("ftps://hostname//foo/bar", "foo/bar");
- assertRemoteFileEndpointFile("ftps://hostname//foo/bar/", "foo/bar");
+ assertRemoteFileEndpointFile("ftps://hostname//", "/");
+ assertRemoteFileEndpointFile("ftps://hostname//foo/bar", "/foo/bar");
+ assertRemoteFileEndpointFile("ftps://hostname//foo/bar/", "/foo/bar/");
}
private void assertRemoteFileEndpointFile(String endpointUri, String expectedFile) {