From 8e2fec20605e62c51118914a06a5fe02897a8d5d Mon Sep 17 00:00:00 2001 From: Andrea Cosentino Date: Mon, 18 May 2026 10:37:39 +0200 Subject: [PATCH] CAMEL-23516: camel-xmpp - Use dedicated HeaderFilterStrategy aligned with sibling components Introduce XmppHeaderFilterStrategy following the KafkaHeaderFilterStrategy / MailHeaderFilterStrategy shape (lowerCase=true, filter headers starting with Camel/camel/org.apache.camel. in both directions), and switch the defaults in XmppEndpoint and the XmppBinding no-arg constructor to use it. Signed-off-by: Andrea Cosentino --- .../camel/component/xmpp/XmppBinding.java | 3 +- .../camel/component/xmpp/XmppEndpoint.java | 3 +- .../xmpp/XmppHeaderFilterStrategy.java | 34 ++++++++++++ .../xmpp/XmppHeaderFilterStrategyTest.java | 53 +++++++++++++++++++ .../pages/camel-4x-upgrade-guide-4_21.adoc | 9 ++++ 5 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategy.java create mode 100644 components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategyTest.java diff --git a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java index b4862547c03f3..bf954eed19acb 100644 --- a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java +++ b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java @@ -22,7 +22,6 @@ import org.apache.camel.Exchange; import org.apache.camel.spi.HeaderFilterStrategy; -import org.apache.camel.support.DefaultHeaderFilterStrategy; import org.apache.camel.util.ObjectHelper; import org.jivesoftware.smack.packet.DefaultExtensionElement; import org.jivesoftware.smack.packet.ExtensionElement; @@ -44,7 +43,7 @@ public class XmppBinding { private HeaderFilterStrategy headerFilterStrategy; public XmppBinding() { - this.headerFilterStrategy = new DefaultHeaderFilterStrategy(); + this.headerFilterStrategy = new XmppHeaderFilterStrategy(); } public XmppBinding(HeaderFilterStrategy headerFilterStrategy) { diff --git a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java index ccd0d62ee9ac1..41e635418a6b8 100644 --- a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java +++ b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java @@ -34,7 +34,6 @@ import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriPath; import org.apache.camel.support.DefaultEndpoint; -import org.apache.camel.support.DefaultHeaderFilterStrategy; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; import org.jivesoftware.smack.ConnectionConfiguration; @@ -103,7 +102,7 @@ public class XmppEndpoint extends DefaultEndpoint implements HeaderFilterStrateg @UriParam(label = "consumer", defaultValue = "10") private int connectionPollDelay = 10; @UriParam(label = "filter") - private HeaderFilterStrategy headerFilterStrategy = new DefaultHeaderFilterStrategy(); + private HeaderFilterStrategy headerFilterStrategy = new XmppHeaderFilterStrategy(); @UriParam(label = "advanced") private ConnectionConfiguration connectionConfig; diff --git a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategy.java b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategy.java new file mode 100644 index 0000000000000..cd2b78b25c42a --- /dev/null +++ b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategy.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.xmpp; + +import org.apache.camel.support.DefaultHeaderFilterStrategy; + +public class XmppHeaderFilterStrategy extends DefaultHeaderFilterStrategy { + + public XmppHeaderFilterStrategy() { + 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-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategyTest.java b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategyTest.java new file mode 100644 index 0000000000000..64718e909210c --- /dev/null +++ b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppHeaderFilterStrategyTest.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.xmpp; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class XmppHeaderFilterStrategyTest { + + private final XmppHeaderFilterStrategy strategy = new XmppHeaderFilterStrategy(); + + @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 46a19e9348fb0..8aa1ff50dd49a 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 @@ -380,6 +380,15 @@ aligning the component with the rest of the Camel component catalog (`camel-kafk names from NATS messages can supply a custom `headerFilterStrategy` to restore the previous behaviour. +=== camel-xmpp + +The default `headerFilterStrategy` is now a new `XmppHeaderFilterStrategy` 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 XMPP 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