camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7465 DefaultFilterStrategy should take an account of case insensitive with thanks to Seiji
Date Mon, 26 May 2014 06:45:15 GMT
Repository: camel
Updated Branches:
  refs/heads/master e52b40392 -> 26466b5b3


CAMEL-7465 DefaultFilterStrategy should take an account of case insensitive with thanks to
Seiji


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/26466b5b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/26466b5b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/26466b5b

Branch: refs/heads/master
Commit: 26466b5b3226ebaeb18a5666b11ccafd9a07cf15
Parents: e52b403
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon May 26 14:44:29 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon May 26 14:44:29 2014 +0800

----------------------------------------------------------------------
 .../camel/impl/DefaultHeaderFilterStrategy.java | 44 +++++++++++++++++---
 .../impl/DefaultHeaderFilterStrategyTest.java   | 19 +++++++++
 2 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/26466b5b/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
index a5fd680..86431cb 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
@@ -17,6 +17,7 @@
 package org.apache.camel.impl;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Locale;
 import java.util.Set;
 import java.util.regex.Pattern;
@@ -49,6 +50,7 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy
{
 
     private boolean lowerCase;
     private boolean allowNullValues;
+    private boolean caseInsensitive;
     
     public boolean applyFilterToCamelHeaders(String headerName, Object headerValue, Exchange
exchange) {
         return doFiltering(Direction.OUT, headerName, headerValue, exchange);
@@ -163,8 +165,8 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy
{
 
     /**
      * Gets the isLowercase property which is a boolean to determine
-     * whether header names should be converted to lowercase before
-     * checking it the filter Set.  It does not affect filtering using
+     * whether header names should be converted to lower case before
+     * checking it with the filter Set.  It does not affect filtering using
      * regular expression pattern.
      */
     public boolean isLowerCase() {
@@ -173,13 +175,37 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy
{
     
     /**
      * Sets the isLowercase property which is a boolean to determine
-     * whether header names should be converted to lowercase before
-     * checking it the filter Set.  It does not affect filtering using
+     * whether header names should be converted to lower case before
+     * checking it with the filter Set.  It does not affect filtering using
      * regular expression pattern.
      */
     public void setLowerCase(boolean value) {
         lowerCase = value;
     }
+
+    /**
+     * Gets the caseInsensitive property which is a boolean to determine
+     * whether header names should be case insensitive when checking it 
+     * with the filter set.
+     * It does not affect filtering using regular expression pattern.
+     * 
+     * @return <tt>true</tt> if header names is case insensitive. 
+     */
+    public boolean isCaseInsensitive() {
+        return caseInsensitive;
+    }
+
+    /**
+     * Sets the caseInsensitive property which is a boolean to determine
+     * whether header names should be case insensitive when checking it 
+     * with the filter set.
+     * It does not affect filtering using regular expression pattern,
+     * 
+     * @param caseInsensitive <tt>true</tt> if header names is case insensitive.
+     */
+    public void setCaseInsensitive(boolean caseInsensitive) {
+        this.caseInsensitive = caseInsensitive;
+    }
     
     public boolean isAllowNullValues() {
         return allowNullValues;
@@ -218,7 +244,15 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy
{
         }
             
         if (filter != null) {
-            if (isLowerCase()) {
+            if (isCaseInsensitive()) {
+                Iterator<String> it = filter.iterator();
+                while (it.hasNext()) {
+                    String filterString = (String) it.next();
+                    if (filterString.equalsIgnoreCase(headerName)) {
+                        return true;
+                    }
+                }
+            } else if (isLowerCase()) {
                 if (filter.contains(headerName.toLowerCase(Locale.ENGLISH))) {
                     return true;
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/26466b5b/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
b/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
index ac30e1b..fa71415 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
@@ -35,6 +35,9 @@ public class DefaultHeaderFilterStrategyTest extends ContextTestSupport
{
 
         comp.setLowerCase(true);
         assertEquals(true, comp.isLowerCase());
+        
+        comp.setCaseInsensitive(true);
+        assertEquals(true, comp.isCaseInsensitive());
     }
 
     public void testInFilterDefaultHeaderFilterStrategy() {
@@ -86,5 +89,21 @@ public class DefaultHeaderFilterStrategyTest extends ContextTestSupport
{
         assertFalse(comp.applyFilterToCamelHeaders("bar", 123, exchange));
         assertTrue(comp.applyFilterToCamelHeaders("foo", "cheese", exchange));
     }
+    
+    public void testCaseInsensitiveHeaderNameDoFilterDefaultHeaderFilterStrategy() {
+        DefaultHeaderFilterStrategy comp = new DefaultHeaderFilterStrategy();
+        comp.setCaseInsensitive(true);
+        
+        Set<String> set = new HashSet<String>();
+        set.add("Content-Type");
+        comp.setOutFilter(set);
 
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setHeader("content-type", "application/xml");
+        exchange.getIn().setHeader("Content-Type", "application/json");
+
+        assertTrue(comp.applyFilterToCamelHeaders("content-type", "application/xml", exchange));
+        assertTrue(comp.applyFilterToCamelHeaders("Content-Type", "application/json", exchange));
+    }
+    
 }


Mime
View raw message