You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/03 14:55:37 UTC

[camel] 02/02: CAMEL-14220: camel-activemq - Setting brokerURL via camel-main issue

This is an automated email from the ASF dual-hosted git repository.

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

commit ffb38d351e19f3e6c81a03edbc77e5f74158a512
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 3 15:48:19 2019 +0100

    CAMEL-14220: camel-activemq - Setting brokerURL via camel-main issue
---
 .../org/apache/camel/component/jms/JmsComponent.java |  2 +-
 .../apache/camel/component/jms/JmsConfiguration.java | 20 +++++++++++++++++---
 .../component/jms/JmsEndpointConfigurationTest.java  |  6 ++++--
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
index 495c122..1adf458 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
@@ -1231,7 +1231,7 @@ public class JmsComponent extends HeaderFilterStrategyComponent {
     @Override
     protected void doStart() throws Exception {
         // only attempt to set connection factory if there is no transaction manager
-        if (configuration.getConnectionFactory() == null && configuration.getTransactionManager() == null && isAllowAutoWiredConnectionFactory()) {
+        if (configuration.getConnectionFactory() == null && configuration.getOrCreateTransactionManager() == null && isAllowAutoWiredConnectionFactory()) {
             Set<ConnectionFactory> beans = getCamelContext().getRegistry().findByType(ConnectionFactory.class);
             if (beans.size() == 1) {
                 ConnectionFactory cf = beans.iterator().next();
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
index fd18e47..e28b2a3 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
@@ -678,7 +678,7 @@ public class JmsConfiguration implements Cloneable {
             return jmsOperations;
         }
 
-        ConnectionFactory factory = getTemplateConnectionFactory();
+        ConnectionFactory factory = getOrCreateTemplateConnectionFactory();
         JmsTemplate template = new CamelJmsTemplate(this, factory);
 
         template.setPubSubDomain(pubSubDomain);
@@ -822,6 +822,10 @@ public class JmsConfiguration implements Cloneable {
     }
 
     public ConnectionFactory getListenerConnectionFactory() {
+        return listenerConnectionFactory;
+    }
+
+    public ConnectionFactory getOrCreateListenerConnectionFactory() {
         if (listenerConnectionFactory == null) {
             listenerConnectionFactory = createListenerConnectionFactory();
         }
@@ -836,6 +840,10 @@ public class JmsConfiguration implements Cloneable {
     }
 
     public ConnectionFactory getTemplateConnectionFactory() {
+        return templateConnectionFactory;
+    }
+
+    public ConnectionFactory getOrCreateTemplateConnectionFactory() {
         if (templateConnectionFactory == null) {
             templateConnectionFactory = createTemplateConnectionFactory();
         }
@@ -1095,6 +1103,10 @@ public class JmsConfiguration implements Cloneable {
     }
 
     public PlatformTransactionManager getTransactionManager() {
+        return transactionManager;
+    }
+
+    public PlatformTransactionManager getOrCreateTransactionManager() {
         if (transactionManager == null && isTransacted() && isLazyCreateTransactionManager()) {
             transactionManager = createTransactionManager();
         }
@@ -1471,7 +1483,9 @@ public class JmsConfiguration implements Cloneable {
 
     protected void configureMessageListenerContainer(AbstractMessageListenerContainer container,
                                                      JmsEndpoint endpoint) throws Exception {
-        container.setConnectionFactory(getListenerConnectionFactory());
+        container.setConnectionFactory(getOrCreateListenerConnectionFactory());
+        container.setConnectionFactory(getOrCreateListenerConnectionFactory());
+        container.setConnectionFactory(getOrCreateListenerConnectionFactory());
         if (endpoint instanceof DestinationEndpoint) {
             container.setDestinationResolver(createDestinationResolver((DestinationEndpoint) endpoint));
         } else if (destinationResolver != null) {
@@ -1580,7 +1594,7 @@ public class JmsConfiguration implements Cloneable {
         if (taskExecutor != null) {
             container.setTaskExecutor(taskExecutor);
         }
-        PlatformTransactionManager tm = getTransactionManager();
+        PlatformTransactionManager tm = getOrCreateTransactionManager();
         if (tm != null) {
             container.setTransactionManager(tm);
         } else if (transactionManager == null && transacted && !lazyCreateTransactionManager) {
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
index 7a49e7f..fc3c707 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
@@ -326,7 +326,8 @@ public class JmsEndpointConfigurationTest extends CamelTestSupport {
         assertEquals(1, endpoint.getIdleConsumerLimit());
         assertNull(endpoint.getJmsMessageType());
         assertNull(endpoint.getJmsOperations());
-        assertNotNull(endpoint.getListenerConnectionFactory());
+        assertNull(endpoint.getListenerConnectionFactory());
+        assertNotNull(endpoint.getConfiguration().getOrCreateListenerConnectionFactory());
         assertEquals(0, endpoint.getMaxConcurrentConsumers());
         assertEquals(-1, endpoint.getMaxMessagesPerTask());
         assertNull(endpoint.getMessageConverter());
@@ -346,7 +347,8 @@ public class JmsEndpointConfigurationTest extends CamelTestSupport {
         assertNull(endpoint.getTransactionName());
         assertEquals(-1, endpoint.getTransactionTimeout());
         assertNull(endpoint.getTaskExecutor());
-        assertNotNull(endpoint.getTemplateConnectionFactory());
+        assertNull(endpoint.getTemplateConnectionFactory());
+        assertNotNull(endpoint.getConfiguration().getOrCreateTemplateConnectionFactory());
         assertNull(endpoint.getTransactionManager());
         assertEquals("Foo", endpoint.getEndpointConfiguredDestinationName());