Repository: camel Updated Branches: refs/heads/camel-2.13.x 4460d796c -> 84f1390d4 refs/heads/camel-2.14.x 64463f801 -> adbb1936d
CAMEL-8248 Camel Mail should filter the 'Camel*' out header by default. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/adbb1936 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/adbb1936 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/adbb1936 Branch: refs/heads/camel-2.14.x Commit: adbb1936d9d0cd5c52a37d82986f2451932d32b6 Parents: 64463f8 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Thu Jan 15 12:49:51 2015 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Thu Jan 15 13:00:25 2015 +0800 ---------------------------------------------------------------------- .../camel/component/mail/MailEndpoint.java | 3 +- .../mail/MailHeaderFilterStrategy.java | 32 ++++++++++++++++++++ .../component/mail/MailUsingHeadersTest.java | 6 ++++ 3 files changed, 39 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/adbb1936/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java index e1345ac..ffbcb59 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java @@ -25,7 +25,6 @@ import org.apache.camel.ExchangePattern; import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.impl.DefaultExchange; -import org.apache.camel.impl.DefaultHeaderFilterStrategy; import org.apache.camel.impl.ScheduledPollEndpoint; import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.spi.UriEndpoint; @@ -41,7 +40,7 @@ public class MailEndpoint extends ScheduledPollEndpoint { private MailBinding binding; @UriParam private MailConfiguration configuration; - private HeaderFilterStrategy headerFilterStrategy = new DefaultHeaderFilterStrategy(); + private HeaderFilterStrategy headerFilterStrategy = new MailHeaderFilterStrategy(); private ContentTypeResolver contentTypeResolver; @UriParam private int maxMessagesPerPoll; http://git-wip-us.apache.org/repos/asf/camel/blob/adbb1936/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailHeaderFilterStrategy.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailHeaderFilterStrategy.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailHeaderFilterStrategy.java new file mode 100644 index 0000000..5bcbb12 --- /dev/null +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailHeaderFilterStrategy.java @@ -0,0 +1,32 @@ +/** + * 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.mail; + +import org.apache.camel.impl.DefaultHeaderFilterStrategy; + +public class MailHeaderFilterStrategy extends DefaultHeaderFilterStrategy { + + public MailHeaderFilterStrategy() { + initialize(); + } + + protected void initialize() { + // filter headers begin with "Camel" or "org.apache.camel" + setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/adbb1936/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingHeadersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingHeadersTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingHeadersTest.java index d967e2c..ad0fbb6 100644 --- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingHeadersTest.java +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingHeadersTest.java @@ -40,6 +40,8 @@ public class MailUsingHeadersTest extends CamelTestSupport { map.put("To", "davscl...@apache.org"); map.put("From", "jstrac...@apache.org"); map.put("Subject", "Camel rocks"); + map.put("CamelFileName", "fileOne"); + map.put("org.apache.camel.test", "value"); String body = "Hello Claus.\nYes it does.\n\nRegards James."; template.sendBodyAndHeaders("smtp://davscl...@apache.org", body, map); @@ -50,6 +52,9 @@ public class MailUsingHeadersTest extends CamelTestSupport { assertEquals("davscl...@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString()); assertEquals("jstrac...@apache.org", msg.getFrom()[0].toString()); assertEquals("Camel rocks", msg.getSubject()); + + assertNull("We should not get the message header here", msg.getHeader("CamelFileName")); + assertNull("We should not get the message header here", msg.getHeader("org.apache.camel.test")); } @Test @@ -67,6 +72,7 @@ public class MailUsingHeadersTest extends CamelTestSupport { assertEquals("davscl...@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString()); assertEquals("James Strachan <jstrac...@apache.org>", msg.getFrom()[0].toString()); assertEquals("Camel rocks", msg.getSubject()); + } protected RouteBuilder createRouteBuilder() throws Exception {