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 2016/08/16 11:51:23 UTC

[1/3] camel git commit: CAMEL-10246: camel-ftp - Add support for configuring active port range

Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 7891367b1 -> 2fa4fd030
  refs/heads/master 813d17c81 -> d4fa3c55c


CAMEL-10246: camel-ftp - Add support for configuring active port range


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

Branch: refs/heads/master
Commit: 6645583a991dc1dc5577191f20b018bee3e3e184
Parents: 813d17c
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Aug 16 13:39:51 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Aug 16 13:39:51 2016 +0200

----------------------------------------------------------------------
 .../camel-ftp/src/main/docs/ftp-component.adoc  |  5 +-
 .../component/file/remote/FtpConfiguration.java | 15 +++++
 .../component/file/remote/FtpEndpoint.java      | 13 ++++
 .../file/remote/FromFtpActivePortRangeTest.java | 70 ++++++++++++++++++++
 4 files changed, 102 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6645583a/components/camel-ftp/src/main/docs/ftp-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/docs/ftp-component.adoc b/components/camel-ftp/src/main/docs/ftp-component.adoc
index 28be641..702a2d0 100644
--- a/components/camel-ftp/src/main/docs/ftp-component.adoc
+++ b/components/camel-ftp/src/main/docs/ftp-component.adoc
@@ -117,8 +117,9 @@ The FTP component has no options.
 
 
 
+
 // endpoint options: START
-The FTP component supports 103 endpoint options which are listed below:
+The FTP component supports 104 endpoint options which are listed below:
 
 {% raw %}
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
@@ -167,6 +168,7 @@ The FTP component supports 103 endpoint options which are listed below:
 | eagerDeleteTargetFile | producer (advanced) | true | boolean | Whether or not to eagerly delete any existing target file. This option only applies when you use fileExists=Override and the tempFileName option as well. You can use this to disable (set it to false) deleting the target file before the temp file is written. For example you may write big files and want the target file to exists during the temp file is being written. This ensure the target file is only deleted until the very last moment just before the temp file is being renamed to the target filename. This option is also used to control whether to delete any existing files when fileExist=Move is enabled and an existing file exists. If this option copyAndDeleteOnRenameFails false then an exception will be thrown if an existing file existed if its true then the existing file is deleted before the move operation.
 | keepLastModified | producer (advanced) | false | boolean | Will keep the last modified timestamp from the source file (if any). Will use the Exchange.FILE_LAST_MODIFIED header to located the timestamp. This header can contain either a java.util.Date or long with the timestamp. If the timestamp exists and the option is enabled it will set this timestamp on the written file. Note: This option only applies to the file producer. You cannot use this option with any of the ftp producers.
 | sendNoop | producer (advanced) | true | boolean | Whether to send a noop command as a pre-write check before uploading files to the FTP server. This is enabled by default as a validation of the connection is still valid which allows to silently re-connect to be able to upload the file. However if this causes problems you can turn this option off.
+| activePortRange | advanced |  | String | Set the client side port range in active mode. The syntax is: minPort-maxPort Both port numbers are inclusive eg 10000-19999 to include all 1xxxx ports.
 | autoCreate | advanced | true | boolean | Automatically create missing directories in the file's pathname. For the file consumer that means creating the starting directory. For the file producer it means the directory the files should be written to.
 | bufferSize | advanced | 131072 | int | Write buffer sized in bytes.
 | connectTimeout | advanced | 10000 | int | Sets the connect timeout for waiting for a connection to be established Used by both FTPClient and JSCH
@@ -239,6 +241,7 @@ The FTP component supports 103 endpoint options which are listed below:
 
 
 
+
 [Info]
 ====
 FTPS component default trust store

