This is an automated email from the ASF dual-hosted git repository.

onders pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f4ae859e17552d26c053da1df30855ac1b2c4534
Author: onders <ond...@apache.org>
AuthorDate: Tue Aug 14 23:27:35 2018 +0300

    CAMEL-12723 - support IPV6 in FTP components
---
 .../camel/component/file/remote/FtpComponent.java  |  6 +--
 .../camel/component/file/remote/FtpsComponent.java |  6 +--
 .../camel/component/file/remote/SftpComponent.java | 12 +----
 .../FileToFtpsWithDefaultSettingsIPV6Test.java     | 56 ++++++++++++++++++++
 .../remote/sftp/SftpSimpleIPV6ConsumeTest.java     | 61 ++++++++++++++++++++++
 5 files changed, 120 insertions(+), 21 deletions(-)

diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
index 326d534..35d5b54 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
@@ -40,11 +40,7 @@ public class FtpComponent extends 
RemoteFileComponent<FTPFile> {
 
     @Override
     protected GenericFileEndpoint<FTPFile> buildFileEndpoint(String uri, 
String remaining, Map<String, Object> parameters) throws Exception {
-        String baseUri = getBaseUri(uri);
-
-        // lets make sure we create a new configuration as each endpoint can 
customize its own version
-        // must pass on baseUri to the configuration (see above)
-        FtpConfiguration config = new FtpConfiguration(new URI(baseUri));
+        FtpConfiguration config = new FtpConfiguration(new 
URI(uri.substring(0, uri.indexOf(":") + 1) + "//" + remaining));
 
         FtpUtils.ensureRelativeFtpDirectory(this, config);
 
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java
index 60c9125..70715d0 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java
@@ -49,11 +49,7 @@ public class FtpsComponent extends FtpComponent implements 
SSLContextParametersA
 
     @Override
     protected GenericFileEndpoint<FTPFile> buildFileEndpoint(String uri, 
String remaining, Map<String, Object> parameters) throws Exception {
-        String baseUri = getBaseUri(uri);
-
-        // lets make sure we create a new configuration as each endpoint can 
customize its own version
-        // must pass on baseUri to the configuration (see above)
-        FtpsConfiguration config = new FtpsConfiguration(new URI(baseUri));
+        FtpsConfiguration config = new FtpsConfiguration(new 
URI(uri.substring(0, uri.indexOf(":") + 1) + "//" + remaining));
 
         FtpUtils.ensureRelativeFtpDirectory(this, config);
 
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java
index a018b87..f7262c2 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java
@@ -38,17 +38,7 @@ public class SftpComponent extends 
RemoteFileComponent<SftpRemoteFile> {
 
     @Override
     protected GenericFileEndpoint<SftpRemoteFile> buildFileEndpoint(String 
uri, String remaining, Map<String, Object> parameters) throws Exception {
-        // 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
-        // to escape the $ for the expression (file language)
-        String baseUri = uri;
-        if (uri.contains("?")) {
-            baseUri = uri.substring(0, uri.indexOf("?"));
-        }
-
-        // lets make sure we create a new configuration as each endpoint can
-        // customize its own version
-        SftpConfiguration config = new SftpConfiguration(new URI(baseUri));
+        SftpConfiguration config = new SftpConfiguration(new 
URI(uri.substring(0, uri.indexOf(":") + 1) + "//" + remaining));
 
         FtpUtils.ensureRelativeFtpDirectory(this, config);
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FileToFtpsWithDefaultSettingsIPV6Test.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FileToFtpsWithDefaultSettingsIPV6Test.java
new file mode 100644
index 0000000..666dbca
--- /dev/null
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FileToFtpsWithDefaultSettingsIPV6Test.java
@@ -0,0 +1,56 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * Test the ftps component over TLS (explicit) and without client 
authentication
+ * 
+ * @version 
+ */
+public class FileToFtpsWithDefaultSettingsIPV6Test extends 
FtpsServerExplicitTLSWithoutClientAuthTestSupport {
+    
+    private String getFtpUrl() {
+        return "ftps://admin@[::1]:" + getPort() + 
"/tmp2/camel?password=admin&consumer.initialDelay=2000&disableSecureDataChannelDefaults=true&delete=true";
+    }
+    
+    @Test
+    public void testFromFileToFtp() throws Exception {
+        // some platforms cannot test SSL
+        if (!canTest) {
+            return;
+        }
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("file:src/main/data?noop=true").log("Got 
${file:name}").to(getFtpUrl());
+
+                from(getFtpUrl()).to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleIPV6ConsumeTest.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleIPV6ConsumeTest.java
new file mode 100644
index 0000000..175f3a3
--- /dev/null
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleIPV6ConsumeTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.sftp;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class SftpSimpleIPV6ConsumeTest extends SftpServerTestSupport {
+
+    @Test
+    public void testSftpSimpleConsume() throws Exception {
+        if (!canTest()) {
+            return;
+        }
+
+        String expected = "Hello World";
+
+        // create file using regular file
+        template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, 
Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
+        mock.expectedBodiesReceived(expected);
+        
+        context.startRoute("foo");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("sftp://[::1]:"; + getPort() + "/" + FTP_ROOT_DIR + 
"?username=admin&password=admin&delay=10s&disconnect=true")
+                    .routeId("foo").noAutoStartup()
+                    .to("mock:result");
+            }
+        };
+    }
+}

Reply via email to