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

jamesnetherton 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 26f7b66325d CAMEL-18233: Handle NoSuchElementException in 
CamelMicroProfilePropertiesSource loadProperties
26f7b66325d is described below

commit 26f7b66325d583a884232afd0b61e188bfb8070a
Author: James Netherton <[email protected]>
AuthorDate: Mon Jun 27 13:03:34 2022 +0100

    CAMEL-18233: Handle NoSuchElementException in 
CamelMicroProfilePropertiesSource loadProperties
---
 .../config/CamelMicroProfilePropertiesSource.java          | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-microprofile/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
 
b/components/camel-microprofile/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
index b8ff012a3fd..615d2688a9d 100644
--- 
a/components/camel-microprofile/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
+++ 
b/components/camel-microprofile/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.microprofile.config;
 
+import java.util.NoSuchElementException;
 import java.util.Properties;
 import java.util.function.Predicate;
 
@@ -23,6 +24,8 @@ import org.apache.camel.spi.LoadablePropertiesSource;
 import org.apache.camel.spi.annotations.JdkService;
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.ConfigProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The microprofile-config component is used for bridging the Eclipse 
MicroProfile Config with Camels properties
@@ -31,6 +34,8 @@ import org.eclipse.microprofile.config.ConfigProvider;
 @JdkService("properties-source-factory")
 public class CamelMicroProfilePropertiesSource implements 
LoadablePropertiesSource {
 
+    private static final Logger LOG = 
LoggerFactory.getLogger(CamelMicroProfilePropertiesSource.class);
+
     @Override
     public String getName() {
         return "CamelMicroProfilePropertiesSource";
@@ -45,9 +50,14 @@ public class CamelMicroProfilePropertiesSource implements 
LoadablePropertiesSour
     public Properties loadProperties() {
         final Properties answer = new Properties();
         final Config config = ConfigProvider.getConfig();
-
         for (String name : config.getPropertyNames()) {
-            config.getOptionalValue(name, String.class).ifPresent(value -> 
answer.put(name, value));
+            try {
+                answer.put(name, config.getValue(name, String.class));
+            } catch (NoSuchElementException e) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Failed to resolve property {} due to {}", name, 
e.getMessage());
+                }
+            }
         }
 
         return answer;

Reply via email to