camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] branch master updated: camel-core - Optimize to avoid regexp compiling the camel in/out header filter pattern.
Date Sun, 08 Mar 2020 11:47:52 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new f7a9ca8  camel-core - Optimize to avoid regexp compiling the camel in/out header
filter pattern.
f7a9ca8 is described below

commit f7a9ca86330b2ad4ca3686a083ae90e0eff5441a
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Sun Mar 8 12:46:53 2020 +0100

    camel-core - Optimize to avoid regexp compiling the camel in/out header filter pattern.
---
 .../component/ahc/HttpHeaderFilterStrategy.java    |  4 +--
 .../cxf/common/header/CxfHeaderFilterStrategy.java |  2 +-
 .../cxf/jaxrs/CxfRsHeaderFilterStrategy.java       |  2 +-
 .../http/common/HttpHeaderFilterStrategy.java      |  4 +--
 .../jetty/HttpBridgeMultipartRouteTest.java        |  2 +-
 .../component/kafka/KafkaHeaderFilterStrategy.java |  4 +--
 .../component/mail/MailHeaderFilterStrategy.java   |  2 +-
 .../netty/http/NettyHttpHeaderFilterStrategy.java  |  4 +--
 .../http/PlatformHttpHeaderFilterStrategy.java     |  2 +-
 .../sparkrest/SparkHeaderFilterStrategy.java       |  2 +-
 .../undertow/UndertowHeaderFilterStrategy.java     |  2 +-
 .../camel/support/DefaultHeaderFilterStrategy.java | 29 ++++++++++++++++++++++
 12 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpHeaderFilterStrategy.java
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpHeaderFilterStrategy.java
index 2112002..e951f8b 100644
--- a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpHeaderFilterStrategy.java
+++ b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpHeaderFilterStrategy.java
@@ -47,8 +47,8 @@ public class HttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
 
         // filter headers begin with "Camel" or "org.apache.camel"
         // must ignore case for Http based transports
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
-        setInFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
+        setInFilterPattern(CAMEL_FILTER_PATTERN);
     }
 
 }
diff --git a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderFilterStrategy.java
b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderFilterStrategy.java
index cdac812..7b85173 100644
--- a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderFilterStrategy.java
+++ b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderFilterStrategy.java
@@ -96,7 +96,7 @@ public class CxfHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
         addToMessageHeaderFilterMap(new SoapMessageHeaderFilter());
         
         // filter headers begin with "Camel" or "org.apache.camel"
-        setOutFilterPattern("(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
     }
 
     @SuppressWarnings("unchecked")
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
index 80a7918..1e930ba 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
@@ -34,7 +34,7 @@ public class CxfRsHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
         setLowerCase(true);
         
         // filter headers begin with "Camel" or "org.apache.camel"
-        setOutFilterPattern("(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
 
     }
 
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java
index cbef5de..7bed459 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java
@@ -44,7 +44,7 @@ public class HttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
         
         // filter headers begin with "Camel" or "org.apache.camel"
         // must ignore case for Http based transports
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
-        setInFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
+        setInFilterPattern(CAMEL_FILTER_PATTERN);
     }
 }
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
index ffb7da9..ec011aa 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
@@ -45,7 +45,7 @@ public class HttpBridgeMultipartRouteTest extends BaseJettyTest {
         protected void initialize() {
             setLowerCase(true);
             getOutFilter().add("content-length");
-            setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+            setOutFilterPattern(CAMEL_FILTER_PATTERN);
         }
     }
 
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaHeaderFilterStrategy.java
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaHeaderFilterStrategy.java
index 8c3fbb9..c5a63a8 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaHeaderFilterStrategy.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaHeaderFilterStrategy.java
@@ -29,7 +29,7 @@ public class KafkaHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
         getInFilter().add("org.apache.kafka.clients.producer.RecordMetadata");
 
         // filter headers begin with "Camel" or "org.apache.camel"
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
-        setInFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
+        setInFilterPattern(CAMEL_FILTER_PATTERN);
     }
 }
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
index a22ad63..4c7f89c 100644
--- 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
@@ -26,7 +26,7 @@ public class MailHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
     
     protected void initialize() {
         // filter headers begin with "Camel" or "org.apache.camel"
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
     }
 
 }
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
index eadaccc..a9b6931 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
@@ -48,7 +48,7 @@ public class NettyHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
 
         // filter headers begin with "Camel" or "org.apache.camel"
         // must ignore case for Http based transports
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
-        setInFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
+        setInFilterPattern(CAMEL_FILTER_PATTERN);
     }
 }
diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
index 26ac67c..2900f0d 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
@@ -50,6 +50,6 @@ public class PlatformHttpHeaderFilterStrategy extends DefaultHeaderFilterStrateg
 
         // filter headers begin with "Camel" or "org.apache.camel"
         // must ignore case for Http based transports
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
     }
 }
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkHeaderFilterStrategy.java
b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkHeaderFilterStrategy.java
index cf174aa..6f5191d 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkHeaderFilterStrategy.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkHeaderFilterStrategy.java
@@ -50,7 +50,7 @@ public class SparkHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
 
         // filter headers begin with "Camel" or "org.apache.camel"
         // must ignore case for Http based transports
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
 
         // filter out splat as its an internal header
         getOutFilter().add(SparkConstants.SPLAT);
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java
index 88656aa..a7e4af9 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java
@@ -44,6 +44,6 @@ public class UndertowHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
         
         // filter headers begin with "Camel" or "org.apache.camel"
         // must ignore case for Http based transports
-        setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+        setOutFilterPattern(CAMEL_FILTER_PATTERN);
     }
 }
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 7f4ea2d..8ae01e8 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
@@ -39,6 +39,11 @@ import org.apache.camel.spi.HeaderFilterStrategy;
  */
 public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
 
+    /**
+     * A filter pattern that only accepts keys starting with <tt>Camel</tt> or
<tt>org.apache.camel.</tt>
+     */
+    public static final Pattern CAMEL_FILTER_PATTERN = Pattern.compile("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+
     private Set<String> inFilter;
     private Pattern inFilterPattern;
 
@@ -113,6 +118,18 @@ 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.
+     *
+     * @param pattern regular expression filter pattern
+     */
+    public void setOutFilterPattern(Pattern pattern) {
+        outFilterPattern = pattern;
+    }
+
+    /**
      * Gets the "in" direction filter set. The "in" direction is referred to
      * copying headers from an external message to a Camel message.
      *
@@ -164,6 +181,18 @@ 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.
+     *
+     * @param pattern regular expression filter pattern
+     */
+    public void setInFilterPattern(Pattern pattern) {
+        inFilterPattern = pattern;
+    }
+
+    /**
      * Gets the isLowercase property which is a boolean to determine
      * whether header names should be converted to lower case before
      * checking it with the filter Set. It does not affect filtering using


Mime
View raw message