Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
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;
Expand Down Expand Up @@ -147,9 +148,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;
Expand Down Expand Up @@ -445,6 +444,17 @@ protected void configurePropertiesService(CamelContext camelContext) throws Exce
}
}

// 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);
Expand Down Expand Up @@ -480,6 +490,20 @@ private Properties tryLoadProperties(
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();
Expand All @@ -488,7 +512,7 @@ private static Properties tryLoadCloudProperties(
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
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";
Expand Down