[ 
https://issues.apache.org/jira/browse/CAMEL-12197?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16341005#comment-16341005
 ] 

ASF GitHub Bot commented on CAMEL-12197:
----------------------------------------

lburgazzoli closed pull request #2194: CAMEL-12197: Automatic discovery of 
LogListener and UuidGenerator
URL: https://github.com/apache/camel/pull/2194
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
 
b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index 3284c4b1e66..71386aee4d6 100644
--- 
a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ 
b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -96,6 +96,7 @@
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.LogListener;
 import org.apache.camel.spi.ManagementNamingStrategy;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.MessageHistoryFactory;
@@ -375,6 +376,23 @@ public void afterPropertiesSet() throws Exception {
             LOG.info("Using RouteController: " + routeController);
             getContext().setRouteController(routeController);
         }
+        // UuidGenerator
+        UuidGenerator uuidGenerator = getBeanForType(UuidGenerator.class);
+        if (uuidGenerator != null) {
+            LOG.info("Using custom UuidGenerator: {}", uuidGenerator);
+            getContext().setUuidGenerator(uuidGenerator);
+        }
+        // LogListener
+        Map<String, LogListener> logListeners = 
getContext().getRegistry().findByTypeWithName(LogListener.class);
+        if (logListeners != null && !logListeners.isEmpty()) {
+            for (Map.Entry<String, LogListener> entry : 
logListeners.entrySet()) {
+                LogListener logListener = entry.getValue();
+                if (!getContext().getLogListeners().contains(logListener)) {
+                    LOG.info("Using custom LogListener with id: {} and 
implementation: {}", entry.getKey(), logListener);
+                    getContext().addLogListener(logListener);
+                }
+            }
+        }
 
         // set the default thread pool profile if defined
         initThreadPoolProfiles(getContext());
diff --git 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index badc9d699f7..4757ab47590 100644
--- 
a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ 
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -47,6 +47,7 @@
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.LogListener;
 import org.apache.camel.spi.ManagementNamingStrategy;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.ReloadStrategy;
@@ -57,6 +58,7 @@
 import org.apache.camel.spi.StreamCachingStrategy;
 import org.apache.camel.spi.ThreadPoolProfile;
 import org.apache.camel.spi.UnitOfWorkFactory;
+import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spring.CamelBeanPostProcessor;
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.camel.spring.spi.XmlCamelContextConfigurer;
@@ -510,6 +512,23 @@ static void afterPropertiesSet(ApplicationContext 
applicationContext, CamelConte
             LOG.info("Using RouteController: " + routeController);
             camelContext.setRouteController(routeController);
         }
+        // UuidGenerator
+        UuidGenerator uuidGenerator = getSingleBeanOfType(applicationContext, 
UuidGenerator.class);
+        if (uuidGenerator != null) {
+            LOG.info("Using custom UuidGenerator: {}", uuidGenerator);
+            camelContext.setUuidGenerator(uuidGenerator);
+        }
+        // LogListener
+        Map<String, LogListener> logListeners = 
applicationContext.getBeansOfType(LogListener.class);
+        if (logListeners != null && !logListeners.isEmpty()) {
+            for (Map.Entry<String, LogListener> entry : 
logListeners.entrySet()) {
+                LogListener logListener = entry.getValue();
+                if (!camelContext.getLogListeners().contains(logListener)) {
+                    LOG.info("Using custom LogListener with id: {} and 
implementation: {}", entry.getKey(), logListener);
+                    camelContext.addLogListener(logListener);
+                }
+            }
+        }
 
         // set the default thread pool profile if defined
         initThreadPoolProfiles(applicationContext, camelContext);
diff --git 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/LogListenerDiscoveryTest.java
 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/LogListenerDiscoveryTest.java
new file mode 100644
index 00000000000..a4bfc6fafb2
--- /dev/null
+++ 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/LogListenerDiscoveryTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.spring.boot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.LogListener;
+import org.apache.camel.util.CamelLogger;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.stereotype.Component;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+    classes = {
+        CamelAutoConfiguration.class,
+        LogListenerDiscoveryTest.MyLogListener.class
+    }
+)
+public class LogListenerDiscoveryTest {
+    @Autowired
+    private CamelContext camelContext;
+    @Autowired
+    private MyLogListener logListener;
+
+    @Test
+    public void testUuidDiscovery() {
+        assertThat(camelContext.getLogListeners()).contains(logListener);
+    }
+
+    @Component
+    public static class MyLogListener implements LogListener {
+        @Override
+        public String onLog(Exchange exchange, CamelLogger logger, String s) {
+            return null;
+        }
+    }
+}
\ No newline at end of file
diff --git 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/UuidGeneratorDiscoveryTest.java
 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/UuidGeneratorDiscoveryTest.java
new file mode 100644
index 00000000000..867e6a5784a
--- /dev/null
+++ 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/UuidGeneratorDiscoveryTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.spring.boot;
+
+import java.util.UUID;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.UuidGenerator;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.stereotype.Component;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+    classes = {
+        CamelAutoConfiguration.class,
+        UuidGeneratorDiscoveryTest.MyUuidGenerator.class
+    }
+)
+public class UuidGeneratorDiscoveryTest {
+    @Autowired
+    private CamelContext camelContext;
+
+    @Test
+    public void testUuidDiscovery() {
+        
assertThat(camelContext.getUuidGenerator()).isInstanceOf(MyUuidGenerator.class);
+    }
+
+    @Component
+    public static class MyUuidGenerator implements UuidGenerator {
+        @Override
+        public String generateUuid() {
+            return UUID.randomUUID().toString();
+        }
+    }
+}
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Automatic discovery of LogListener and UuidGenerator
> ----------------------------------------------------
>
>                 Key: CAMEL-12197
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12197
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core-xml, camel-spring-boot
>            Reporter: Luca Burgazzoli
>            Assignee: Luca Burgazzoli
>            Priority: Minor
>             Fix For: 2.21.0
>
>
> It would be nice if  beans of type LogListener or UuidGenerator are 
> automatically discovered from the registry
> Impacts:
> - AbstractCamelContextFactoryBean
> - CamelAutoConfiguration



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to