This is an automated email from the ASF dual-hosted git repository.
oscerd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new be8aad96fa04 CAMEL-23515: camel-nats - Use dedicated
HeaderFilterStrategy aligned with sibling components (#23233)
be8aad96fa04 is described below
commit be8aad96fa04f81d2b58884e27ba6755c9ad2718
Author: Andrea Cosentino <[email protected]>
AuthorDate: Fri May 15 12:16:58 2026 +0200
CAMEL-23515: camel-nats - Use dedicated HeaderFilterStrategy aligned with
sibling components (#23233)
Introduce NatsHeaderFilterStrategy following the KafkaHeaderFilterStrategy /
MailHeaderFilterStrategy shape (lowerCase=true, filter headers starting with
Camel/camel/org.apache.camel. in both directions), and switch the default
in NatsConfiguration to use it.
Signed-off-by: Andrea Cosentino <[email protected]>
---
.../camel/component/nats/NatsConfiguration.java | 3 +-
.../component/nats/NatsHeaderFilterStrategy.java | 34 ++++++++++++++
.../nats/NatsHeaderFilterStrategyTest.java | 53 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_21.adoc | 7 +++
4 files changed, 95 insertions(+), 2 deletions(-)
diff --git
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
index 00b489098c7b..4db1cdef3ba3 100644
---
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
+++
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
@@ -29,7 +29,6 @@ import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;
-import org.apache.camel.support.DefaultHeaderFilterStrategy;
import org.apache.camel.support.jsse.SSLContextParameters;
import org.apache.camel.util.ObjectHelper;
@@ -116,7 +115,7 @@ public class NatsConfiguration implements Cloneable {
@UriParam(label = "advanced")
private boolean traceConnection;
@UriParam(label = "advanced")
- private HeaderFilterStrategy headerFilterStrategy = new
DefaultHeaderFilterStrategy();
+ private HeaderFilterStrategy headerFilterStrategy = new
NatsHeaderFilterStrategy();
public NatsConfiguration copy() {
try {
diff --git
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsHeaderFilterStrategy.java
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsHeaderFilterStrategy.java
new file mode 100644
index 000000000000..9997b3a66623
--- /dev/null
+++
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsHeaderFilterStrategy.java
@@ -0,0 +1,34 @@
+/*
+ * 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.nats;
+
+import org.apache.camel.support.DefaultHeaderFilterStrategy;
+
+public class NatsHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
+
+ public NatsHeaderFilterStrategy() {
+ initialize();
+ }
+
+ protected void initialize() {
+ setLowerCase(true);
+ // filter headers begin with "Camel" or "org.apache.camel"
+ setOutFilterStartsWith(CAMEL_FILTER_STARTS_WITH);
+ setInFilterStartsWith(CAMEL_FILTER_STARTS_WITH);
+ }
+
+}
diff --git
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsHeaderFilterStrategyTest.java
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsHeaderFilterStrategyTest.java
new file mode 100644
index 000000000000..96083045a0db
--- /dev/null
+++
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsHeaderFilterStrategyTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.nats;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class NatsHeaderFilterStrategyTest {
+
+ private final NatsHeaderFilterStrategy strategy = new
NatsHeaderFilterStrategy();
+
+ @Test
+ void inboundCamelHeadersAreFiltered() {
+ assertTrue(strategy.applyFilterToExternalHeaders("CamelHttpUri",
"http://evil.example", null));
+ assertTrue(strategy.applyFilterToExternalHeaders("CamelFileName",
"../../etc/passwd", null));
+
assertTrue(strategy.applyFilterToExternalHeaders("CamelBeanMethodName",
"evilMethod", null));
+ }
+
+ @Test
+ void inboundLowercaseCamelHeadersAreFiltered() {
+ assertTrue(strategy.applyFilterToExternalHeaders("camelHttpUri",
"http://evil.example", null));
+ assertTrue(strategy.applyFilterToExternalHeaders("camelfilename",
"../../etc/passwd", null));
+ }
+
+ @Test
+ void outboundCamelHeadersAreFiltered() {
+ assertTrue(strategy.applyFilterToCamelHeaders("CamelHttpUri", "value",
null));
+ assertTrue(strategy.applyFilterToCamelHeaders("camelHttpUri", "value",
null));
+ }
+
+ @Test
+ void nonCamelHeadersPassThrough() {
+ assertFalse(strategy.applyFilterToExternalHeaders("Content-Type",
"application/json", null));
+ assertFalse(strategy.applyFilterToExternalHeaders("X-Request-Id",
"abc-123", null));
+ assertFalse(strategy.applyFilterToCamelHeaders("Content-Type",
"application/json", null));
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
index c49f1b970368..28cfa8a627df 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
@@ -373,6 +373,13 @@ Two new endpoint options have been added to control the
pull fetch loop:
* `pullBatchSize` (default `10`) — maximum number of messages to fetch per
pull request.
* `pullFetchTimeout` (default `1000` ms) — maximum time to wait for a batch on
each fetch.
+The default `headerFilterStrategy` is now a new `NatsHeaderFilterStrategy`
that filters headers
+starting with `Camel` / `camel` (case-insensitive) in both the inbound and
outbound directions,
+aligning the component with the rest of the Camel component catalog
(`camel-kafka`, `camel-mail`,
+`camel-coap`, `camel-google-pubsub`, ...). Routes that relied on passing
through these header
+names from NATS messages can supply a custom `headerFilterStrategy` to restore
the previous
+behaviour.
+
=== camel-lucene
The Exchange header values exposed by `LuceneConstants` have been renamed to
follow the standard