You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/12/18 08:52:00 UTC
[1/2] git commit: CAMEL-7077 FtpEndpoint createRemoteFileOperations
should keep the parameters for next invocation
Updated Branches:
refs/heads/camel-2.11.x aa2982447 -> b77525227
refs/heads/camel-2.12.x 318d653be -> 1430c6b0d
CAMEL-7077 FtpEndpoint createRemoteFileOperations should keep the parameters for next invocation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1430c6b0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1430c6b0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1430c6b0
Branch: refs/heads/camel-2.12.x
Commit: 1430c6b0dbe037f6139941d4222d62d09b8c80b6
Parents: 318d653
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Dec 18 15:17:59 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Dec 18 15:38:39 2013 +0800
----------------------------------------------------------------------
.../component/file/remote/FtpEndpoint.java | 13 ++--
.../remote/FromFtpClientSoTimeout3Test.java | 71 ++++++++++++++++++++
2 files changed, 79 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1430c6b0/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 03b14b5..abad079 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
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file.remote;
+import java.util.HashMap;
import java.util.Map;
import org.apache.camel.FailedToCreateConsumerException;
@@ -89,17 +90,18 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
// then lookup ftp client parameters and set those
if (ftpClientParameters != null) {
+ Map<String, Object> localParameters = new HashMap<String, Object>(ftpClientParameters);
// setting soTimeout has to be done later on FTPClient (after it has connected)
- Object timeout = ftpClientParameters.remove("soTimeout");
+ Object timeout = localParameters.remove("soTimeout");
if (timeout != null) {
soTimeout = getCamelContext().getTypeConverter().convertTo(int.class, timeout);
}
// and we want to keep data timeout so we can log it later
- timeout = ftpClientParameters.remove("dataTimeout");
+ timeout = localParameters.remove("dataTimeout");
if (timeout != null) {
dataTimeout = getCamelContext().getTypeConverter().convertTo(int.class, dataTimeout);
}
- setProperties(client, ftpClientParameters);
+ setProperties(client, localParameters);
}
if (ftpClientConfigParameters != null) {
@@ -107,7 +109,8 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
if (ftpClientConfig == null) {
ftpClientConfig = new FTPClientConfig();
}
- setProperties(ftpClientConfig, ftpClientConfigParameters);
+ Map<String, Object> localConfigParameters = new HashMap<String, Object>(ftpClientConfigParameters);
+ setProperties(ftpClientConfig, localConfigParameters);
}
if (dataTimeout > 0) {
@@ -175,7 +178,7 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
* Used by FtpComponent to provide additional parameters for the FTPClientConfig
*/
void setFtpClientConfigParameters(Map<String, Object> ftpClientConfigParameters) {
- this.ftpClientConfigParameters = ftpClientConfigParameters;
+ this.ftpClientConfigParameters = new HashMap<String, Object>(ftpClientConfigParameters);
}
public int getSoTimeout() {
http://git-wip-us.apache.org/repos/asf/camel/blob/1430c6b0/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java
new file mode 100644
index 0000000..dc83444
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java
@@ -0,0 +1,71 @@
+/**
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.net.ftp.FTPFile;
+import org.junit.Test;
+
+/**
+ * Test re-creating operations
+ * @see {org.apache.camel.component.file.remote.RemoteFileConsumer#recoverableConnectIfNecessary}
+ */
+public class FromFtpClientSoTimeout3Test extends CamelTestSupport {
+
+ private String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/timeout/?soTimeout=5000";
+ }
+
+ private String getPort() {
+ return "21";
+ }
+
+ @Test
+ public void test() throws Exception {
+ @SuppressWarnings("unchecked")
+ FtpEndpoint<FTPFile> ftpEndpoint = context.getEndpoint(getFtpUrl(), FtpEndpoint.class);
+
+ // set "ftp://admin@localhost:21/timeout/?ftpClient.soTimeout=10"
+ Map<String, Object> ftpClientParameters = new HashMap<String, Object>();
+ ftpClientParameters.put("soTimeout", "10");
+ ftpEndpoint.setFtpClientParameters(ftpClientParameters);
+
+ // test RemoteFileConsumer#buildConsumer
+ assertEquals(ftpClientParameters.get("soTimeout"), "10");
+ ftpEndpoint.createRemoteFileOperations();
+
+ // test RemoteFileConsumer#recoverableConnectIfNecessary
+ // recover by re-creating operations which should most likely be able to recover
+ assertEquals(ftpClientParameters.get("soTimeout"), "10");
+ ftpEndpoint.createRemoteFileOperations();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from(getFtpUrl()).to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
[2/2] git commit: CAMEL-7077 FtpEndpoint createRemoteFileOperations
should keep the parameters for next invocation
Posted by ni...@apache.org.
CAMEL-7077 FtpEndpoint createRemoteFileOperations should keep the parameters for next invocation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b7752522
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b7752522
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b7752522
Branch: refs/heads/camel-2.11.x
Commit: b775252279af824377a06ca2fb97ea634a33307b
Parents: aa29824
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Dec 18 15:17:59 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Dec 18 15:51:36 2013 +0800
----------------------------------------------------------------------
.../component/file/remote/FtpEndpoint.java | 13 ++--
.../remote/FromFtpClientSoTimeout3Test.java | 71 ++++++++++++++++++++
2 files changed, 79 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b7752522/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 03b14b5..abad079 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
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file.remote;
+import java.util.HashMap;
import java.util.Map;
import org.apache.camel.FailedToCreateConsumerException;
@@ -89,17 +90,18 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
// then lookup ftp client parameters and set those
if (ftpClientParameters != null) {
+ Map<String, Object> localParameters = new HashMap<String, Object>(ftpClientParameters);
// setting soTimeout has to be done later on FTPClient (after it has connected)
- Object timeout = ftpClientParameters.remove("soTimeout");
+ Object timeout = localParameters.remove("soTimeout");
if (timeout != null) {
soTimeout = getCamelContext().getTypeConverter().convertTo(int.class, timeout);
}
// and we want to keep data timeout so we can log it later
- timeout = ftpClientParameters.remove("dataTimeout");
+ timeout = localParameters.remove("dataTimeout");
if (timeout != null) {
dataTimeout = getCamelContext().getTypeConverter().convertTo(int.class, dataTimeout);
}
- setProperties(client, ftpClientParameters);
+ setProperties(client, localParameters);
}
if (ftpClientConfigParameters != null) {
@@ -107,7 +109,8 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
if (ftpClientConfig == null) {
ftpClientConfig = new FTPClientConfig();
}
- setProperties(ftpClientConfig, ftpClientConfigParameters);
+ Map<String, Object> localConfigParameters = new HashMap<String, Object>(ftpClientConfigParameters);
+ setProperties(ftpClientConfig, localConfigParameters);
}
if (dataTimeout > 0) {
@@ -175,7 +178,7 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
* Used by FtpComponent to provide additional parameters for the FTPClientConfig
*/
void setFtpClientConfigParameters(Map<String, Object> ftpClientConfigParameters) {
- this.ftpClientConfigParameters = ftpClientConfigParameters;
+ this.ftpClientConfigParameters = new HashMap<String, Object>(ftpClientConfigParameters);
}
public int getSoTimeout() {
http://git-wip-us.apache.org/repos/asf/camel/blob/b7752522/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java
new file mode 100644
index 0000000..dc83444
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpClientSoTimeout3Test.java
@@ -0,0 +1,71 @@
+/**
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.net.ftp.FTPFile;
+import org.junit.Test;
+
+/**
+ * Test re-creating operations
+ * @see {org.apache.camel.component.file.remote.RemoteFileConsumer#recoverableConnectIfNecessary}
+ */
+public class FromFtpClientSoTimeout3Test extends CamelTestSupport {
+
+ private String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/timeout/?soTimeout=5000";
+ }
+
+ private String getPort() {
+ return "21";
+ }
+
+ @Test
+ public void test() throws Exception {
+ @SuppressWarnings("unchecked")
+ FtpEndpoint<FTPFile> ftpEndpoint = context.getEndpoint(getFtpUrl(), FtpEndpoint.class);
+
+ // set "ftp://admin@localhost:21/timeout/?ftpClient.soTimeout=10"
+ Map<String, Object> ftpClientParameters = new HashMap<String, Object>();
+ ftpClientParameters.put("soTimeout", "10");
+ ftpEndpoint.setFtpClientParameters(ftpClientParameters);
+
+ // test RemoteFileConsumer#buildConsumer
+ assertEquals(ftpClientParameters.get("soTimeout"), "10");
+ ftpEndpoint.createRemoteFileOperations();
+
+ // test RemoteFileConsumer#recoverableConnectIfNecessary
+ // recover by re-creating operations which should most likely be able to recover
+ assertEquals(ftpClientParameters.get("soTimeout"), "10");
+ ftpEndpoint.createRemoteFileOperations();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from(getFtpUrl()).to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file