camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r751478 - in /camel/trunk/components/camel-ftp/src: main/java/org/apache/camel/component/file/remote/ test/java/org/apache/camel/component/file/remote/
Date Sun, 08 Mar 2009 17:32:06 GMT
Author: davsclaus
Date: Sun Mar  8 17:32:05 2009
New Revision: 751478

URL: http://svn.apache.org/viewvc?rev=751478&view=rev
Log:
CAMEL-1428: Polished code.

Added:
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/PaddyRouteTest.java
  (with props)
Modified:
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=751478&r1=751477&r2=751478&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
Sun Mar  8 17:32:05 2009
@@ -20,6 +20,7 @@
 
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.net.ftp.FTPFile;
 
@@ -40,10 +41,8 @@
             return;
         }
 
-        // fix filename
-        if (fileName.endsWith("/")) {
-            fileName = fileName.substring(0, fileName.length() - 1);
-        }
+        // remove trailing /
+        fileName = FileUtil.stripTrailingSeparator(fileName);
 
         if (log.isTraceEnabled()) {
             log.trace("Polling directory: " + fileName);
@@ -116,10 +115,8 @@
 
         // the relative filename, skip the leading endpoint configured path
         String relativePath = ObjectHelper.after(absoluteFileName, endpointPath);
-        if (relativePath.startsWith("/")) {
-            // skip trailing /
-            relativePath = relativePath.substring(1);
-        }
+        // skip trailing /
+        relativePath = FileUtil.stripLeadingSeparator(relativePath);
         answer.setRelativeFilePath(relativePath);
 
         return answer;

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=751478&r1=751477&r2=751478&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Sun Mar  8 17:32:05 2009
@@ -66,7 +66,7 @@
         FtpConfiguration ftpConfig = (FtpConfiguration) config;
 
         if (ftpConfig.getFtpClientConfig() != null) {
-            LOG.trace("Configuring FTPFile with config: " + ftpConfig.getFtpClientConfig());
+            LOG.trace("Configuring FTPClient with config: " + ftpConfig.getFtpClientConfig());
             client.configure(ftpConfig.getFtpClientConfig());
         }
 

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java?rev=751478&r1=751477&r2=751478&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
Sun Mar  8 17:32:05 2009
@@ -21,6 +21,7 @@
 import com.jcraft.jsch.ChannelSftp;
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -40,18 +41,16 @@
             return;
         }
 
