gnodet opened a new pull request, #31164:
URL: https://github.com/apache/camel/pull/31164

   ## Summary
   
   Fix incorrect broker URL inheritance in `camel-activemq6` and 
`camel-activemq` when an endpoint overrides the component's `ConnectionFactory`.
   
   ## Root Cause
   
   `ActiveMQConfiguration.setConnectionFactory()` contains two branches:
   - If `customBrokerURL=true`: push the configuration's broker URL into the 
`ActiveMQConnectionFactory`
   - Else: read the broker URL from the `ActiveMQConnectionFactory` back into 
the configuration
   
   The bug is in the `else` branch: it called 
`setBrokerURL(acf.getBrokerURL())` to sync the URL, but `setBrokerURL()` has 
the side effect of setting `customBrokerURL = true`. From that point on, any 
subsequent `setConnectionFactory()` call on the same (or a cloned) 
configuration object would enter the `if (customBrokerURL)` branch and 
overwrite the new CF's broker URL with the first CF's URL.
   
   This surfaced when:
   1. The component sets its own `ConnectionFactory` → `customBrokerURL` 
becomes `true`
   2. The endpoint configuration (cloned from the component) sets its own 
`ConnectionFactory`
   3. Because `customBrokerURL=true` was inherited, the component's URL gets 
pushed into the endpoint's CF — overriding whatever URL the endpoint's own 
factory had
   
   ## Fix
   
   In the `else` branch of `setConnectionFactory()`, assign `this.brokerURL` 
directly instead of calling `setBrokerURL()`. This syncs the field without 
touching `customBrokerURL`, preserving correct behavior for subsequent calls.
   
   The fix is applied identically to both `camel-activemq` and 
`camel-activemq6` which share the same implementation.
   
   ## Tests
   
   Three unit tests added to `ActiveMQConfigurationConnectionFactoryTest` in 
both modules:
   
   1. **`settingConnectionFactoryAloneDoesNotCorruptEndpointCF`** — the 
regression test for CAMEL-27897: simulates a component CF being set, then an 
endpoint CF being set on the same configuration object. Verifies the endpoint 
CF's URL is not overwritten with the component's URL. This test is RED on the 
unfixed code and GREEN after the fix.
   
   2. **`customBrokerURLIsAppliedToConnectionFactory`** — verifies the `if 
(customBrokerURL)` path still works correctly: an explicit `setBrokerURL()` 
call must still propagate into the CF.
   
   3. **`noBrokerURLOverrideLetsCFUrlWin`** — verifies that without a custom 
broker URL, the latest CF's URL always wins on successive calls.
   
   ---
   
   Fixes CAMEL-27897
   
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to