camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] camel git commit: CAMEL-8248 Camel Mail should filter the 'Camel*' out header by default.
Date Thu, 15 Jan 2015 04:58:38 GMT
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/87677b27
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/87677b27
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/87677b27

Branch: refs/heads/master
Commit: 87677b27ddbd56b278ae5ab63d8c35e40e7f4de4
Parents: 6235e02
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Thu Jan 15 12:49:51 2015 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Thu Jan 15 12:57:59 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/87677b27/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 dbda337..6fe665a 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
@@ -27,7 +27,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/87677b27/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/87677b27/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", "davsclaus@apache.org");
         map.put("From", "jstrachan@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://davsclaus@apache.org", body, map);
@@ -50,6 +52,9 @@ public class MailUsingHeadersTest extends CamelTestSupport {
         assertEquals("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
         assertEquals("jstrachan@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("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
         assertEquals("James Strachan <jstrachan@apache.org>", msg.getFrom()[0].toString());
         assertEquals("Camel rocks", msg.getSubject());
+        
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {


Mime
View raw message