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/11/21 09:08:08 UTC

[camel] branch master updated (8245282 -> bfe8df0)

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

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 8245282  Introduce TransformerFactoryConfigurationStrategy to be able to configure a TransformerFactory per XsltEndpoint (#3353)
     new 2aac4d7  CAMEL-14190: JMSComponent tries to use applicationContext before it is initialised. Change this kind of logic to be more Camel like.
     new bfe8df0  Polished

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/component/jms/JmsComponent.java   | 66 +++++++++-------------
 .../java/sample/camel/SampleAmqApplication.java    |  2 -
 2 files changed, 26 insertions(+), 42 deletions(-)


[camel] 01/02: CAMEL-14190: JMSComponent tries to use applicationContext before it is initialised. Change this kind of logic to be more Camel like.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2aac4d79e42a7d45736473a1480d3f505f49ed59
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Nov 21 09:53:22 2019 +0100

    CAMEL-14190: JMSComponent tries to use applicationContext before it is initialised. Change this kind of logic to be more Camel like.
---
 .../apache/camel/component/jms/JmsComponent.java   | 66 +++++++++-------------
 1 file changed, 26 insertions(+), 40 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 7b04588..6b50499 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
@@ -17,8 +17,8 @@
 package org.apache.camel.component.jms;
 
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ExecutorService;
-
 import javax.jms.ConnectionFactory;
 import javax.jms.ExceptionListener;
 import javax.jms.Message;
@@ -31,9 +31,6 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.HeaderFilterStrategyComponent;
 import org.apache.camel.util.ObjectHelper;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
 import org.springframework.core.task.TaskExecutor;
 import org.springframework.jms.connection.JmsTransactionManager;
 import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter;
@@ -46,15 +43,14 @@ import org.springframework.util.ErrorHandler;
 import static org.apache.camel.util.StringHelper.removeStartingCharacters;
 
 /**
- * A <a href="http://activemq.apache.org/jms.html">JMS Component</a>
+ * JMS component which uses Spring JMS.
  */
 @Component("jms")
-public class JmsComponent extends HeaderFilterStrategyComponent implements ApplicationContextAware {
+public class JmsComponent extends HeaderFilterStrategyComponent {
 
     private static final String KEY_FORMAT_STRATEGY_PARAM = "jmsKeyFormatStrategy";
 
     private ExecutorService asyncStartStopExecutorService;
-    private ApplicationContext applicationContext;
 
     @Metadata(label = "advanced", description = "To use a shared JMS configuration")
     private JmsConfiguration configuration;
@@ -65,14 +61,15 @@ public class JmsComponent extends HeaderFilterStrategyComponent implements Appli
     private MessageCreatedStrategy messageCreatedStrategy;
 
     public JmsComponent() {
+        this.configuration = createConfiguration();
     }
 
     public JmsComponent(CamelContext context) {
         super(context);
+        this.configuration = createConfiguration();
     }
 
     public JmsComponent(JmsConfiguration configuration) {
-        this();
         this.configuration = configuration;
     }
 
@@ -133,29 +130,6 @@ public class JmsComponent extends HeaderFilterStrategyComponent implements Appli
     // -------------------------------------------------------------------------
 
     public JmsConfiguration getConfiguration() {
-        if (configuration == null) {
-            configuration = createConfiguration();
-
-            // If we are being configured with spring...
-            if (applicationContext != null) {
-
-                if (isAllowAutoWiredConnectionFactory()) {
-                    Map<String, ConnectionFactory> beansOfTypeConnectionFactory = applicationContext.getBeansOfType(ConnectionFactory.class);
-                    if (!beansOfTypeConnectionFactory.isEmpty()) {
-                        ConnectionFactory cf = beansOfTypeConnectionFactory.values().iterator().next();
-                        configuration.setConnectionFactory(cf);
-                    }
-                }
-
-                if (isAllowAutoWiredDestinationResolver()) {
-                    Map<String, DestinationResolver> beansOfTypeDestinationResolver = applicationContext.getBeansOfType(DestinationResolver.class);
-                    if (!beansOfTypeDestinationResolver.isEmpty()) {
-                        DestinationResolver destinationResolver = beansOfTypeDestinationResolver.values().iterator().next();
-                        configuration.setDestinationResolver(destinationResolver);
-                    }
-                }
-            }
-        }
         return configuration;
     }
 
@@ -1055,14 +1029,6 @@ public class JmsComponent extends HeaderFilterStrategyComponent implements Appli
         getConfiguration().setAllowAdditionalHeaders(allowAdditionalHeaders);
     }
 
-    /**
-     * Sets the Spring ApplicationContext to use
-     */
-    @Override
-    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
-        this.applicationContext = applicationContext;
-    }
-
     public QueueBrowseStrategy getQueueBrowseStrategy() {
         if (queueBrowseStrategy == null) {
             queueBrowseStrategy = new DefaultQueueBrowseStrategy();
@@ -1256,8 +1222,28 @@ public class JmsComponent extends HeaderFilterStrategyComponent implements Appli
 
     @Override
     protected void doStart() throws Exception {
+        if (configuration.getConnectionFactory() == null && isAllowAutoWiredConnectionFactory()) {
+            Set<ConnectionFactory> beans = getCamelContext().getRegistry().findByType(ConnectionFactory.class);
+            if (beans.size() == 1) {
+                ConnectionFactory cf = beans.iterator().next();
+                configuration.setConnectionFactory(cf);
+            } else if (beans.size() > 1) {
+                log.debug("Cannot autowire ConnectionFactory as " + beans.size() + " instances found in registry.");
+            }
+        }
+
+        if (configuration.getDestinationResolver() == null && isAllowAutoWiredDestinationResolver()) {
+            Set<DestinationResolver> beans = getCamelContext().getRegistry().findByType(DestinationResolver.class);
+            if (beans.size() == 1) {
+                DestinationResolver destinationResolver = beans.iterator().next();
+                configuration.setDestinationResolver(destinationResolver);
+            } else if (beans.size() > 1) {
+                log.debug("Cannot autowire ConnectionFactory as " + beans.size() + " instances found in registry.");
+            }
+        }
+
         if (getHeaderFilterStrategy() == null) {
-            setHeaderFilterStrategy(new JmsHeaderFilterStrategy(getConfiguration().isIncludeAllJMSXProperties()));
+            setHeaderFilterStrategy(new JmsHeaderFilterStrategy(configuration.isIncludeAllJMSXProperties()));
         }
     }
 


[camel] 02/02: Polished

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bfe8df07436bb73447c14c0ad04ff72966335a0c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Nov 21 10:01:50 2019 +0100

    Polished
---
 .../src/main/java/sample/camel/SampleAmqApplication.java                | 2 --
 1 file changed, 2 deletions(-)

diff --git a/examples/camel-example-spring-boot-activemq/src/main/java/sample/camel/SampleAmqApplication.java b/examples/camel-example-spring-boot-activemq/src/main/java/sample/camel/SampleAmqApplication.java
index bd7b327..6890811 100644
--- a/examples/camel-example-spring-boot-activemq/src/main/java/sample/camel/SampleAmqApplication.java
+++ b/examples/camel-example-spring-boot-activemq/src/main/java/sample/camel/SampleAmqApplication.java
@@ -17,12 +17,10 @@
 package sample.camel;
 
 import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 //CHECKSTYLE:OFF
 @SpringBootApplication
-@EnableAutoConfiguration
 public class SampleAmqApplication {
 
     public static void main(String[] args) {