Author: davsclaus
Date: Thu Jul 31 11:05:26 2008
New Revision: 681428
URL: http://svn.apache.org/viewvc?rev=681428&view=rev
Log:
CAMEL-767: ExcludedName pre- and postfix is now only a single String type.
@deprecated the String[] type that is unfriendly for URI configuration. Added
more options to FTP consumer that the File consumer has.
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java
(with props)
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java
(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/component/file/FileEndpoint.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
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=681428&r1=681427&r2=681428&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
Thu Jul 31 11:05:26 2008
@@ -306,6 +306,11 @@
}
}
+ if (endpoint.getExcludedNamePrefix() != null) {
+ if (name.startsWith(endpoint.getExcludedNamePrefix())) {
+ return false;
+ }
+ }
String[] prefixes = endpoint.getExcludedNamePrefixes();
if (prefixes != null) {
for (String prefix : prefixes) {
@@ -314,6 +319,11 @@
}
}
}
+ if (endpoint.getExcludedNamePostfix() != null) {
+ if (name.endsWith(endpoint.getExcludedNamePostfix())) {
+ return false;
+ }
+ }
String[] postfixes = endpoint.getExcludedNamePostfixes();
if (postfixes != null) {
for (String postfix : postfixes) {
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=681428&r1=681427&r2=681428&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
Thu Jul 31 11:05:26 2008
@@ -56,6 +56,8 @@
private String moveNamePostfix;
private String[] excludedNamePrefixes;
private String[] excludedNamePostfixes;
+ private String excludedNamePrefix;
+ private String excludedNamePostfix;
private int bufferSize = 128 * 1024;
private boolean ignoreFileNameHeader;
@@ -107,7 +109,6 @@
return new FileExchange(getCamelContext(), pattern, file);
}
-
/**
* Return the file name that will be auto-generated for the given message
if none is provided
*/
@@ -218,6 +219,8 @@
/**
* Sets the excluded file name prefixes, such as <tt>"."</tt> for hidden
files which
* are excluded by default
+ *
+ * @deprecated use ExcludedNamePrefix. Will be removed in Camel 2.0.
*/
public void setExcludedNamePrefixes(String[] excludedNamePrefixes) {
this.excludedNamePrefixes = excludedNamePrefixes;
@@ -230,6 +233,8 @@
/**
* Sets the excluded file name postfixes, such as [EMAIL PROTECTED]
FileProcessStrategySupport#DEFAULT_LOCK_FILE_POSTFIX}
* to ignore lock files by default.
+ *
+ * @deprecated use ExcludedNamePostfix. Will be removed in Camel 2.0.
*/
public void setExcludedNamePostfixes(String[] excludedNamePostfixes) {
this.excludedNamePostfixes = excludedNamePostfixes;
@@ -283,6 +288,22 @@
this.ignoreFileNameHeader = ignoreFileNameHeader;
}
+ public String getExcludedNamePrefix() {
+ return excludedNamePrefix;
+ }
+
+ public void setExcludedNamePrefix(String excludedNamePrefix) {
+ this.excludedNamePrefix = excludedNamePrefix;
+ }
+
+ public String getExcludedNamePostfix() {
+ return excludedNamePostfix;
+ }
+
+ public void setExcludedNamePostfix(String excludedNamePostfix) {
+ this.excludedNamePostfix = excludedNamePostfix;
+ }
+
/**
* A strategy method to lazily create the file strategy
*/
@@ -342,7 +363,7 @@
return "file://" + getFile().getAbsolutePath();
}
- protected String getFileFriendlyMessageId(String id) {
+ protected String getFileFriendlyMessageId(String id) {
return UuidGenerator.generateSanitizedId(id);
}
}
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java?rev=681428&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java
(added)
+++
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java
Thu Jul 31 11:05:26 2008
@@ -0,0 +1,39 @@
+package org.apache.camel.component.file;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Unit test that file consumer will exclude pre and postfixes
+ */
+public class FileConsumerExcludeNameTest extends ContextTestSupport {
+
+ public void testExludePreAndPostfixes() throws Exception {
+ deleteDirectory("./target/exclude");
+ prepareFiles();
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+ mock.expectedBodiesReceived("Report 1", "Report 2");
+ mock.assertIsSatisfied();
+ }
+
+ private void prepareFiles() throws Exception {
+ String url = "file://target/exclude/";
+ template.sendBodyAndHeader(url, "Hello World",
FileComponent.HEADER_FILE_NAME, "hello.xml");
+ template.sendBodyAndHeader(url, "Report 1",
FileComponent.HEADER_FILE_NAME, "report1.txt");
+ template.sendBodyAndHeader(url, "Bye World",
FileComponent.HEADER_FILE_NAME, "secret.txt");
+ template.sendBodyAndHeader(url, "Report 2",
FileComponent.HEADER_FILE_NAME, "report2.txt");
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+
from("file://target/exclude/?excludedNamePrefix=secret&excludedNamePostfix=xml")
+ .to("mock:result");
+ }
+ };
+ }
+
+}
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
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=681428&r1=681427&r2=681428&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
Thu Jul 31 11:05:26 2008
@@ -35,13 +35,16 @@
protected boolean deleteFile;
protected String moveNamePrefix;
protected String moveNamePostfix;
+ protected String excludedNamePrefix;
+ protected String excludedNamePostfix;
public RemoteFileConsumer(RemoteFileEndpoint<T> endpoint, Processor
processor) {
super(endpoint, processor);
this.endpoint = endpoint;
}
- public RemoteFileConsumer(RemoteFileEndpoint<T> endpoint, Processor
processor, ScheduledExecutorService executor) {
+ public RemoteFileConsumer(RemoteFileEndpoint<T> endpoint, Processor
processor,
+ ScheduledExecutorService executor) {
super(endpoint, processor, executor);
}
@@ -54,21 +57,34 @@
protected abstract String getFileName(Object file);
/**
- * Is the given file matched to be consumed (will consider regexp if
provided as an option).
- * <p/>
- * Note: Returns true if no reg exp is used.
+ * Is the given file matched to be consumed.
*/
protected boolean isMatched(Object file) {
- String fileName = getFileName(file);
+ String name = getFileName(file);
+
+ // folders/names starting with dot is always skipped (eg. ".",
".camel", ".camelLock")
+ if (name.startsWith(".")) {
+ return false;
+ }
- boolean result = true;
if (regexPattern != null && regexPattern.length() > 0) {
- result = fileName.matches(regexPattern);
+ if (!name.matches(regexPattern)) {
+ return false;
+ }
+ }
+
+ if (excludedNamePrefix != null) {
+ if (name.startsWith(excludedNamePrefix)) {
+ return false;
+ }
}
- if (LOG.isTraceEnabled()) {
- LOG.trace("Matching file: " + fileName + " is " + result);
+ if (excludedNamePostfix != null) {
+ if (name.endsWith(excludedNamePostfix)) {
+ return false;
+ }
}
- return result;
+
+ return true;
}
/**
@@ -80,7 +96,7 @@
/**
* Gets the to filename for moving.
- *
+ *
* @param name the original filename
* @return the move filename
*/
@@ -164,4 +180,19 @@
this.moveNamePostfix = moveNamePostfix;
}
+ public String getExcludedNamePrefix() {
+ return excludedNamePrefix;
+ }
+
+ public void setExcludedNamePrefix(String excludedNamePrefix) {
+ this.excludedNamePrefix = excludedNamePrefix;
+ }
+
+ public String getExcludedNamePostfix() {
+ return excludedNamePostfix;
+ }
+
+ public void setExcludedNamePostfix(String excludedNamePostfix) {
+ this.excludedNamePostfix = excludedNamePostfix;
+ }
}
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=681428&r1=681427&r2=681428&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
Thu Jul 31 11:05:26 2008
@@ -137,7 +137,9 @@
String currentDir = channel.pwd();
channel.cd(dir);
- for (ChannelSftp.LsEntry sftpFile :
(ChannelSftp.LsEntry[])channel.ls(".").toArray(new ChannelSftp.LsEntry[] {})) {
+ Vector files = channel.ls(".");
+ for (int i = 0; i < files.size(); i++) {
+ ChannelSftp.LsEntry sftpFile = (ChannelSftp.LsEntry)files.get(i);
if (sftpFile.getFilename().startsWith(".")) {
// skip
} else if (sftpFile.getAttrs().isDir()) {
Added:
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java?rev=681428&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java
(added)
+++
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java
Thu Jul 31 11:05:26 2008
@@ -0,0 +1,52 @@
+package org.apache.camel.component.file.remote;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test that ftp consumer will exclude pre and postfixes
+ */
+public class FtpConsumerExcludeNameTest extends FtpServerTestSupport {
+
+ private String port = "20095";
+
+ private String ftpUrl = "ftp://[EMAIL PROTECTED]:" + port +
"/excludename?password=admin"
+ +
"&consumer.excludedNamePrefix=secret&consumer.excludedNamePostfix=xml";
+
+ public void testExludePreAndPostfixes() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+ mock.expectedBodiesReceived("Report 1", "Report 2");
+ mock.assertIsSatisfied();
+ }
+
+ public String 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
+ String ftpUrl = "ftp://[EMAIL PROTECTED]:" + port +
"/excludename/?password=admin";
+ template.sendBodyAndHeader(ftpUrl, "Hello World",
FileComponent.HEADER_FILE_NAME, "hello.xml");
+ template.sendBodyAndHeader(ftpUrl, "Report 1",
FileComponent.HEADER_FILE_NAME, "report1.txt");
+ template.sendBodyAndHeader(ftpUrl, "Bye World",
FileComponent.HEADER_FILE_NAME, "secret.txt");
+ template.sendBodyAndHeader(ftpUrl, "Report 2",
FileComponent.HEADER_FILE_NAME, "report2.txt");
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(ftpUrl).to("mock:result");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Added:
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java?rev=681428&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java
(added)
+++
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java
Thu Jul 31 11:05:26 2008
@@ -0,0 +1,51 @@
+package org.apache.camel.component.file.remote;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test that ftp consumer will skip any files starting with a dot
+ */
+public class FtpConsumerSkipDotFilesTest extends FtpServerTestSupport {
+
+ private String port = "20096";
+
+ private String ftpUrl = "ftp://[EMAIL PROTECTED]:" + port +
"/dotfiles?password=admin";
+
+ public void testSkipDotFiles() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+ mock.expectedBodiesReceived("Report 1", "Report 2");
+ mock.assertIsSatisfied();
+ }
+
+ public String 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
+ String ftpUrl = "ftp://[EMAIL PROTECTED]:" + port +
"/dotfiles/?password=admin";
+ template.sendBodyAndHeader(ftpUrl, "Hello World",
FileComponent.HEADER_FILE_NAME, ".skipme");
+ template.sendBodyAndHeader(ftpUrl, "Report 1",
FileComponent.HEADER_FILE_NAME, "report1.txt");
+ template.sendBodyAndHeader(ftpUrl, "Bye World",
FileComponent.HEADER_FILE_NAME, ".camel");
+ template.sendBodyAndHeader(ftpUrl, "Report 2",
FileComponent.HEADER_FILE_NAME, "report2.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/FtpConsumerSkipDotFilesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date