Repository: camel Updated Branches: refs/heads/master e284fd657 -> 5091f938c
Enable Case Sensitive pattern match for file include and exclude Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b4d05211 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b4d05211 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b4d05211 Branch: refs/heads/master Commit: b4d0521162e890209ef089c7417513a930d96e4e Parents: e284fd6 Author: dwarakart <dwaraka.ram...@gmail.com> Authored: Sat Nov 21 10:36:49 2015 +0000 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Nov 25 14:00:54 2015 +0100 ---------------------------------------------------------------------- .../component/file/GenericFileConsumer.java | 20 +++++- .../component/file/GenericFileEndpoint.java | 14 +++++ ...ileConsumerExcludeNameCaseSensitiveTest.java | 58 ++++++++++++++++++ .../file/FileConsumerExcludeNameTest.java | 8 ++- ...rIncludeAndExcludeNameCaseSensitiveTest.java | 64 ++++++++++++++++++++ .../FileConsumerIncludeAndExcludeNameTest.java | 4 +- ...ileConsumerIncludeNameCaseSensitiveTest.java | 64 ++++++++++++++++++++ .../file/FileConsumerIncludeNameTest.java | 4 +- 8 files changed, 229 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java index d1f58d6..7fc75d4 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java @@ -597,14 +597,30 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum return true; } + // Check for case sensitive flag + boolean caseSensitive = true; + if (ObjectHelper.isNotEmpty(endpoint.getCaseSensitive())) { + caseSensitive = endpoint.getCaseSensitive(); + } + if (ObjectHelper.isNotEmpty(endpoint.getExclude())) { - if (name.matches(endpoint.getExclude())) { + String excludePattern = endpoint.getExclude(); + if (caseSensitive == false ) { + if (name.toUpperCase().matches(excludePattern.toUpperCase())) { + return false; + } + } else if (name.matches(excludePattern)) { return false; } } if (ObjectHelper.isNotEmpty(endpoint.getInclude())) { - if (!name.matches(endpoint.getInclude())) { + String includePattern = endpoint.getInclude(); + if (caseSensitive == false) { + if (!name.toUpperCase().matches(includePattern.toUpperCase())) { + return false; + } + } else if (!name.matches(includePattern)) { return false; } } http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java index c81e2d3..7183847 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java @@ -129,6 +129,8 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple protected String include; @UriParam(label = "consumer,filter") protected String exclude; + @UriParam(label = "consumer,filter", defaultValue = "true") + protected Boolean caseSensitive; @UriParam(label = "consumer,filter") protected Expression move; @UriParam(label = "consumer") @@ -441,6 +443,18 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple this.exclude = exclude; } + public Boolean getCaseSensitive() { + return caseSensitive; + } + + /** + * Is used to determine if the include & exclude patterns are case sensitive or not + * @param caseSensitive + */ + public void setCaseSensitive(Boolean caseSensitive) { + this.caseSensitive = caseSensitive; + } + public String getAntInclude() { return antInclude; } http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameCaseSensitiveTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameCaseSensitiveTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameCaseSensitiveTest.java new file mode 100644 index 0000000..bb243ff --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameCaseSensitiveTest.java @@ -0,0 +1,58 @@ +/** + * 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; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +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 FileConsumerExcludeNameCaseSensitiveTest extends ContextTestSupport { + + public void testExludePreAndPostfixes() throws Exception { + deleteDirectory("target/exclude"); + prepareFiles(); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Reports", "Reports", "Reports3"); + mock.expectedMessageCount(3); + mock.assertIsSatisfied(); + } + + private void prepareFiles() throws Exception { + String url = "file://target/exclude"; + template.sendBodyAndHeader(url, "Hello World", Exchange.FILE_NAME, "hello.xml"); + template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report1.txt"); + template.sendBodyAndHeader(url, "Bye World", Exchange.FILE_NAME, "secret.txt"); + template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report2.txt"); + template.sendBodyAndHeader(url, "Reports3", Exchange.FILE_NAME, "Report3.txt"); + template.sendBodyAndHeader(url, "Secret2", Exchange.FILE_NAME, "Secret2.txt"); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("file://target/exclude/?exclude=^secret.*|.*xml$&caseSensitive=false") + .convertBodyTo(String.class).to("mock:result"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java index fed3913..cda3e5a 100644 --- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java @@ -31,8 +31,8 @@ public class FileConsumerExcludeNameTest extends ContextTestSupport { prepareFiles(); MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(2); - mock.expectedBodiesReceived("Reports", "Reports"); + mock.expectedBodiesReceived("Reports", "Reports", "Reports3", "Secret2"); + mock.expectedMessageCount(4); mock.assertIsSatisfied(); } @@ -42,12 +42,14 @@ public class FileConsumerExcludeNameTest extends ContextTestSupport { template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report1.txt"); template.sendBodyAndHeader(url, "Bye World", Exchange.FILE_NAME, "secret.txt"); template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report2.txt"); + template.sendBodyAndHeader(url, "Reports3", Exchange.FILE_NAME, "Report3.txt"); + template.sendBodyAndHeader(url, "Secret2", Exchange.FILE_NAME, "Secret2.txt"); } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("file://target/exclude/?exclude=^secret.*|.*xml$") + from("file://target/exclude/?exclude=^secret.*|.*xml$&caseSensitive=true") .convertBodyTo(String.class).to("mock:result"); } }; http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameCaseSensitiveTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameCaseSensitiveTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameCaseSensitiveTest.java new file mode 100644 index 0000000..f4593ec --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameCaseSensitiveTest.java @@ -0,0 +1,64 @@ +/** + * 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; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * Unit test that file consumer will include/exclude pre and postfixes + */ +public class FileConsumerIncludeAndExcludeNameCaseSensitiveTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/includeexclude"); + super.setUp(); + } + + public void testIncludePreAndPostfixes() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceivedInAnyOrder("Report 2", "Report 3", "Report 4"); + mock.expectedMessageCount(3); + + sendFiles(); + + mock.assertIsSatisfied(); + } + + private void sendFiles() throws Exception { + String url = "file://target/includeexclude"; + template.sendBodyAndHeader(url, "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(url, "Report 1", Exchange.FILE_NAME, "report1.xml"); + template.sendBodyAndHeader(url, "Report 2", Exchange.FILE_NAME, "report2.txt"); + template.sendBodyAndHeader(url, "Report 3", Exchange.FILE_NAME, "report3.txt"); + template.sendBodyAndHeader(url, "Report 4", Exchange.FILE_NAME, "Report4.txt"); + template.sendBodyAndHeader(url, "Secret", Exchange.FILE_NAME, "Secret.txt"); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("file://target/includeexclude/?include=report.*txt&exclude=hello.*&caseSensitive=false") + .convertBodyTo(String.class).to("mock:result"); + } + }; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java index 1124ad8..5ee697b 100644 --- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java @@ -48,12 +48,14 @@ public class FileConsumerIncludeAndExcludeNameTest extends ContextTestSupport { template.sendBodyAndHeader(url, "Report 1", Exchange.FILE_NAME, "report1.xml"); template.sendBodyAndHeader(url, "Report 2", Exchange.FILE_NAME, "report2.txt"); template.sendBodyAndHeader(url, "Report 3", Exchange.FILE_NAME, "report3.txt"); + template.sendBodyAndHeader(url, "Report 4", Exchange.FILE_NAME, "Report4.txt"); + template.sendBodyAndHeader(url, "Secret", Exchange.FILE_NAME, "Secret.txt"); } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("file://target/includeexclude/?include=.*txt&exclude=hello.*") + from("file://target/includeexclude/?include=report.*txt&exclude=hello.*") .convertBodyTo(String.class).to("mock:result"); } }; http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameCaseSensitiveTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameCaseSensitiveTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameCaseSensitiveTest.java new file mode 100644 index 0000000..a6b54a1 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameCaseSensitiveTest.java @@ -0,0 +1,64 @@ +/** + * 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; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * Unit test that file consumer will include pre and postfixes + */ +public class FileConsumerIncludeNameCaseSensitiveTest extends ContextTestSupport { + + @Override + protected void setUp() throws Exception { + deleteDirectory("target/include"); + super.setUp(); + } + + public void testIncludePreAndPostfixes() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Reports", "Reports", "Reports3"); + mock.expectedMessageCount(3); + + sendFiles(); + + mock.assertIsSatisfied(); + } + + private void sendFiles() throws Exception { + String url = "file://target/include"; + template.sendBodyAndHeader(url, "Hello World", Exchange.FILE_NAME, "hello.xml"); + template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report1.txt"); + template.sendBodyAndHeader(url, "Bye World", Exchange.FILE_NAME, "secret.txt"); + template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report2.txt"); + template.sendBodyAndHeader(url, "Reports3", Exchange.FILE_NAME, "Report3.txt"); + template.sendBodyAndHeader(url, "Secret2", Exchange.FILE_NAME, "Secret2.txt"); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("file://target/include/?include=^report.*txt$&caseSensitive=false") + .convertBodyTo(String.class).to("mock:result"); + } + }; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b4d05211/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java index 822232b..50820f3 100644 --- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java @@ -34,8 +34,8 @@ public class FileConsumerIncludeNameTest extends ContextTestSupport { public void testIncludePreAndPostfixes() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(2); mock.expectedBodiesReceived("Reports", "Reports"); + mock.expectedMessageCount(2); sendFiles(); @@ -48,6 +48,8 @@ public class FileConsumerIncludeNameTest extends ContextTestSupport { template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report1.txt"); template.sendBodyAndHeader(url, "Bye World", Exchange.FILE_NAME, "secret.txt"); template.sendBodyAndHeader(url, "Reports", Exchange.FILE_NAME, "report2.txt"); + template.sendBodyAndHeader(url, "Reports3", Exchange.FILE_NAME, "Report3.txt"); + template.sendBodyAndHeader(url, "Secret2", Exchange.FILE_NAME, "Secret2.txt"); } protected RouteBuilder createRouteBuilder() throws Exception {