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 2011/09/23 11:53:05 UTC
svn commit: r1174626 - in /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: Fri Sep 23 09:53:05 2011
New Revision: 1174626
URL: http://svn.apache.org/viewvc?rev=1174626&view=rev
Log:
CAMEL-4182: Port the minDepth and maxDepth options from file component to ftp component
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth2Test.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth3Test.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepthTest.java
- copied, changed from r1174563, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java
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/SftpConsumer.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=1174626&r1=1174625&r2=1174626&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 Fri Sep 23 09:53:05 2011
@@ -48,7 +48,7 @@ public class FtpConsumer extends RemoteF
// strip trailing slash
fileName = FileUtil.stripTrailingSeparator(fileName);
- boolean answer = doPollDirectory(fileName, null, fileList);
+ boolean answer = doPollDirectory(fileName, null, fileList, depth);
if (currentDir != null) {
operations.changeCurrentDirectory(currentDir);
}
@@ -56,8 +56,8 @@ public class FtpConsumer extends RemoteF
return answer;
}
- protected boolean pollSubDirectory(String absolutePath, String dirName, List<GenericFile<FTPFile>> fileList) {
- boolean answer = doPollDirectory(absolutePath, dirName, fileList);
+ protected boolean pollSubDirectory(String absolutePath, String dirName, List<GenericFile<FTPFile>> fileList, int depth) {
+ boolean answer = doPollDirectory(absolutePath, dirName, fileList, depth);
// change back to parent directory when finished polling sub directory
if (isStepwise()) {
operations.changeToParentDirectory();
@@ -65,8 +65,11 @@ public class FtpConsumer extends RemoteF
return answer;
}
- protected boolean doPollDirectory(String absolutePath, String dirName, List<GenericFile<FTPFile>> fileList) {
+ protected boolean doPollDirectory(String absolutePath, String dirName, List<GenericFile<FTPFile>> fileList, int depth) {
log.trace("doPollDirectory from absolutePath: {}, dirName: {}", absolutePath, dirName);
+
+ depth++;
+
// remove trailing /
dirName = FileUtil.stripTrailingSeparator(dirName);
@@ -105,18 +108,18 @@ public class FtpConsumer extends RemoteF
if (file.isDirectory()) {
RemoteFile<FTPFile> remote = asRemoteFile(absolutePath, file);
- if (endpoint.isRecursive() && isValidFile(remote, true)) {
+ if (endpoint.isRecursive() && isValidFile(remote, true) && depth < endpoint.getMaxDepth()) {
// recursive scan and add the sub files and folders
String subDirectory = file.getName();
String path = absolutePath + "/" + subDirectory;
- boolean canPollMore = pollSubDirectory(path, subDirectory, fileList);
+ boolean canPollMore = pollSubDirectory(path, subDirectory, fileList, depth);
if (!canPollMore) {
return false;
}
}
} else if (file.isFile()) {
RemoteFile<FTPFile> remote = asRemoteFile(absolutePath, file);
- if (isValidFile(remote, false)) {
+ if (isValidFile(remote, false) && depth >= endpoint.getMinDepth()) {
if (isInProgress(remote)) {
log.trace("Skipping as file is already in progress: {}", remote.getFileName());
} else {
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=1174626&r1=1174625&r2=1174626&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 Fri Sep 23 09:53:05 2011
@@ -47,7 +47,7 @@ public class SftpConsumer extends Remote
// strip trailing slash
fileName = FileUtil.stripTrailingSeparator(fileName);
- boolean answer = doPollDirectory(fileName, null, fileList);
+ boolean answer = doPollDirectory(fileName, null, fileList, depth);
if (currentDir != null) {
operations.changeCurrentDirectory(currentDir);
}
@@ -55,8 +55,8 @@ public class SftpConsumer extends Remote
return answer;
}
- protected boolean pollSubDirectory(String absolutePath, String dirName, List<GenericFile<ChannelSftp.LsEntry>> fileList) {
- boolean answer = doPollDirectory(absolutePath, dirName, fileList);
+ protected boolean pollSubDirectory(String absolutePath, String dirName, List<GenericFile<ChannelSftp.LsEntry>> fileList, int depth) {
+ boolean answer = doPollDirectory(absolutePath, dirName, fileList, depth);
// change back to parent directory when finished polling sub directory
if (isStepwise()) {
operations.changeToParentDirectory();
@@ -64,9 +64,11 @@ public class SftpConsumer extends Remote
return answer;
}
- protected boolean doPollDirectory(String absolutePath, String dirName, List<GenericFile<ChannelSftp.LsEntry>> fileList) {
+ protected boolean doPollDirectory(String absolutePath, String dirName, List<GenericFile<ChannelSftp.LsEntry>> fileList, int depth) {
log.trace("doPollDirectory from absolutePath: {}, dirName: {}", absolutePath, dirName);
+ depth++;
+
// remove trailing /
dirName = FileUtil.stripTrailingSeparator(dirName);
// compute dir depending on stepwise is enabled or not
@@ -103,11 +105,11 @@ public class SftpConsumer extends Remote
if (file.getAttrs().isDir()) {
RemoteFile<ChannelSftp.LsEntry> remote = asRemoteFile(absolutePath, file);
- if (endpoint.isRecursive() && isValidFile(remote, true)) {
+ if (endpoint.isRecursive() && isValidFile(remote, true) && depth < endpoint.getMaxDepth()) {
// recursive scan and add the sub files and folders
String subDirectory = file.getFilename();
String path = absolutePath + "/" + subDirectory;
- boolean canPollMore = pollSubDirectory(path, subDirectory, fileList);
+ boolean canPollMore = pollSubDirectory(path, subDirectory, fileList, depth);
if (!canPollMore) {
return false;
}
@@ -116,7 +118,7 @@ public class SftpConsumer extends Remote
// just assuming its a file we should poll
} else {
RemoteFile<ChannelSftp.LsEntry> remote = asRemoteFile(absolutePath, file);
- if (isValidFile(remote, false)) {
+ if (isValidFile(remote, false) && depth >= endpoint.getMinDepth()) {
if (isInProgress(remote)) {
if (log.isTraceEnabled()) {
log.trace("Skipping as file is already in progress: {}", remote.getFileName());
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth2Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth2Test.java?rev=1174626&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth2Test.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth2Test.java Fri Sep 23 09:53:05 2011
@@ -0,0 +1,59 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class FtpRecursiveDepth2Test extends FtpServerTestSupport {
+
+ protected String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/depth2?password=admin&recursive=true";
+ }
+
+ @Test
+ public void testDepthMin2Max99() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceivedInAnyOrder("a2", "b2", "a3", "b3");
+
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth2?password=admin", "a", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth2?password=admin", "b", Exchange.FILE_NAME, "b.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth2/bar?password=admin", "b2", Exchange.FILE_NAME, "b2.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth2/foo?password=admin", "a2", Exchange.FILE_NAME, "a2.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth2/foo/bar?password=admin", "a3", Exchange.FILE_NAME, "a3.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth2/bar/foo?password=admin", "b3", Exchange.FILE_NAME, "b3.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(getFtpUrl() + "&minDepth=2&maxDepth=99")
+ .convertBodyTo(String.class)
+ .to("mock:result");
+ }
+ };
+ }
+}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth3Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth3Test.java?rev=1174626&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth3Test.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepth3Test.java Fri Sep 23 09:53:05 2011
@@ -0,0 +1,59 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class FtpRecursiveDepth3Test extends FtpServerTestSupport {
+
+ protected String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/depth3?password=admin&recursive=true";
+ }
+
+ @Test
+ public void testDepthMin1Max1() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceivedInAnyOrder("a", "b");
+
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth3?password=admin", "a", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth3?password=admin", "b", Exchange.FILE_NAME, "b.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth3/foo?password=admin", "a2", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth3/foo/bar?password=admin", "a3", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth3/bar?password=admin", "b2", Exchange.FILE_NAME, "b.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth3/bar/foo?password=admin", "b3", Exchange.FILE_NAME, "b.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(getFtpUrl() + "&minDepth=1&maxDepth=1")
+ .convertBodyTo(String.class)
+ .to("mock:result");
+ }
+ };
+ }
+}
Copied: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepthTest.java (from r1174563, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepthTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepthTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java&r1=1174563&r2=1174626&rev=1174626&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRecursiveNoopTest.java (original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRecursiveDepthTest.java Fri Sep 23 09:53:05 2011
@@ -22,39 +22,27 @@ import org.apache.camel.component.mock.M
import org.junit.Test;
/**
- * @version
+ * @version
*/
-public class FromFtpRecursiveNoopTest extends FtpServerTestSupport {
+public class FtpRecursiveDepthTest extends FtpServerTestSupport {
protected String getFtpUrl() {
- return "ftp://admin@localhost:" + getPort() + "/noop?password=admin&binary=false&initialDelay=3000"
- + "&recursive=true&noop=true";
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- template.sendBodyAndHeader(getFtpUrl(), "a", Exchange.FILE_NAME, "a.txt");
- template.sendBodyAndHeader(getFtpUrl(), "b", Exchange.FILE_NAME, "b.txt");
- template.sendBodyAndHeader(getFtpUrl(), "a2", Exchange.FILE_NAME, "foo/a.txt");
- template.sendBodyAndHeader(getFtpUrl(), "c", Exchange.FILE_NAME, "bar/c.txt");
- template.sendBodyAndHeader(getFtpUrl(), "b2", Exchange.FILE_NAME, "bar/b.txt");
+ return "ftp://admin@localhost:" + getPort() + "/depth?password=admin&recursive=true";
}
@Test
- public void testRecursiveNoop() throws Exception {
+ public void testDepth() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedBodiesReceivedInAnyOrder("a", "b", "a2", "c", "b2");
+ mock.expectedBodiesReceivedInAnyOrder("a2", "b2");
- assertMockEndpointsSatisfied();
-
- // reset mock and send in a new file to be picked up only
- mock.reset();
- mock.expectedBodiesReceived("c2");
-
- template.sendBodyAndHeader(getFtpUrl(), "c2", Exchange.FILE_NAME, "c.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth?password=admin", "a", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth?password=admin", "b", Exchange.FILE_NAME, "b.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth/foo?password=admin", "a2", Exchange.FILE_NAME, "a2.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth/foo/bar?password=admin", "a3", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth/bar?password=admin", "b2", Exchange.FILE_NAME, "b2.txt");
+ template.sendBodyAndHeader("ftp://admin@localhost:" + getPort() + "/depth/bar/foo?password=admin", "b3", Exchange.FILE_NAME, "b.txt");
+ // only expect 2 of the 6 sent, those at depth 2
assertMockEndpointsSatisfied();
}
@@ -63,12 +51,10 @@ public class FromFtpRecursiveNoopTest ex
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from(getFtpUrl())
+ from(getFtpUrl() + "&minDepth=2&maxDepth=2")
.convertBodyTo(String.class)
- .to("log:ftp")
.to("mock:result");
}
};
}
-
}