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 2008/09/14 11:04:04 UTC

svn commit: r695152 - in /activemq/camel/trunk/components/camel-ftp/src: main/java/org/apache/camel/component/file/remote/ test/java/org/apache/camel/component/file/remote/

Author: davsclaus
Date: Sun Sep 14 02:04:03 2008
New Revision: 695152

URL: http://svn.apache.org/viewvc?rev=695152&view=rev
Log:
CAMEL-897: New option FTPClientConfig for camel-ftp (regular ftp, not sftp) to allow end-users use a custom config to set FTP server date format, timezone etc.

Added:
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java   (with props)
Modified:
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java?rev=695152&r1=695151&r2=695152&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java Sun Sep 14 02:04:03 2008
@@ -36,17 +36,25 @@
         int port = config.getPort();
         String username = config.getUsername();
 
+        if (config.getFtpClientConfig() != null) {
+            LOG.trace("Configuring FTPClient with config: " + config.getFtpClientConfig());
+            client.configure(config.getFtpClientConfig());
+        }
+
         LOG.trace("Connecting to " + config);
         client.connect(host, port);
 
         boolean login;
-        LOG.trace("Attempting to login " + username);
         if (username != null) {
+            LOG.trace("Attempting to login " + username);
             login = client.login(username, config.getPassword());
         } else {
+            LOG.trace("Attempting to login anonymous");
             login = client.login("anonymous", null);
         }
-        LOG.trace("User " + username + " logged in: " + login);
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("User " + (username != null ? username : "anonymous") + " logged in: " + login);
+        }
         if (!login) {
             return false;
         }

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java?rev=695152&r1=695151&r2=695152&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java Sun Sep 14 02:04:03 2008
@@ -22,6 +22,7 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.commons.net.ftp.FTPClientConfig;
 
 public class RemoteFileComponent extends DefaultComponent<RemoteFileExchange> {
     private RemoteFileConfiguration configuration;
@@ -62,10 +63,23 @@
             throw new RuntimeCamelException("Unsupported protocol: " + config.getProtocol());
         }
 
+        configureFTPClientConfig(parameters, endpoint);
         setProperties(endpoint.getConfiguration(), parameters);
         return endpoint;
     }
 
+    private void configureFTPClientConfig(Map parameters, RemoteFileEndpoint endpoint) {
+        // lookup client config in registry if provided
+        String ref = getAndRemoveParameter(parameters, "ftpClientConfig", String.class);
+        if (ref != null) {
+            FTPClientConfig ftpClientConfig = this.getCamelContext().getRegistry().lookup(ref, FTPClientConfig.class);
+            if (ftpClientConfig == null) {
+                throw new IllegalArgumentException("FTPClientConfig " + ref + " not found in registry.");
+            }
+            endpoint.getConfiguration().setFtpClientConfig(ftpClientConfig);
+        }
+    }
+
     public RemoteFileConfiguration getConfiguration() {
         return configuration;
     }

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java?rev=695152&r1=695151&r2=695152&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java Sun Sep 14 02:04:03 2008
@@ -19,6 +19,7 @@
 import java.net.URI;
 
 import org.apache.camel.RuntimeCamelException;
+import org.apache.commons.net.ftp.FTPClientConfig;
 
 public class RemoteFileConfiguration implements Cloneable {
     private String protocol;
@@ -29,6 +30,7 @@
     private String file;
     private boolean binary;
     private boolean directory = true;
+    private FTPClientConfig ftpClientConfig;
 
     public RemoteFileConfiguration() {
     }
@@ -144,6 +146,14 @@
         this.directory = directory;
     }
 
+    public FTPClientConfig getFtpClientConfig() {
+        return ftpClientConfig;
+    }
+
+    public void setFtpClientConfig(FTPClientConfig ftpClientConfig) {
+        this.ftpClientConfig = ftpClientConfig;
+    }
+
     public String dump() {
         return "RemoteFileConfiguration{" + "protocol='" + protocol + '\'' + ", username='" + username + '\'' + ", host='" + host + '\'' + ", port=" + port + ", password='" + password + '\''
                + ", file='" + file + '\'' + ", binary=" + binary + ", directory=" + directory + '}';

Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java?rev=695152&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java (added)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java Sun Sep 14 02:04:03 2008
@@ -0,0 +1,79 @@
+/**
+ * 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.file.FileComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.commons.net.ftp.FTPClientConfig;
+
+/**
+ * Unit test for ftpClientConfig option. 
+ */
+public class FtpConsumerUsingFTPClientConfigTest extends FtpServerTestSupport {
+
+    private int port = 20066;
+
+    private String ftpUrl = "ftp://admin@localhost:" + port + "/clientconfig?password=admin&ftpClientConfig=myConfig";
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myConfig", createConfig());
+        return jndi;
+    }
+
+    private FTPClientConfig createConfig() {
+        FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
+        config.setServerTimeZoneId("Europe/Paris");
+        return config;
+    }
+
+    public void testFTPClientConfig() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived("Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        prepareFtpServer();
+    }
+
+    private void prepareFtpServer() throws Exception {
+        // prepares the FTP Server by creating files on the server that we want to unit
+        // test that we can pool and store as a local file
+        template.sendBodyAndHeader(ftpUrl, "Hello World", FileComponent.HEADER_FILE_NAME, "hello.txt");
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from(ftpUrl).to("mock:result");
+            }
+        };
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date