This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch camel-4.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.14.x by this push:
new d6a7b178fc9 feat(core): scan .properties in cloud configuration
d6a7b178fc9 is described below
commit d6a7b178fc9ea62b0297603186a8c7b006460db6
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 cff1264bd25..b20c3e5f74c 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
@@ -489,12 +489,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