You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/02/14 11:42:21 UTC

[camel] branch camel-3.7.x updated (a86d166 -> 75df16f)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch camel-3.7.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from a86d166  CAMEL-16203: camel-core - Optimize removeHeaders all
     new 38f06b1  CAMEL-16202: Polished
     new 75df16f  CAMEL-16202: camel-core - Optimize DefaultHeaderFilterStrategy filtering

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/camel/spi/HeaderFilterStrategy.java |  4 +-
 .../camel/support/DefaultHeaderFilterStrategy.java | 44 ++++++++++++++++------
 2 files changed, 35 insertions(+), 13 deletions(-)


[camel] 02/02: CAMEL-16202: camel-core - Optimize DefaultHeaderFilterStrategy filtering

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.7.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 75df16f4b4a6a666e37ec006cd17fc74411246c0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 14 12:40:19 2021 +0100

    CAMEL-16202: camel-core - Optimize DefaultHeaderFilterStrategy filtering
---
 .../camel/support/DefaultHeaderFilterStrategy.java | 23 +++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
index eff21be..fa1ad2a 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
@@ -275,8 +275,22 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
             filter = inFilter;
         }
 
-        if (pattern != null && pattern.matcher(headerName).matches()) {
-            return filterOnMatch;
+        String lower = null;
+        if (pattern != null) {
+            // optimize if its the default pattern as we know the pattern is to check for keys starting with Camel
+            if (pattern == CAMEL_FILTER_PATTERN) {
+                boolean match = headerName.startsWith("org.apache.camel.") || headerName.startsWith("Camel");
+                if (!match) {
+                    // the default filter is case insensitive so check for lower case starting match
+                    lower = headerName.toLowerCase(Locale.ENGLISH);
+                    match = lower.startsWith("org.apache.camel.") || lower.startsWith("camel");
+                }
+                if (match) {
+                    return filterOnMatch;
+                }
+            } else if (pattern.matcher(headerName).matches()) {
+                return filterOnMatch;
+            }
         }
 
         if (filter != null) {
@@ -287,7 +301,10 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
                     }
                 }
             } else if (isLowerCase()) {
-                if (filter.contains(headerName.toLowerCase(Locale.ENGLISH))) {
+                if (lower == null) {
+                    lower = headerName.toLowerCase(Locale.ENGLISH);
+                }
+                if (filter.contains(lower)) {
                     return filterOnMatch;
                 }
             } else {


[camel] 01/02: CAMEL-16202: Polished

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.7.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 38f06b11d69ca1c3df2a595bb0e5e9a6d8c7cb34
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 14 09:38:35 2021 +0100

    CAMEL-16202: Polished
---
 .../org/apache/camel/spi/HeaderFilterStrategy.java  |  4 ++--
 .../camel/support/DefaultHeaderFilterStrategy.java  | 21 +++++++++++++--------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java b/core/camel-api/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java
index a8cadae..9a2d651 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java
@@ -41,7 +41,7 @@ public interface HeaderFilterStrategy {
      * @param  headerName  the header name
      * @param  headerValue the header value
      * @param  exchange    the context to perform filtering
-     * @return             <tt>true</tt> if this header should be filtered out.
+     * @return             <tt>true</tt> if this header should be filtered (skipped).
      */
     boolean applyFilterToCamelHeaders(String headerName, Object headerValue, Exchange exchange);
 
@@ -55,7 +55,7 @@ public interface HeaderFilterStrategy {
      * @param  headerName  the header name
      * @param  headerValue the header value
      * @param  exchange    the context to perform filtering
-     * @return             <tt>true</tt> if this header should be filtered out.
+     * @return             <tt>true</tt> if this header should be filtered (skipped).
      */
     boolean applyFilterToExternalHeaders(String headerName, Object headerValue, Exchange exchange);
 
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
index a26e603..eff21be 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
@@ -89,7 +89,7 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
     /**
      * Gets the "out" direction filter regular expression {@link Pattern}. The "out" direction is referred to copying
      * headers from Camel message to an external message. If the pattern matches a header, the header will be filtered
-     * out.
+     * (skipped).
      *
      * @return regular expression filter pattern
      */
@@ -100,7 +100,7 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
     /**
      * Sets the "out" direction filter regular expression {@link Pattern}. The "out" direction is referred to copying
      * headers from Camel message to an external message. If the pattern matches a header, the header will be filtered
-     * out.
+     * (skipped).
      *
      * @param value regular expression filter pattern
      */
@@ -115,7 +115,7 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
     /**
      * Sets the "out" direction filter regular expression {@link Pattern}. The "out" direction is referred to copying
      * headers from Camel message to an external message. If the pattern matches a header, the header will be filtered
-     * out.
+     * (skipped).
      *
      * @param pattern regular expression filter pattern
      */
@@ -149,7 +149,7 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
     /**
      * Gets the "in" direction filter regular expression {@link Pattern}. The "in" direction is referred to copying
      * headers from an external message to a Camel message. If the pattern matches a header, the header will be filtered
-     * out.
+     * (skipped).
      *
      * @return regular expression filter pattern
      */
@@ -160,7 +160,7 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
     /**
      * Sets the "in" direction filter regular expression {@link Pattern}. The "in" direction is referred to copying
      * headers from an external message to a Camel message. If the pattern matches a header, the header will be filtered
-     * out.
+     * (skipped).
      *
      * @param value regular expression filter pattern
      */
@@ -175,7 +175,7 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
     /**
      * Sets the "in" direction filter regular expression {@link Pattern}. The "in" direction is referred to copying
      * headers from an external message to a Camel message. If the pattern matches a header, the header will be filtered
-     * out.
+     * (skipped).
      *
      * @param pattern regular expression filter pattern
      */
@@ -223,6 +223,11 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
         return allowNullValues;
     }
 
+    /**
+     * Whether to allow null values.
+     *
+     * By default a header is skipped if its value is null. Setting this to true will preserve the header.
+     */
     public void setAllowNullValues(boolean value) {
         allowNullValues = value;
     }
@@ -238,9 +243,9 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
      * When set to true, a match will filter out the header. This is the default value for backwards compatibility.
      *
      * When set to false, the pattern or filter will indicate that the header must be kept; anything not matched will be
-     * filtered out.
+     * filtered (skipped).
      *
-     * @param filterOnMatch <tt>true</tt> if a match filters out the header.
+     * @param filterOnMatch <tt>true</tt> if a match filters (skips) the header.
      */
     public void setFilterOnMatch(boolean filterOnMatch) {
         this.filterOnMatch = filterOnMatch;