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

pcongiusti 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 cd6a85894d4 feat(core): scan .properties in cloud configuration
cd6a85894d4 is described below

commit cd6a85894d45cff6c4e02502ce833d8cd9fcaa53
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Thu Oct 2 17:01:10 2025 +0200

    feat(core): scan .properties in cloud configuration
    
    Enable the possibility to include a .properties file
---
 .../org/apache/camel/main/BaseMainSupport.java     | 24 ++++++++++++++++------
 .../camel/main/MainPropertyPlaceholderTest.java    | 12 +++++++++++
 .../k8s/etc/camel/conf.d/_configmaps/my.properties | 18 ++++++++++++++++
 .../k8s/etc/camel/conf.d/_secrets/my.properties    | 18 ++++++++++++++++
 4 files changed, 66 insertions(+), 6 deletions(-)

diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index b7857dd07d9..179d605a447 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -492,12 +492,24 @@ public abstract class BaseMainSupport extends BaseService 
{
                         @Override
                         public FileVisitResult visitFile(Path file, 
BasicFileAttributes attrs) {
                             if (!Files.isDirectory(file)) {
-                                try {
-                                    String val = new 
String(Files.readAllBytes(file));
-                                    cp.put(loc, file.getFileName().toString(), 
val);
-                                } catch (IOException e) {
-                                    LOG.warn("Some error happened while 
reading property from cloud configuration file {}",
-                                            file, e);
+                                if 
(file.getFileName().toString().endsWith(".properties")) {
+                                    try {
+                                        Properties prop = new Properties();
+                                        prop.load(Files.newInputStream(file));
+                                        cp.putAll(loc, prop);
+                                    } catch (IOException e) {
+                                        LOG.warn(
+                                                "Some error happened while 
reading properties file from cloud configuration file {}",
+                                                file, e);
+                                    }
+                                } else {
+                                    try {
+                                        String val = new 
String(Files.readAllBytes(file));
+                                        cp.put(loc, 
file.getFileName().toString(), val);
+                                    } catch (IOException e) {
+                                        LOG.warn("Some error happened while 
reading property from cloud configuration file {}",
+                                                file, e);
+                                    }
                                 }
                             }
                             return FileVisitResult.CONTINUE;
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java
index 0a3194facd8..235de56c17a 100644
--- 
a/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java
@@ -22,6 +22,7 @@ import org.junit.jupiter.api.parallel.Isolated;
 import static org.apache.camel.util.CollectionHelper.mapOf;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @Isolated
 public class MainPropertyPlaceholderTest {
@@ -98,8 +99,19 @@ public class MainPropertyPlaceholderTest {
         try {
             
main.setDefaultPropertyPlaceholderLocation("classpath:cloud.properties");
             main.start();
+            // NOTE: the usage of .txt file is done to prevent some strict 
checks on file type during building by maven
+            // however, the user can add any free form (eg, my-prop-1).
             assertEquals("My configmap value", 
main.getCamelContext().resolvePropertyPlaceholders("{{my-prop-1.txt}}"));
             assertEquals("My secret value", 
main.getCamelContext().resolvePropertyPlaceholders("{{my-prop-2.txt}}"));
+            IllegalArgumentException exception = 
assertThrows(IllegalArgumentException.class, () -> {
+                
main.getCamelContext().resolvePropertyPlaceholders("{{my.properties}}");
+            });
+            String expectedMessage = "Property with key [my.properties] not 
found";
+            assertTrue(exception.getMessage().contains(expectedMessage));
+            assertEquals("hello1", 
main.getCamelContext().resolvePropertyPlaceholders("{{my.prop.1}}"));
+            assertEquals("hello2", 
main.getCamelContext().resolvePropertyPlaceholders("{{my.prop.2}}"));
+            assertEquals("secretHello1", 
main.getCamelContext().resolvePropertyPlaceholders("{{my.secret.prop.1}}"));
+            assertEquals("secretHello2", 
main.getCamelContext().resolvePropertyPlaceholders("{{my.secret.prop.2}}"));
         } finally {
             main.stop();
         }
diff --git 
a/core/camel-main/src/test/resources/k8s/etc/camel/conf.d/_configmaps/my.properties
 
b/core/camel-main/src/test/resources/k8s/etc/camel/conf.d/_configmaps/my.properties
new file mode 100644
index 00000000000..d986a69c01a
--- /dev/null
+++ 
b/core/camel-main/src/test/resources/k8s/etc/camel/conf.d/_configmaps/my.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+my.prop.1=hello1
+my.prop.2=hello2
\ No newline at end of file
diff --git 
a/core/camel-main/src/test/resources/k8s/etc/camel/conf.d/_secrets/my.properties
 
b/core/camel-main/src/test/resources/k8s/etc/camel/conf.d/_secrets/my.properties
new file mode 100644
index 00000000000..875e512acbb
--- /dev/null
+++ 
b/core/camel-main/src/test/resources/k8s/etc/camel/conf.d/_secrets/my.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+my.secret.prop.1=secretHello1
+my.secret.prop.2=secretHello2
\ No newline at end of file

Reply via email to