This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 530d7791c3c6 CAMEL-22695: camel-jbang - Fix --observe to load always
regardless if there is a custom application.properties. (#19962)
530d7791c3c6 is described below
commit 530d7791c3c6a7f748a54d93a1bfcad888f5598a
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 18 14:36:22 2025 +0100
CAMEL-22695: camel-jbang - Fix --observe to load always regardless if there
is a custom application.properties. (#19962)
---
.../org/apache/camel/main/BaseMainSupport.java | 32 +++++++++++++++++++---
.../java/org/apache/camel/main/MainConstants.java | 2 --
2 files changed, 28 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 1ff586554e45..98283fb9aa2d 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
@@ -105,6 +105,7 @@ import org.apache.camel.support.startup.EnvStartupCondition;
import org.apache.camel.support.startup.FileStartupCondition;
import org.apache.camel.support.startup.LoggingStartupStepRecorder;
import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.OrderedLocationProperties;
import org.apache.camel.util.OrderedProperties;
@@ -144,9 +145,7 @@ public abstract class BaseMainSupport extends BaseService {
protected final OrderedLocationProperties wildcardProperties = new
OrderedLocationProperties();
protected RoutesCollector routesCollector = new DefaultRoutesCollector();
protected String propertyPlaceholderLocations;
- protected String defaultPropertyPlaceholderLocation
- = MainConstants.DEFAULT_PROPERTY_PLACEHOLDER_LOCATION + ","
- + MainConstants.DEFAULT_OBSERVABILITY_SERVICES_PROPERTY_LOCATION;
+ protected String defaultPropertyPlaceholderLocation =
MainConstants.DEFAULT_PROPERTY_PLACEHOLDER_LOCATION;
protected Properties initialProperties;
protected Properties overrideProperties;
protected boolean standalone = true;
@@ -442,6 +441,17 @@ public abstract class BaseMainSupport extends BaseService {
}
}
+ // load optional observability configuration from inside JAR
+ final Properties osp = tryLoadObservabilityProperties(camelContext,
"observability-services.properties");
+ if (!osp.isEmpty()) {
+ // only add observability properties if not already defined as
initial
+ osp.forEach((k, v) -> {
+ if (!initialProperties.containsKey(k)) {
+ initialProperties.setProperty(k.toString(), v.toString());
+ }
+ });
+ }
+
final Properties ip = tryLoadProperties(initialProperties,
MainConstants.INITIAL_PROPERTIES_LOCATION, camelContext);
if (ip != null) {
pc.setInitialProperties(ip);
@@ -477,6 +487,20 @@ public abstract class BaseMainSupport extends BaseService {
return ip;
}
+ private static Properties tryLoadObservabilityProperties(CamelContext
camelContext, String location) {
+ Properties p = new Properties();
+ InputStream is = null;
+ try {
+ is = ResourceHelper.resolveResourceAsInputStream(camelContext,
location);
+ p.load(is);
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ IOHelper.close(is);
+ }
+ return p;
+ }
+
private static Properties tryLoadCloudProperties(
Properties overridProperties, String cloudPropertiesLocations) {
final OrderedLocationProperties cp = new OrderedLocationProperties();
@@ -485,7 +509,7 @@ public abstract class BaseMainSupport extends BaseService {
for (String loc : locations) {
Path confPath = Paths.get(loc);
if (Files.exists(confPath) && Files.isDirectory(confPath)) {
- Files.walkFileTree(confPath, new SimpleFileVisitor<Path>()
{
+ Files.walkFileTree(confPath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) {
if (!Files.isDirectory(file)) {
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java
b/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java
index 03d7d7ab360a..0304faa0acef 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java
@@ -19,8 +19,6 @@ package org.apache.camel.main;
public final class MainConstants {
public static final String DEFAULT_PROPERTY_PLACEHOLDER_LOCATION =
"classpath:application.properties;optional=true";
- public static final String DEFAULT_OBSERVABILITY_SERVICES_PROPERTY_LOCATION
- = "classpath:observability-services.properties;optional=true";
public static final String INITIAL_PROPERTIES_LOCATION =
"camel.main.initial-properties-location";
public static final String OVERRIDE_PROPERTIES_LOCATION =
"camel.main.override-properties-location";
public static final String CLOUD_PROPERTIES_LOCATION =
"camel.main.cloud-properties-location";