This is an automated email from the ASF dual-hosted git repository.
gnodet 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 47bc70908187 CAMEL-27897: camel-activemq6: an endpoint
connectionFactory gets the broker URL of the component connectionFactory
(#31164)
47bc70908187 is described below
commit 47bc70908187cf3442acf05c7d9ddc03a81c1bd7
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Dec 1 11:18:41 2026 +0100
CAMEL-27897: camel-activemq6: an endpoint connectionFactory gets the broker
URL of the component connectionFactory (#31164)
CAMEL-27897: camel-activemq6/activemq: endpoint CF must not inherit
component broker URL
When setConnectionFactory() is called with an ActiveMQConnectionFactory and
no
custom broker URL has been set (customBrokerURL=false), the else branch
previously
called setBrokerURL(), which set customBrokerURL=true as a side effect.
A cloned endpoint configuration inheriting that flag would then enter the
if(customBrokerURL) branch on its own setConnectionFactory() call,
overwriting
the endpoint's own ConnectionFactory broker URL with the component's URL.
Fix: use direct field assignment (this.brokerURL = acf.getBrokerURL()) in
the
else branch to sync the broker URL without touching the customBrokerURL
flag.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../component/activemq/ActiveMQConfiguration.java | 6 +-
...ActiveMQConfigurationConnectionFactoryTest.java | 93 ++++++++++++++++++++++
.../component/activemq6/ActiveMQConfiguration.java | 6 +-
...ActiveMQConfigurationConnectionFactoryTest.java | 93 ++++++++++++++++++++++
4 files changed, 194 insertions(+), 4 deletions(-)
diff --git
a/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java
b/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java
index 77a4677e0241..d9ddebc1f774 100644
---
a/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java
+++
b/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQConfiguration.java
@@ -144,8 +144,10 @@ public class ActiveMQConfiguration extends
JmsConfiguration {
// the real target connection factory knows about
acf.setBrokerURL(brokerURL);
} else {
- // it's the opposite the target has the brokerURL which we
want to set on this
- setBrokerURL(acf.getBrokerURL());
+ // it's the opposite: the target has the brokerURL which we
want to set on this
+ // assign directly to avoid setting customBrokerURL=true
(which would cause the
+ // component's URL to overwrite an endpoint's own connection
factory URL)
+ this.brokerURL = acf.getBrokerURL();
}
}
diff --git
a/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQConfigurationConnectionFactoryTest.java
b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQConfigurationConnectionFactoryTest.java
new file mode 100644
index 000000000000..2ddbf6ea7b63
--- /dev/null
+++
b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQConfigurationConnectionFactoryTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.activemq;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Verifies correct broker URL handling in {@link
ActiveMQConfiguration#setConnectionFactory}.
+ * <p>
+ * Regression test for CAMEL-27897: when the component configuration has its
ConnectionFactory set via
+ * {@link ActiveMQConfiguration#setConnectionFactory}, the internal call to
{@link ActiveMQConfiguration#setBrokerURL}
+ * in the else branch was marking customBrokerURL=true. A cloned endpoint
configuration inheriting that flag would then
+ * have the component's broker URL overwritten into the endpoint's own
ConnectionFactory.
+ */
+class ActiveMQConfigurationConnectionFactoryTest {
+
+ private static final String COMPONENT_BROKER_URL =
"tcp://component-broker:61616";
+ private static final String ENDPOINT_BROKER_URL =
"tcp://endpoint-broker:61617";
+
+ /**
+ * CAMEL-27897: setting a CF on a configuration must not mark
customBrokerURL=true.
+ * <p>
+ * When customBrokerURL is not set, an endpoint's cloned config must be
able to accept its own CF without having the
+ * component's URL pushed into it.
+ */
+ @Test
+ void settingConnectionFactoryAloneDoesNotCorruptEndpointCF() {
+ // Simulate component config: CF set, no explicit setBrokerURL call
+ ActiveMQConfiguration config = new ActiveMQConfiguration();
+ config.setConnectionFactory(new
ActiveMQConnectionFactory(COMPONENT_BROKER_URL));
+ assertEquals(COMPONENT_BROKER_URL, config.getBrokerURL()); //
precondition: config absorbed the component CF's URL
+
+ // Simulate endpoint config (cloned from component): set a different
CF.
+ // Before the fix: setConnectionFactory in the else branch called
setBrokerURL(), which set
+ // customBrokerURL=true. On the next setConnectionFactory call, the
if(customBrokerURL) branch fired
+ // and overwrote the endpoint CF's URL with the component's URL.
+ // After the fix: direct field assignment keeps customBrokerURL=false
throughout.
+ ActiveMQConnectionFactory endpointCF = new
ActiveMQConnectionFactory(ENDPOINT_BROKER_URL);
+ config.setConnectionFactory(endpointCF);
+
+ assertEquals(ENDPOINT_BROKER_URL, endpointCF.getBrokerURL(),
+ "Endpoint CF must not have the component's broker URL applied
to it");
+ assertEquals(ENDPOINT_BROKER_URL, config.getBrokerURL(),
+ "Config brokerURL must reflect the endpoint CF's URL");
+ }
+
+ /**
+ * When a custom broker URL is set explicitly (via setBrokerURL), it must
be pushed into the CF's internal URL.
+ */
+ @Test
+ void customBrokerURLIsAppliedToConnectionFactory() {
+ ActiveMQConfiguration config = new ActiveMQConfiguration();
+ config.setBrokerURL("tcp://custom:61616");
+
+ ActiveMQConnectionFactory cf = new
ActiveMQConnectionFactory("tcp://original:61616");
+ config.setConnectionFactory(cf);
+
+ assertEquals("tcp://custom:61616", cf.getBrokerURL(),
+ "Custom broker URL must be pushed into the
ActiveMQConnectionFactory");
+ }
+
+ /**
+ * Without an explicit broker URL, repeated setConnectionFactory calls
must keep reflecting the latest CF's URL.
+ */
+ @Test
+ void noBrokerURLOverrideLetsCFUrlWin() {
+ ActiveMQConfiguration config = new ActiveMQConfiguration();
+
+ config.setConnectionFactory(new
ActiveMQConnectionFactory("tcp://first:61616"));
+ assertEquals("tcp://first:61616", config.getBrokerURL());
+
+ config.setConnectionFactory(new
ActiveMQConnectionFactory("tcp://second:61617"));
+ assertEquals("tcp://second:61617", config.getBrokerURL(),
+ "Without a custom broker URL, the latest CF's own URL must
win");
+ }
+}
diff --git
a/components/camel-activemq6/src/main/java/org/apache/camel/component/activemq6/ActiveMQConfiguration.java
b/components/camel-activemq6/src/main/java/org/apache/camel/component/activemq6/ActiveMQConfiguration.java
index f683719c3dbc..2bfda406343e 100644
---
a/components/camel-activemq6/src/main/java/org/apache/camel/component/activemq6/ActiveMQConfiguration.java
+++
b/components/camel-activemq6/src/main/java/org/apache/camel/component/activemq6/ActiveMQConfiguration.java
@@ -158,8 +158,10 @@ public class ActiveMQConfiguration extends
JmsConfiguration {
// the real target connection factory knows about
acf.setBrokerURL(brokerURL);
} else {
- // it's the opposite the target has the brokerURL which we
want to set on this
- setBrokerURL(acf.getBrokerURL());
+ // it's the opposite: the target has the brokerURL which we
want to set on this
+ // assign directly to avoid setting customBrokerURL=true
(which would cause the
+ // component's URL to overwrite an endpoint's own connection
factory URL)
+ this.brokerURL = acf.getBrokerURL();
}
}
diff --git
a/components/camel-activemq6/src/test/java/org/apache/camel/component/activemq6/ActiveMQConfigurationConnectionFactoryTest.java
b/components/camel-activemq6/src/test/java/org/apache/camel/component/activemq6/ActiveMQConfigurationConnectionFactoryTest.java
new file mode 100644
index 000000000000..94719e8810f5
--- /dev/null
+++
b/components/camel-activemq6/src/test/java/org/apache/camel/component/activemq6/ActiveMQConfigurationConnectionFactoryTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.activemq6;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Verifies correct broker URL handling in {@link
ActiveMQConfiguration#setConnectionFactory}.
+ * <p>
+ * Regression test for CAMEL-27897: when the component configuration has its
ConnectionFactory set via
+ * {@link ActiveMQConfiguration#setConnectionFactory}, the internal call to
{@link ActiveMQConfiguration#setBrokerURL}
+ * in the else branch was marking customBrokerURL=true. A cloned endpoint
configuration inheriting that flag would then
+ * have the component's broker URL overwritten into the endpoint's own
ConnectionFactory.
+ */
+class ActiveMQConfigurationConnectionFactoryTest {
+
+ private static final String COMPONENT_BROKER_URL =
"tcp://component-broker:61616";
+ private static final String ENDPOINT_BROKER_URL =
"tcp://endpoint-broker:61617";
+
+ /**
+ * CAMEL-27897: setting a CF on a configuration must not mark
customBrokerURL=true.
+ * <p>
+ * When customBrokerURL is not set, an endpoint's cloned config must be
able to accept its own CF without having the
+ * component's URL pushed into it.
+ */
+ @Test
+ void settingConnectionFactoryAloneDoesNotCorruptEndpointCF() {
+ // Simulate component config: CF set, no explicit setBrokerURL call
+ ActiveMQConfiguration config = new ActiveMQConfiguration();
+ config.setConnectionFactory(new
ActiveMQConnectionFactory(COMPONENT_BROKER_URL));
+ assertEquals(COMPONENT_BROKER_URL, config.getBrokerURL()); //
precondition: config absorbed the component CF's URL
+
+ // Simulate endpoint config (cloned from component): set a different
CF.
+ // Before the fix: setConnectionFactory in the else branch called
setBrokerURL(), which set
+ // customBrokerURL=true. On the next setConnectionFactory call, the
if(customBrokerURL) branch fired
+ // and overwrote the endpoint CF's URL with the component's URL.
+ // After the fix: direct field assignment keeps customBrokerURL=false
throughout.
+ ActiveMQConnectionFactory endpointCF = new
ActiveMQConnectionFactory(ENDPOINT_BROKER_URL);
+ config.setConnectionFactory(endpointCF);
+
+ assertEquals(ENDPOINT_BROKER_URL, endpointCF.getBrokerURL(),
+ "Endpoint CF must not have the component's broker URL applied
to it");
+ assertEquals(ENDPOINT_BROKER_URL, config.getBrokerURL(),
+ "Config brokerURL must reflect the endpoint CF's URL");
+ }
+
+ /**
+ * When a custom broker URL is set explicitly (via setBrokerURL), it must
be pushed into the CF's internal URL.
+ */
+ @Test
+ void customBrokerURLIsAppliedToConnectionFactory() {
+ ActiveMQConfiguration config = new ActiveMQConfiguration();
+ config.setBrokerURL("tcp://custom:61616");
+
+ ActiveMQConnectionFactory cf = new
ActiveMQConnectionFactory("tcp://original:61616");
+ config.setConnectionFactory(cf);
+
+ assertEquals("tcp://custom:61616", cf.getBrokerURL(),
+ "Custom broker URL must be pushed into the
ActiveMQConnectionFactory");
+ }
+
+ /**
+ * Without an explicit broker URL, repeated setConnectionFactory calls
must keep reflecting the latest CF's URL.
+ */
+ @Test
+ void noBrokerURLOverrideLetsCFUrlWin() {
+ ActiveMQConfiguration config = new ActiveMQConfiguration();
+
+ config.setConnectionFactory(new
ActiveMQConnectionFactory("tcp://first:61616"));
+ assertEquals("tcp://first:61616", config.getBrokerURL());
+
+ config.setConnectionFactory(new
ActiveMQConnectionFactory("tcp://second:61617"));
+ assertEquals("tcp://second:61617", config.getBrokerURL(),
+ "Without a custom broker URL, the latest CF's own URL must
win");
+ }
+}