in core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java [1201:1634]
protected void doConfigureCamelContextFromMainConfiguration(
CamelContext camelContext, MainConfigurationProperties config,
OrderedLocationProperties autoConfiguredProperties)
throws Exception {
// configure the common/default options
DefaultConfigurationConfigurer.configure(camelContext, config);
// org.apache.camel.spring.boot.CamelAutoConfiguration (camel-spring-boot) also calls the methods
// on DefaultConfigurationConfigurer, but the CamelContext being configured is already
// org.apache.camel.spring.boot.SpringBootCamelContext, which has access to Spring's ApplicationContext.
// That's why DefaultConfigurationConfigurer.afterConfigure() can alter CamelContext using beans from
// Spring's ApplicationContext.
// so here, before configuring Camel Context, we can process the registry and let Main implementations
// decide how to do it
preProcessCamelRegistry(camelContext, config);
// lookup and configure SPI beans
DefaultConfigurationConfigurer.afterConfigure(camelContext);
// now configure the various camel groups
OrderedLocationProperties prop = (OrderedLocationProperties) camelContext.getPropertiesComponent()
.loadProperties(name -> name.startsWith("camel."), MainHelper::optionKey);
// load properties from ENV (override existing)
if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) {
Properties propENV
= MainHelper.loadEnvironmentVariablesAsProperties(GROUP_PREFIXES);
if (!propENV.isEmpty()) {
prop.putAll("ENV", propENV);
LOG.debug("Properties from OS environment variables:");
for (String key : propENV.stringPropertyNames()) {
LOG.debug(" {}={}", key, propENV.getProperty(key));
}
}
}
// load properties from JVM (override existing)
if (mainConfigurationProperties.isAutoConfigurationSystemPropertiesEnabled()) {
Properties propJVM = MainHelper.loadJvmSystemPropertiesAsProperties(GROUP_PREFIXES);
if (!propJVM.isEmpty()) {
prop.putAll("SYS", propJVM);
LOG.debug("Properties from JVM system properties:");
for (String key : propJVM.stringPropertyNames()) {
LOG.debug(" {}={}", key, propJVM.getProperty(key));
}
}
}
OrderedLocationProperties contextProperties = new OrderedLocationProperties();
OrderedLocationProperties resilience4jProperties = new OrderedLocationProperties();
OrderedLocationProperties faultToleranceProperties = new OrderedLocationProperties();
OrderedLocationProperties restProperties = new OrderedLocationProperties();
OrderedLocationProperties threadPoolProperties = new OrderedLocationProperties();
OrderedLocationProperties healthProperties = new OrderedLocationProperties();
OrderedLocationProperties lraProperties = new OrderedLocationProperties();
OrderedLocationProperties otelProperties = new OrderedLocationProperties();
OrderedLocationProperties otel2Properties = new OrderedLocationProperties();
OrderedLocationProperties telemetryDevProperties = new OrderedLocationProperties();
OrderedLocationProperties metricsProperties = new OrderedLocationProperties();
OrderedLocationProperties routeTemplateProperties = new OrderedLocationProperties();
OrderedLocationProperties variableProperties = new OrderedLocationProperties();
OrderedLocationProperties beansProperties = new OrderedLocationProperties();
OrderedLocationProperties devConsoleProperties = new OrderedLocationProperties();
OrderedLocationProperties globalOptions = new OrderedLocationProperties();
OrderedLocationProperties httpServerProperties = new OrderedLocationProperties();
OrderedLocationProperties httpManagementServerProperties = new OrderedLocationProperties();
OrderedLocationProperties sslProperties = new OrderedLocationProperties();
OrderedLocationProperties debuggerProperties = new OrderedLocationProperties();
OrderedLocationProperties tracerProperties = new OrderedLocationProperties();
OrderedLocationProperties routeControllerProperties = new OrderedLocationProperties();
for (String key : prop.stringPropertyNames()) {
String loc = prop.getLocation(key);
if (startsWithIgnoreCase(key, "camel.context.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(14);
validateOptionAndValue(key, option, value);
contextProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.resilience4j.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(19);
validateOptionAndValue(key, option, value);
resilience4jProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.faulttolerance.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(21);
validateOptionAndValue(key, option, value);
faultToleranceProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.rest.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(11);
validateOptionAndValue(key, option, value);
restProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.threadpool.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(17);
validateOptionAndValue(key, option, value);
threadPoolProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.health.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(13);
validateOptionAndValue(key, option, value);
healthProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.lra.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(10);
validateOptionAndValue(key, option, value);
lraProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.opentelemetry2.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(21);
validateOptionAndValue(key, option, value);
otel2Properties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.opentelemetry.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(20);
validateOptionAndValue(key, option, value);
otelProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.telemetryDev.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(19);
validateOptionAndValue(key, option, value);
telemetryDevProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.metrics.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(14);
validateOptionAndValue(key, option, value);
metricsProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.routeTemplate")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(19);
validateOptionAndValue(key, option, value);
routeTemplateProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.devConsole.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(17);
validateOptionAndValue(key, option, value);
devConsoleProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.variable.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(15);
validateOptionAndValue(key, option, value);
variableProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.beans.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(12);
validateOptionAndValue(key, option, value);
beansProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.globalOptions.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(20);
validateOptionAndValue(key, option, value);
globalOptions.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.server.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(13);
validateOptionAndValue(key, option, value);
httpServerProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.management.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(17);
validateOptionAndValue(key, option, value);
httpManagementServerProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.ssl.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(10);
validateOptionAndValue(key, option, value);
sslProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.debug.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(12);
validateOptionAndValue(key, option, value);
debuggerProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.trace.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(12);
validateOptionAndValue(key, option, value);
tracerProperties.put(loc, optionKey(option), value);
} else if (startsWithIgnoreCase(key, "camel.routeController.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(22);
validateOptionAndValue(key, option, value);
routeControllerProperties.put(loc, optionKey(option), value);
}
}
// global options first
if (!globalOptions.isEmpty()) {
for (var name : globalOptions.stringPropertyNames()) {
Object value = globalOptions.getProperty(name);
mainConfigurationProperties.addGlobalOption(name, value);
}
}
// create variables first as they may be used later
if (!variableProperties.isEmpty()) {
LOG.debug("Auto-configuring Variables from loaded properties: {}", variableProperties.size());
MainSupportModelConfigurer.setVariableProperties(camelContext, variableProperties, autoConfiguredProperties);
}
// create beans first as they may be used later
if (!beansProperties.isEmpty()) {
LOG.debug("Creating and binding beans to registry from loaded properties: {}", beansProperties.size());
bindBeansToRegistry(camelContext, beansProperties, "camel.beans.",
mainConfigurationProperties.isAutoConfigurationFailFast(),
mainConfigurationProperties.isAutoConfigurationLogSummary(), true, autoConfiguredProperties);
}
if (!contextProperties.isEmpty()) {
LOG.debug("Auto-configuring CamelContext from loaded properties: {}", contextProperties.size());
setPropertiesOnTarget(camelContext, camelContext, contextProperties, "camel.context.",
mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
setPropertiesOnTarget(camelContext, camelContext.getCamelContextExtension(), contextProperties,
"camel.context.",
mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
}
if (!restProperties.isEmpty() || mainConfigurationProperties.hasRestConfiguration()) {
RestConfigurationProperties rest = mainConfigurationProperties.rest();
LOG.debug("Auto-configuring Rest DSL from loaded properties: {}", restProperties.size());
setPropertiesOnTarget(camelContext, rest, restProperties, "camel.rest.",
mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
camelContext.setRestConfiguration(rest);
}
if (!httpServerProperties.isEmpty() || mainConfigurationProperties.hasHttpServerConfiguration()) {
LOG.debug("Auto-configuring HTTP Server from loaded properties: {}", httpServerProperties.size());
setHttpServerProperties(camelContext, httpServerProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!httpManagementServerProperties.isEmpty() || mainConfigurationProperties.hasHttpManagementServerConfiguration()) {
LOG.debug("Auto-configuring HTTP Management Server from loaded properties: {}",
httpManagementServerProperties.size());
setHttpManagementServerProperties(camelContext, httpManagementServerProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!threadPoolProperties.isEmpty() || mainConfigurationProperties.hasThreadPoolConfiguration()) {
LOG.debug("Auto-configuring Thread Pool from loaded properties: {}", threadPoolProperties.size());
MainSupportModelConfigurer.setThreadPoolProperties(camelContext, mainConfigurationProperties, threadPoolProperties,
autoConfiguredProperties);
}
// need to let camel-main setup health-check using its convention over configuration
boolean hc = mainConfigurationProperties.health().getEnabled() != null; // health-check is enabled by default
if (hc || !healthProperties.isEmpty() || mainConfigurationProperties.hasHealthCheckConfiguration()) {
LOG.debug("Auto-configuring HealthCheck from loaded properties: {}", healthProperties.size());
setHealthCheckProperties(camelContext, healthProperties,
autoConfiguredProperties);
}
if (!routeTemplateProperties.isEmpty()) {
LOG.debug("Auto-configuring Route templates from loaded properties: {}", routeTemplateProperties.size());
setRouteTemplateProperties(camelContext, routeTemplateProperties,
autoConfiguredProperties);
}
if (!lraProperties.isEmpty() || mainConfigurationProperties.hasLraConfiguration()) {
LOG.debug("Auto-configuring Saga LRA from loaded properties: {}", lraProperties.size());
setLraCheckProperties(camelContext, lraProperties, mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!otelProperties.isEmpty() || mainConfigurationProperties.hasOtelConfiguration()) {
LOG.debug("Auto-configuring OpenTelemetry from loaded properties: {}", otelProperties.size());
setOtelProperties(camelContext, otelProperties, mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
} else if (!otel2Properties.isEmpty() || mainConfigurationProperties.hasOtel2Configuration()) {
LOG.debug("Auto-configuring OpenTelemetry 2 from loaded properties: {}", otel2Properties.size());
setOtel2Properties(camelContext, otel2Properties, mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
} else {
// Attempt to fallback to Telemetry simple only if no other tracing service is found
if (!telemetryDevProperties.isEmpty() || mainConfigurationProperties.hasTelemetryDevConfiguration()) {
LOG.debug("Auto-configuring TelemetryDev from loaded properties: {}", telemetryDevProperties.size());
setTelemetryDevProperties(camelContext, telemetryDevProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
}
if (!metricsProperties.isEmpty() || mainConfigurationProperties.hasMetricsConfiguration()) {
LOG.debug("Auto-configuring Micrometer metrics from loaded properties: {}", metricsProperties.size());
setMetricsProperties(camelContext, metricsProperties, mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!devConsoleProperties.isEmpty()) {
LOG.debug("Auto-configuring Dev Console from loaded properties: {}", devConsoleProperties.size());
setDevConsoleProperties(camelContext, devConsoleProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!sslProperties.isEmpty() || mainConfigurationProperties.hasSslConfiguration()) {
LOG.debug("Auto-configuring SSL from loaded properties: {}", sslProperties.size());
setSslProperties(camelContext, sslProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!debuggerProperties.isEmpty() || mainConfigurationProperties.hasDebuggerConfiguration()) {
LOG.debug("Auto-configuring Debugger from loaded properties: {}", debuggerProperties.size());
setDebuggerProperties(camelContext, debuggerProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!tracerProperties.isEmpty() || mainConfigurationProperties.hasTracerConfiguration()) {
LOG.debug("Auto-configuring Tracer from loaded properties: {}", tracerProperties.size());
setTracerProperties(camelContext, tracerProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
if (!routeControllerProperties.isEmpty() || mainConfigurationProperties.hasRouteControllerConfiguration()) {
LOG.debug("Auto-configuring Route Controller from loaded properties: {}", routeControllerProperties.size());
setRouteControllerProperties(camelContext, routeControllerProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
// configure which requires access to the model
MainSupportModelConfigurer.configureModelCamelContext(camelContext, mainConfigurationProperties,
autoConfiguredProperties, resilience4jProperties, faultToleranceProperties);
// log which options was not set
if (!variableProperties.isEmpty()) {
variableProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.variable.{}={}", k, v);
});
}
if (!beansProperties.isEmpty()) {
beansProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.beans.{}={}", k, v);
});
}
if (!contextProperties.isEmpty()) {
contextProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.context.{}={}", k, v);
});
}
if (!resilience4jProperties.isEmpty()) {
resilience4jProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.resilience4j.{}={}", k, v);
});
}
if (!faultToleranceProperties.isEmpty()) {
faultToleranceProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.faulttolerance.{}={}", k, v);
});
}
if (!restProperties.isEmpty()) {
restProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.rest.{}={}", k, v);
});
}
if (!threadPoolProperties.isEmpty()) {
threadPoolProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.threadpool.{}={}", k, v);
});
}
if (!healthProperties.isEmpty()) {
healthProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.health.{}={}", k, v);
});
}
if (!sslProperties.isEmpty()) {
sslProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.ssl.{}={}", k, v);
});
}
if (!debuggerProperties.isEmpty()) {
debuggerProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.debug.{}={}", k, v);
});
}
if (!routeControllerProperties.isEmpty()) {
routeControllerProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.routeController.{}={}", k, v);
});
}
if (!devConsoleProperties.isEmpty()) {
devConsoleProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.devConsole.{}={}", k, v);
});
}
if (!routeTemplateProperties.isEmpty()) {
routeTemplateProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.routetemplate.{}={}", k, v);
});
}
if (!lraProperties.isEmpty()) {
lraProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.lra.{}={}", k, v);
});
}
if (!otelProperties.isEmpty()) {
otelProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.opentelemetry.{}={}", k, v);
});
}
if (!otel2Properties.isEmpty()) {
otel2Properties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.opentelemetry2.{}={}", k, v);
});
}
if (!telemetryDevProperties.isEmpty()) {
telemetryDevProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.telemetryDev.{}={}", k, v);
});
}
if (!httpServerProperties.isEmpty()) {
httpServerProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.server.{}={}", k, v);
});
}
if (!httpManagementServerProperties.isEmpty()) {
httpManagementServerProperties.forEach((k, v) -> {
LOG.warn("Property not auto-configured: camel.management.{}={}", k, v);
});
}
// and call after all properties are set
DefaultConfigurationConfigurer.afterPropertiesSet(camelContext);
}