-        // fix filename
-        if (fileName.endsWith("/")) {
-            fileName = fileName.substring(0, fileName.length() - 1);
-        }
+        // remove trailing /
+        fileName = FileUtil.stripTrailingSeparator(fileName);
 
         if (log.isTraceEnabled()) {
             log.trace("Polling directory: " + fileName);
         }
         List<ChannelSftp.LsEntry> files = operations.listFiles(fileName);
         for (ChannelSftp.LsEntry file : files) {
-            RemoteFile<ChannelSftp.LsEntry> remote = asRemoteFile(fileName, file);
             if (file.getAttrs().isDir()) {
+                RemoteFile<ChannelSftp.LsEntry> remote = asRemoteFile(fileName, file);
                 if (endpoint.isRecursive() && isValidFile(remote, true)) {
                     // recursive scan and add the sub files and folders
                     String directory = fileName + "/" + file.getFilename();
@@ -60,6 +59,7 @@
                 // we cannot use file.getAttrs().isLink on Windows, so we dont invoke the
method
                 // just assuming its a file we should poll
             } else {
+                RemoteFile<ChannelSftp.LsEntry> remote = asRemoteFile(fileName, file);
                 if (isValidFile(remote, false)) {
                     // matched file so add
                     fileList.add(remote);
@@ -118,10 +118,8 @@
 
         // the relative filename, skip the leading endpoint configured path
         String relativePath = ObjectHelper.after(absoluteFileName, endpointPath);
-        if (relativePath.startsWith("/")) {
-            // skip trailing /
-            relativePath = relativePath.substring(1);
-        }
+        // skip trailing /
+        relativePath = FileUtil.stripLeadingSeparator(relativePath);
         answer.setRelativeFilePath(relativePath);
 
         return answer;

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=751478&r1=751477&r2=751478&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Sun Mar  8 17:32:05 2009
@@ -32,6 +32,7 @@
 import com.jcraft.jsch.Session;
 import com.jcraft.jsch.SftpException;
 import com.jcraft.jsch.UserInfo;
+import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.file.GenericFileEndpoint;
@@ -39,7 +40,6 @@
 import org.apache.camel.component.file.GenericFileOperationFailedException;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.FileUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import static org.apache.camel.util.ObjectHelper.isNotEmpty;
@@ -212,7 +212,7 @@
 
     private boolean buildDirectoryChunks(String dirName) throws IOException, SftpException
{
         final StringBuilder sb = new StringBuilder(dirName.length());
-        final String[] dirs = dirName.split("\\/|\\\\");
+        final String[] dirs = dirName.split("/|\\\\");
 
         boolean success = false;
         for (String dir : dirs) {
@@ -331,7 +331,8 @@
             os = new FileOutputStream(temp);
 
             // set header with the path to the local work file
-            exchange.getIn().setHeader("CamelFileLocalWorkPath", local.getPath());
+            exchange.getIn().setHeader(Exchange.FILE_LOCAL_WORK_PATH, local.getPath());
+
 
         } catch (Exception e) {
             throw new GenericFileOperationFailedException("Cannot create new local work file:
" + local);

Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/PaddyRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/PaddyRouteTest.java?rev=751478&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/PaddyRouteTest.java
(added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/PaddyRouteTest.java
Sun Mar  8 17:32:05 2009
@@ -0,0 +1,57 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * An unit test based on Paddy having trouble with SFTP.
+ */
+public class PaddyRouteTest extends FtpServerTestSupport {
+
+    private String getFtpUrl() {
+        return "ftp://admin@localhost:" + getPort() + "/paddy/?password=admin&recursive=true";
+    }
+
+    public void testConsumeFile() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        sendFile(getFtpUrl() + "/?password=admin", "Hello World", "incoming/hello.txt");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(getFtpUrl()).process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        assertNotNull(exchange.getIn().getHeader(Exchange.FILE_NAME));
+                        assertEquals("hello.txt", exchange.getIn().getHeader(Exchange.FILE_NAME_ONLY));
+                        assertEquals("Hello World", exchange.getIn().getBody(String.class));
+                    }
+                }).to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

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

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

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java?rev=751478&r1=751477&r2=751478&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
Sun Mar  8 17:32:05 2009
@@ -86,21 +86,25 @@
 
     public void testRemoteFileEndpointFiles() {
         assertRemoteFileEndpointFile("ftp://hostname/foo/bar", "foo/bar");
-        assertRemoteFileEndpointFile("ftp://hostname/foo/", "foo/");
+        assertRemoteFileEndpointFile("ftp://hostname/foo/bar/", "foo/bar");
+        assertRemoteFileEndpointFile("ftp://hostname/foo/", "foo");
         assertRemoteFileEndpointFile("ftp://hostname/foo", "foo");
         assertRemoteFileEndpointFile("ftp://hostname/", "");
         assertRemoteFileEndpointFile("ftp://hostname", "");
-        assertRemoteFileEndpointFile("ftp://hostname//", "/");
+        assertRemoteFileEndpointFile("ftp://hostname//", "");
         assertRemoteFileEndpointFile("ftp://hostname//foo/bar", "/foo/bar");
+        assertRemoteFileEndpointFile("ftp://hostname//foo/bar/", "/foo/bar");
         assertRemoteFileEndpointFile("sftp://user@hostname:123//foo/bar?password=secret",
"/foo/bar");
         assertRemoteFileEndpointFile("sftp://user@hostname:123?password=secret", "");
         assertRemoteFileEndpointFile("sftp://hostname/foo/bar", "foo/bar");
-        assertRemoteFileEndpointFile("sftp://hostname/foo/", "foo/");
+        assertRemoteFileEndpointFile("sftp://hostname/foo/bar/", "foo/bar");
+        assertRemoteFileEndpointFile("sftp://hostname/foo/", "foo");
         assertRemoteFileEndpointFile("sftp://hostname/foo", "foo");
         assertRemoteFileEndpointFile("sftp://hostname/", "");
         assertRemoteFileEndpointFile("sftp://hostname", "");
-        assertRemoteFileEndpointFile("sftp://hostname//", "/");
+        assertRemoteFileEndpointFile("sftp://hostname//", "");
         assertRemoteFileEndpointFile("sftp://hostname//foo/bar", "/foo/bar");
+        assertRemoteFileEndpointFile("sftp://hostname//foo/bar/", "/foo/bar");
     }
 
     private void assertRemoteFileEndpointFile(String endpointUri, String expectedFile) {



Mime
View raw message