http://git-wip-us.apache.org/repos/asf/camel/blob/6645583a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java
index 85fcb2f..876f027 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java
@@ -31,6 +31,8 @@ public class FtpConfiguration extends RemoteFileConfiguration {
 
     @UriParam(label = "security", secret = true)
     private String account;
+    @UriParam(label = "advanced")
+    private String activePortRange;
 
     public FtpConfiguration() {
         setProtocol("ftp");
@@ -55,4 +57,17 @@ public class FtpConfiguration extends RemoteFileConfiguration {
     public void setAccount(String account) {
         this.account = account;
     }
+
+    public String getActivePortRange() {
+        return activePortRange;
+    }
+
+    /**
+     * Set the client side port range in active mode.
+     * The syntax is: minPort-maxPort
+     * Both port numbers are inclusive, eg 10000-19999 to include all 1xxxx ports.
+     */
+    public void setActivePortRange(String activePortRange) {
+        this.activePortRange = activePortRange;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/6645583a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
index f5d0297..8a48737 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
@@ -28,6 +28,7 @@ import org.apache.camel.component.file.remote.RemoteFileConfiguration.PathSepara
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.PlatformHelper;
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPClientConfig;
@@ -106,6 +107,18 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
         }
         dataTimeout = getConfiguration().getTimeout();
 
+        if (getConfiguration().getActivePortRange() != null) {
+            // parse it as min-max
+            String[] parts = getConfiguration().getActivePortRange().split("-");
+            if (parts.length != 2) {
+                throw new IllegalArgumentException("The option activePortRange should have syntax: min-max");
+            }
+            int min = getCamelContext().getTypeConverter().mandatoryConvertTo(int.class, parts[0]);
+            int max = getCamelContext().getTypeConverter().mandatoryConvertTo(int.class, parts[1]);
+            log.debug("Using active port range: {}-{}", min, max);
+            client.setActivePortRange(min, max);
+        }
+
         // then lookup ftp client parameters and set those
         if (ftpClientParameters != null) {
             Map<String, Object> localParameters = new HashMap<String, Object>(ftpClientParameters);

http://git-wip-us.apache.org/repos/asf/camel/blob/6645583a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpActivePortRangeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpActivePortRangeTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpActivePortRangeTest.java
new file mode 100644
index 0000000..106fe3a
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpActivePortRangeTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class FromFtpActivePortRangeTest extends FtpServerTestSupport {
+
+    private String getFtpUrl() {
+        return "ftp://admin@localhost:" + getPort() + "/portrange/?password=admin&activePortRange=10000-19999";
+    }
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        prepareFtpServer();
+    }
+
+    @Test
+    public void testActivePortRange() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        mock.assertIsSatisfied();
+    }
+
+    private void prepareFtpServer() throws Exception {
+        // prepares the FTP Server by creating a file on the server
+        Endpoint endpoint = context.getEndpoint(getFtpUrl());
+        Exchange exchange = endpoint.createExchange();
+        exchange.getIn().setBody("Hello World");
+        exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
+        Producer producer = endpoint.createProducer();
+        producer.start();
+        producer.process(exchange);
+        producer.stop();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from(getFtpUrl()).to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file


[3/3] camel git commit: sftp endpoint should exclude some options it does not support

Posted by da...@apache.org.
sftp endpoint should exclude some options it does not support


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

Branch: refs/heads/camel-2.17.x
Commit: 2fa4fd0302f6684d4a401160d10ac50fd6ef9e05
Parents: 7891367
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Aug 16 13:50:27 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Aug 16 13:51:12 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/component/file/remote/SftpEndpoint.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2fa4fd03/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
index 12af0f8..0da5beb 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
@@ -28,7 +28,8 @@ import org.apache.camel.spi.UriParam;
  *  The sftp (FTP over SSH) component is used for uploading or downloading files from SFTP servers.
  */
 @UriEndpoint(scheme = "sftp", extendsScheme = "file", title = "SFTP",
-        syntax = "sftp:host:port/directoryName", consumerClass = SftpConsumer.class, label = "file")
+        syntax = "sftp:host:port/directoryName", consumerClass = SftpConsumer.class, label = "file",
+        excludeProperties = "binary,passiveMode,receiveBufferSize,siteCommand,useList")
 public class SftpEndpoint extends RemoteFileEndpoint<ChannelSftp.LsEntry> {
 
     @UriParam


[2/3] camel git commit: sftp endpoint should exclude some options it does not support

Posted by da...@apache.org.
sftp endpoint should exclude some options it does not support


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

Branch: refs/heads/master
Commit: d4fa3c55ca1a0801232d96302609a34c6cab648b
Parents: 6645583
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Aug 16 13:50:27 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Aug 16 13:50:27 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/component/file/remote/SftpEndpoint.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d4fa3c55/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
index 12af0f8..0da5beb 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
@@ -28,7 +28,8 @@ import org.apache.camel.spi.UriParam;
  *  The sftp (FTP over SSH) component is used for uploading or downloading files from SFTP servers.
  */
 @UriEndpoint(scheme = "sftp", extendsScheme = "file", title = "SFTP",
-        syntax = "sftp:host:port/directoryName", consumerClass = SftpConsumer.class, label = "file")
+        syntax = "sftp:host:port/directoryName", consumerClass = SftpConsumer.class, label = "file",
+        excludeProperties = "binary,passiveMode,receiveBufferSize,siteCommand,useList")
 public class SftpEndpoint extends RemoteFileEndpoint<ChannelSftp.LsEntry> {
 
     @UriParam