Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ACDBF100EB for ; Wed, 18 Dec 2013 07:30:08 +0000 (UTC) Received: (qmail 47560 invoked by uid 500); 18 Dec 2013 07:30:08 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 47522 invoked by uid 500); 18 Dec 2013 07:30:07 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 47491 invoked by uid 99); 18 Dec 2013 07:30:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Dec 2013 07:30:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 68B868BBAEE; Wed, 18 Dec 2013 07:30:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Message-Id: <618a5e191a75496b866197e71f1d3e19@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: CAMEL-7077 FtpEndpoint createRemoteFileOperations should keep the parameters for next invocation Date: Wed, 18 Dec 2013 07:30:04 +0000 (UTC) Updated Branches: refs/heads/master ec54b6818 -> 20b5756cc 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/20b5756c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/20b5756c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/20b5756c Branch: refs/heads/master Commit: 20b5756cc880257c2879e78905ac2dd2c3db47df Parents: ec54b68 Author: Willem Jiang Authored: Wed Dec 18 15:17:59 2013 +0800 Committer: Willem Jiang Committed: Wed Dec 18 15:17:59 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/20b5756c/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 extends RemoteFileEndpoint // then lookup ftp client parameters and set those if (ftpClientParameters != null) { + Map localParameters = new HashMap(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 extends RemoteFileEndpoint if (ftpClientConfig == null) { ftpClientConfig = new FTPClientConfig(); } - setProperties(ftpClientConfig, ftpClientConfigParameters); + Map localConfigParameters = new HashMap(ftpClientConfigParameters); + setProperties(ftpClientConfig, localConfigParameters); } if (dataTimeout > 0) { @@ -175,7 +178,7 @@ public class FtpEndpoint extends RemoteFileEndpoint * Used by FtpComponent to provide additional parameters for the FTPClientConfig */ void setFtpClientConfigParameters(Map ftpClientConfigParameters) { - this.ftpClientConfigParameters = ftpClientConfigParameters; + this.ftpClientConfigParameters = new HashMap(ftpClientConfigParameters); } public int getSoTimeout() { http://git-wip-us.apache.org/repos/asf/camel/blob/20b5756c/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 ftpEndpoint = context.getEndpoint(getFtpUrl(), FtpEndpoint.class); + + // set "ftp://admin@localhost:21/timeout/?ftpClient.soTimeout=10" + Map ftpClientParameters = new HashMap(); + 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