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 2009/01/02 16:17:12 UTC
svn commit: r730753 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/component/file/
camel-core/src/main/java/org/apache/camel/util/
camel-core/src/test/java/org/apache/camel/util/ components/camel-ftp/
components/camel-ftp/src/mai...
Author: davsclaus
Date: Fri Jan 2 07:17:11 2009
New Revision: 730753
URL: http://svn.apache.org/viewvc?rev=730753&view=rev
Log:
CAMEL-1198: Ant path matcher now also possible with camel-ftp.
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java (contents, props changed)
- copied, changed from r730678, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java (with props)
activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/
activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java
activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/
activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml (with props)
activemq/camel/trunk/tests/camel-itest/src/test/resources/users.properties (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
activemq/camel/trunk/components/camel-ftp/pom.xml
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
activemq/camel/trunk/components/camel-spring/pom.xml
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java
activemq/camel/trunk/tests/camel-itest/pom.xml
activemq/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java Fri Jan 2 07:17:11 2009
@@ -23,9 +23,9 @@
import org.apache.camel.AsyncCallback;
import org.apache.camel.Processor;
-import org.apache.camel.util.ObjectHelper;
import org.apache.camel.impl.ScheduledPollConsumer;
import org.apache.camel.processor.DeadLetterChannel;
+import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -103,8 +103,8 @@
}
File[] files = fileOrDirectory.listFiles();
for (File file : files) {
- if (endpoint.isRecursive() && file.isDirectory()) {
- if (isValidFile(file)) {
+ if (file.isDirectory()) {
+ if (endpoint.isRecursive() && isValidFile(file)) {
// recursive scan and add the sub files and folders
pollDirectory(file, fileList);
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java Fri Jan 2 07:17:11 2009
@@ -18,7 +18,9 @@
import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -107,4 +109,29 @@
}
return answer;
}
+
+ public static String collectionAsCommaDelimitedString(String[] col) {
+ if (col == null || col.length == 0) {
+ return "";
+ }
+ return collectionAsCommaDelimitedString(Arrays.asList(col));
+ }
+
+ public static String collectionAsCommaDelimitedString(Collection col) {
+ if (col == null || col.isEmpty()) {
+ return "";
+ }
+
+ StringBuilder sb = new StringBuilder();
+ Iterator it = col.iterator();
+ while (it.hasNext()) {
+ sb.append(it.next());
+ if (it.hasNext()) {
+ sb.append(",");
+ }
+ }
+
+ return sb.toString();
+ }
+
}
Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java (from r730678, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java&r1=730678&r2=730753&rev=730753&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java Fri Jan 2 07:17:11 2009
@@ -16,11 +16,8 @@
*/
package org.apache.camel.util;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
@@ -28,108 +25,19 @@
/**
* @version $Revision$
*/
-public class ObjectHelperTest extends TestCase {
- public void testRemoveInitialCharacters() throws Exception {
- assertEquals(ObjectHelper.removeStartingCharacters("foo", '/'), "foo");
- assertEquals(ObjectHelper.removeStartingCharacters("/foo", '/'), "foo");
- assertEquals(ObjectHelper.removeStartingCharacters("//foo", '/'), "foo");
- }
-
- public void testGetPropertyName() throws Exception {
- Method method = getClass().getMethod("setCheese", String.class);
- assertNotNull("should have found a method!", method);
-
- String name = ObjectHelper.getPropertyName(method);
- assertEquals("Property name", "cheese", name);
- }
+public class CollectionHelperTest extends TestCase {
- public void setCheese(String cheese) {
- // used in the above unit test
- }
+ private String[] names = new String[]{"Claus", "Willem", "Jonathan"};
+ private List list = Arrays.asList(names);
- public void testContains() throws Exception {
- String[] array = {"foo", "bar"};
- Collection<String> collection = Arrays.asList(array);
-
- assertTrue(ObjectHelper.contains(array, "foo"));
- assertTrue(ObjectHelper.contains(collection, "foo"));
- assertTrue(ObjectHelper.contains("foo", "foo"));
-
- assertFalse(ObjectHelper.contains(array, "xyz"));
- assertFalse(ObjectHelper.contains(collection, "xyz"));
- assertFalse(ObjectHelper.contains("foo", "xyz"));
- }
+ public void testCollectionAsCommaDelimitedString() {
+ assertEquals("Claus,Willem,Jonathan", CollectionHelper.collectionAsCommaDelimitedString(names));
+ assertEquals("Claus,Willem,Jonathan", CollectionHelper.collectionAsCommaDelimitedString(list));
- public void testEqual() {
- assertTrue(ObjectHelper.equal(null, null));
- assertTrue(ObjectHelper.equal("", ""));
- assertTrue(ObjectHelper.equal(" ", " "));
- assertTrue(ObjectHelper.equal("Hello", "Hello"));
- assertTrue(ObjectHelper.equal(123, 123));
- assertTrue(ObjectHelper.equal(true, true));
-
- assertFalse(ObjectHelper.equal(null, ""));
- assertFalse(ObjectHelper.equal("", null));
- assertFalse(ObjectHelper.equal(" ", " "));
- assertFalse(ObjectHelper.equal("Hello", "World"));
- assertFalse(ObjectHelper.equal(true, false));
- assertFalse(ObjectHelper.equal(new Object(), new Object()));
-
- byte[] a = new byte[] {40, 50, 60};
- byte[] b = new byte[] {40, 50, 60};
- assertTrue(ObjectHelper.equal(a, b));
-
- a = new byte[] {40, 50, 60};
- b = new byte[] {40, 50, 60, 70};
- assertFalse(ObjectHelper.equal(a, b));
- }
+ assertEquals("", CollectionHelper.collectionAsCommaDelimitedString((String[]) null));
+ assertEquals("", CollectionHelper.collectionAsCommaDelimitedString((Collection) null));
- public void testEqualByteArray() {
- assertTrue(ObjectHelper.equalByteArray("Hello".getBytes(), "Hello".getBytes()));
- assertFalse(ObjectHelper.equalByteArray("Hello".getBytes(), "World".getBytes()));
-
- assertTrue(ObjectHelper.equalByteArray("Hello Thai Elephant \u0E08".getBytes(), "Hello Thai Elephant \u0E08".getBytes()));
- assertTrue(ObjectHelper.equalByteArray(null, null));
-
- byte[] empty = new byte[0];
- assertTrue(ObjectHelper.equalByteArray(empty, empty));
-
- byte[] a = new byte[] {40, 50, 60};
- byte[] b = new byte[] {40, 50, 60};
- assertTrue(ObjectHelper.equalByteArray(a, b));
-
- a = new byte[] {40, 50, 60};
- b = new byte[] {40, 50, 60, 70};
- assertFalse(ObjectHelper.equalByteArray(a, b));
-
- a = new byte[] {40, 50, 60, 70};
- b = new byte[] {40, 50, 60};
- assertFalse(ObjectHelper.equalByteArray(a, b));
-
- a = new byte[] {40, 50, 60};
- b = new byte[0];
- assertFalse(ObjectHelper.equalByteArray(a, b));
-
- a = new byte[0];
- b = new byte[] {40, 50, 60};
- assertFalse(ObjectHelper.equalByteArray(a, b));
-
- a = new byte[] {40, 50, 60};
- b = null;
- assertFalse(ObjectHelper.equalByteArray(a, b));
-
- a = null;
- b = new byte[] {40, 50, 60};
- assertFalse(ObjectHelper.equalByteArray(a, b));
-
- a = null;
- b = null;
- assertTrue(ObjectHelper.equalByteArray(a, b));
+ assertEquals("Claus", CollectionHelper.collectionAsCommaDelimitedString(new String[]{"Claus"}));
}
- public void testCreateIterator() {
- List<String> list = new ArrayList<String>();
- Iterator<String> iterator = list.iterator();
- assertSame("Should return the same iterator", iterator, ObjectHelper.createIterator(iterator));
- }
-}
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: activemq/camel/trunk/components/camel-ftp/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/pom.xml?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/pom.xml (original)
+++ activemq/camel/trunk/components/camel-ftp/pom.xml Fri Jan 2 07:17:11 2009
@@ -81,6 +81,13 @@
<scope>test</scope>
</dependency>
+ <!-- for unit testing AntPathMatcher -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.ftpserver</groupId>
<artifactId>ftpserver-core</artifactId>
Added: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java?rev=730753&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java (added)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java Fri Jan 2 07:17:11 2009
@@ -0,0 +1,89 @@
+/**
+ * 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.util.ObjectHelper;
+import static org.apache.camel.util.CollectionHelper.collectionAsCommaDelimitedString;
+
+/**
+ * File filter using Spring's AntPathMatcher.
+ * <p/>
+ * Exclude take precedence over includes. If a file match both exclude and include it will be regarded as excluded.
+ */
+public class AntPathMatcherRemoteFileFilter implements RemoteFileFilter {
+ private static final String ANTPATHMATCHER_CLASSNAME = "org.apache.camel.component.file.AntPathMatcherFileFilter";
+ private String[] excludes;
+ private String[] includes;
+
+ public boolean accept(RemoteFile file) {
+ // we must use reflection to invoke the AntPathMatcherFileFilter that reside in camel-spring.jar
+ // and we don't want camel-ftp to have runtime dependency on camel-spring.jar
+ Class clazz = ObjectHelper.loadClass(ANTPATHMATCHER_CLASSNAME);
+ ObjectHelper.notNull(clazz, ANTPATHMATCHER_CLASSNAME + " not found in classpath. camel-spring.jar is required in the classpath.");
+
+ try {
+ Object filter = ObjectHelper.newInstance(clazz);
+
+ // invoke setIncludes(String), must using string type as invoking with string[] does not work
+ ObjectHelper.invokeMethod(filter.getClass().getMethod("setIncludes", String.class), filter, collectionAsCommaDelimitedString(includes));
+
+ // invoke setExcludes(String), must using string type as invoking with string[] does not work
+ ObjectHelper.invokeMethod(filter.getClass().getMethod("setExcludes", String.class), filter, collectionAsCommaDelimitedString(excludes));
+
+ // invoke acceptPathName(String)
+ String path = file.getRelativeFileName();
+ Boolean result = (Boolean) ObjectHelper.invokeMethod(filter.getClass().getMethod("acceptPathName", String.class), filter, path);
+ return result;
+
+ } catch (NoSuchMethodException e) {
+ throw new TypeNotPresentException(ANTPATHMATCHER_CLASSNAME, e);
+ }
+ }
+
+ public String[] getExcludes() {
+ return excludes;
+ }
+
+ public void setExcludes(String[] excludes) {
+ this.excludes = excludes;
+ }
+
+ public String[] getIncludes() {
+ return includes;
+ }
+
+ public void setIncludes(String[] includes) {
+ this.includes = includes;
+ }
+
+ /**
+ * Sets excludes using a single string where each element can be separated with comma
+ */
+ public void setExcludes(String excludes) {
+ setExcludes(excludes.split(","));
+ }
+
+ /**
+ * Sets includes using a single string where each element can be separated with comma
+ */
+ public void setIncludes(String includes) {
+ setIncludes(includes.split(","));
+ }
+
+
+
+}
Propchange: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java Fri Jan 2 07:17:11 2009
@@ -30,7 +30,7 @@
super(endpoint, processor, ftp);
}
- protected void pollDirectory(String fileName, boolean processDir, List<RemoteFile> fileList) {
+ protected void pollDirectory(String fileName, List<RemoteFile> fileList) {
if (fileName == null) {
return;
}
@@ -45,11 +45,11 @@
List<FTPFile> files = operations.listFiles(fileName);
for (FTPFile file : files) {
RemoteFile<FTPFile> remote = asRemoteFile(fileName, file);
- if (processDir && file.isDirectory()) {
- if (isValidFile(remote, true)) {
+ if (file.isDirectory()) {
+ if (endpoint.isRecursive() && isValidFile(remote, true)) {
// recursive scan and add the sub files and folders
String directory = fileName + "/" + file.getName();
- pollDirectory(directory, endpoint.isRecursive(), fileList);
+ pollDirectory(directory, fileList);
}
} else if (file.isFile()) {
if (isValidFile(remote, false)) {
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java Fri Jan 2 07:17:11 2009
@@ -62,7 +62,7 @@
String name = endpoint.getConfiguration().getFile();
boolean isDirectory = endpoint.getConfiguration().isDirectory();
if (isDirectory) {
- pollDirectory(name, endpoint.isRecursive(), files);
+ pollDirectory(name, files);
} else {
pollFile(name, files);
}
@@ -103,10 +103,9 @@
* Polls the given directory for files to process
*
* @param fileName current directory or file
- * @param processDir recursive
* @param fileList current list of files gathered
*/
- protected abstract void pollDirectory(String fileName, boolean processDir, List<RemoteFile> fileList);
+ protected abstract void pollDirectory(String fileName, List<RemoteFile> fileList);
/**
* Polls the given file
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java Fri Jan 2 07:17:11 2009
@@ -30,7 +30,7 @@
super(endpoint, processor, operations);
}
- protected void pollDirectory(String fileName, boolean processDir, List<RemoteFile> fileList) {
+ protected void pollDirectory(String fileName, List<RemoteFile> fileList) {
if (fileName == null) {
return;
}
@@ -45,10 +45,10 @@
List<ChannelSftp.LsEntry> files = operations.listFiles(fileName);
for (ChannelSftp.LsEntry file : files) {
RemoteFile<ChannelSftp.LsEntry> remote = asRemoteFile(fileName, file);
- if (processDir && file.getAttrs().isDir()) {
- if (isValidFile(remote, true)) {
+ if (file.getAttrs().isDir()) {
+ if (endpoint.isRecursive() && isValidFile(remote, true)) {
// recursive scan and add the sub files and folders
- pollDirectory(file.getFilename(), endpoint.isRecursive(), fileList);
+ pollDirectory(file.getFilename(), fileList);
}
} else if (!file.getAttrs().isLink()) {
if (isValidFile(remote, false)) {
Modified: activemq/camel/trunk/components/camel-spring/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/pom.xml?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/pom.xml (original)
+++ activemq/camel/trunk/components/camel-spring/pom.xml Fri Jan 2 07:17:11 2009
@@ -43,6 +43,7 @@
org.apache.camel.spring.*;${camel.osgi.version},
org.apache.camel.component;${camel.osgi.split.pkg};${camel.osgi.version},
org.apache.camel.component.event;${camel.osgi.split.pkg};${camel.osgi.version},
+ org.apache.camel.component.file;${camel.osgi.split.pkg};${camel.osgi.version},
org.apache.camel.component.test;${camel.osgi.split.pkg};${camel.osgi.version},
org.apache.camel.component.validator;${camel.osgi.split.pkg};${camel.osgi.version},
org.apache.camel.component.xslt;${camel.osgi.split.pkg};${camel.osgi.version}
Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java Fri Jan 2 07:17:11 2009
@@ -37,7 +37,16 @@
private String[] includes;
public boolean accept(File pathname) {
- String path = pathname.getPath();
+ return acceptPathName(pathname.getPath());
+ }
+
+ /**
+ * Accepts the given file by the path name
+ *
+ * @param path the path
+ * @return <tt>true</tt> if accepted, <tt>false</tt> if not
+ */
+ public boolean acceptPathName(String path) {
// must use single / as path seperators
path = StringUtils.replace(path, File.separator, "/");
Modified: activemq/camel/trunk/tests/camel-itest/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/pom.xml?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/pom.xml (original)
+++ activemq/camel/trunk/tests/camel-itest/pom.xml Fri Jan 2 07:17:11 2009
@@ -20,136 +20,170 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-parent</artifactId>
- <version>2.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>camel-itest</artifactId>
- <name>Camel :: Integration Tests</name>
- <description>Performs cross component integration tests</description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-jms</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-cxf</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-jetty</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-http</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-camel</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.xbean</groupId>
- <artifactId>xbean-spring</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>spring</artifactId>
- </exclusion>
- </exclusions>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkMode>pertest</forkMode>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-codegen-plugin</artifactId>
- <version>${cxf-version}</version>
- <executions>
- <execution>
- <id>generate-test-sources</id>
- <phase>generate-sources</phase>
- <configuration>
- <testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
- <wsdlOptions>
- <wsdlOption>
- <wsdl>
- ${basedir}/src/test/resources/wsdl/CustomerService-1.0.0.wsdl
- </wsdl>
- </wsdlOption>
- <wsdlOption>
- <wsdl>
- ${basedir}/src/test/resources/wsdl/hello_world.wsdl
- </wsdl>
- </wsdlOption>
- </wsdlOptions>
- </configuration>
- <goals>
- <goal>wsdl2java</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-itest</artifactId>
+ <name>Camel :: Integration Tests</name>
+ <description>Performs cross component integration tests</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jms</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-cxf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jetty</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-http</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-ftp</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ftpserver</groupId>
+ <artifactId>ftpserver-core</artifactId>
+ <version>1.0.0-M3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ftpserver</groupId>
+ <artifactId>ftplet-api</artifactId>
+ <version>1.0.0-M3</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- ftpserver using mina 2.0.0-M2 -->
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-core</artifactId>
+ <version>2.0.0-M2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-camel</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-spring</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-codegen-plugin</artifactId>
+ <version>${cxf-version}</version>
+ <executions>
+ <execution>
+ <id>generate-test-sources</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
+ <wsdlOptions>
+ <wsdlOption>
+ <wsdl>
+ ${basedir}/src/test/resources/wsdl/CustomerService-1.0.0.wsdl
+ </wsdl>
+ </wsdlOption>
+ <wsdlOption>
+ <wsdl>
+ ${basedir}/src/test/resources/wsdl/hello_world.wsdl
+ </wsdl>
+ </wsdlOption>
+ </wsdlOptions>
+ </configuration>
+ <goals>
+ <goal>wsdl2java</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
Added: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java?rev=730753&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java Fri Jan 2 07:17:11 2009
@@ -0,0 +1,87 @@
+/**
+ * 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.itest.ftp;
+
+import java.io.File;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor;
+import org.apache.ftpserver.usermanager.PropertiesUserManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+/**
+ * Unit testing FTP ant path matcher
+ */
+@ContextConfiguration
+public class SpringFileAntPathMatcherRemoteFileFilterTest extends AbstractJUnit38SpringContextTests {
+ protected FtpServer ftpServer;
+
+ protected String expectedBody = "Godday World";
+ @Autowired
+ protected ProducerTemplate template;
+ @EndpointInject(name = "myFTPEndpoint")
+ protected Endpoint inputFTP;
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint result;
+
+ public void testAntPatchMatherFilter() throws Exception {
+ result.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(inputFTP, "Hello World", FileComponent.HEADER_FILE_NAME, "hello.txt");
+ template.sendBodyAndHeader(inputFTP, "Bye World", FileComponent.HEADER_FILE_NAME, "bye.xml");
+ template.sendBodyAndHeader(inputFTP, "Bad world", FileComponent.HEADER_FILE_NAME, "subfolder/badday.txt");
+ template.sendBodyAndHeader(inputFTP, "Day world", FileComponent.HEADER_FILE_NAME, "day.xml");
+ template.sendBodyAndHeader(inputFTP, expectedBody, FileComponent.HEADER_FILE_NAME, "subfolder/foo/godday.txt");
+
+ result.assertIsSatisfied();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ initFtpServer();
+ ftpServer.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ ftpServer.stop();
+ ftpServer = null;
+ }
+
+ protected void initFtpServer() throws Exception {
+ ftpServer = new FtpServer();
+
+ // setup user management to read our users.properties and use clear text passwords
+ PropertiesUserManager uman = new PropertiesUserManager();
+ uman.setFile(new File("./src/test/resources/users.properties").getAbsoluteFile());
+ uman.setPasswordEncryptor(new ClearTextPasswordEncryptor());
+ uman.setAdminName("admin");
+ uman.configure();
+ ftpServer.setUserManager(uman);
+
+ ftpServer.getListener("default").setPort(20123);
+ }
+
+}
+
Modified: activemq/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties?rev=730753&r1=730752&r2=730753&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties Fri Jan 2 07:17:11 2009
@@ -22,7 +22,9 @@
log4j.logger.org.springframework=WARN
log4j.logger.org.apache.activemq=WARN
+#log4j.logger.org.apache.camel=TRACE
#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.camel.component.file=TRACE
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
Added: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml?rev=730753&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml Fri Jan 2 07:17:11 2009
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <template id="camelTemplate"/>
+
+ <!-- use myFilter as filter to allow setting ANT paths for which files to scan for -->
+ <endpoint id="myFTPEndpoint" uri="ftp://admin@localhost:20123/antpath?password=admin&recursive=true&delay=10000&initialDelay=2000&filter=#myAntFilter"/>
+
+ <route>
+ <from ref="myFTPEndpoint"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+ <!-- we use the AntPathMatcherRemoteFileFilter to use ant paths for includes and exlucde -->
+ <bean id="myAntFilter" class="org.apache.camel.component.file.remote.AntPathMatcherRemoteFileFilter">
+ <!-- include and file in the subfolder that has day in the name -->
+ <property name="includes" value="**/subfolder/**/*day*"/>
+ <!-- exclude all files with bad in name or .xml files. Use comma to seperate multiple excludes -->
+ <property name="excludes" value="**/*bad*,**/*.xml"/>
+ </bean>
+ <!-- END SNIPPET: example -->
+
+</beans>
Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: activemq/camel/trunk/tests/camel-itest/src/test/resources/users.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/users.properties?rev=730753&view=auto
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/users.properties (added)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/users.properties Fri Jan 2 07:17:11 2009
@@ -0,0 +1,12 @@
+ftpserver.user.admin
+ftpserver.user.admin.userpassword=admin
+ftpserver.user.admin.homedirectory=./res/home
+ftpserver.user.admin.writepermission=true
+ftpserver.user.scott
+ftpserver.user.scott.userpassword=tiger
+ftpserver.user.scott.homedirectory=./res/home
+ftpserver.user.scott.writepermission=true
+ftpserver.user.dummy
+ftpserver.user.dummy.userpassword=foo
+ftpserver.user.dummy.homedirectory=./res/home
+ftpserver.user.dummy.writepermission=false
Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/users.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/tests/camel-itest/src/test/resources/users.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date