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
6 changes: 6 additions & 0 deletions core/camel-spring-boot/src/main/docs/spring-boot.json
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,12 @@
"sourceType": "org.apache.camel.spring.boot.CamelConfigurationProperties$Main",
"defaultValue": 1000
},
{
"name": "camel.main.profile",
"type": "java.lang.String",
"description": "Camel profile to use when running. The dev profile is for development, which enables a set of additional developer focus functionality, tracing, debugging, and gathering additional runtime statistics that are useful during development. However, those additional features has a slight overhead cost, and are not enabled for production profile. The default profile is prod.",
"sourceType": "org.apache.camel.spring.boot.CamelConfigurationProperties$Main"
},
{
"name": "camel.main.route-filter-exclude-pattern",
"type": "java.lang.String",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.camel.main.DebuggerConfigurationProperties;
import org.apache.camel.main.DefaultConfigurationConfigurer;
import org.apache.camel.main.MainListener;
import org.apache.camel.main.ProfileConfigurer;
import org.apache.camel.main.RoutesCollector;
import org.apache.camel.main.fatjar.FatJarPackageScanClassResolver;
import org.apache.camel.main.fatjar.FatJarPackageScanResourceResolver;
Expand Down Expand Up @@ -216,6 +217,11 @@ public static CamelContext doConfigureCamelContext(ApplicationContext applicatio
config.getMain().getRouteFilterIncludePattern(), config.getMain().getRouteFilterExcludePattern());
}

// configure profile (dev/prod) defaults before applying main configuration,
// so that profile defaults are set but user-explicit properties take precedence
Properties autoConfigured = doExtractCamelMainProperties(applicationContext);
ProfileConfigurer.configureCommon(camelContext, config.getMain().getProfile(), config.getMain(), autoConfigured);

// configure the common/default options
DefaultConfigurationConfigurer.configure(camelContext, config.getMain());
// lookup and configure SPI beans
Expand All @@ -230,6 +236,27 @@ public static CamelContext doConfigureCamelContext(ApplicationContext applicatio
return camelContext;
}

/**
* Collect all camel.main.* property names that the user has explicitly configured
* so that ProfileConfigurer does not override them with profile defaults.
*/
protected static Properties doExtractCamelMainProperties(ApplicationContext applicationContext) {
Properties answer = new Properties();
Environment env = applicationContext.getEnvironment();
if (env instanceof ConfigurableEnvironment cev) {
cev.getPropertySources().forEach(ps -> {
if (ps instanceof EnumerablePropertySource<?> eps) {
for (String n : eps.getPropertyNames()) {
if (n.startsWith("camel.main.")) {
answer.put(n, cev.getProperty(n, ""));
}
}
}
});
}
return answer;
}

protected static Map<String, String> doExtractVariablesFromSpringBoot(ConfigurableEnvironment env) {
Map<String, String> answer = new LinkedHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class CamelErrorRegistryAutoConfiguration {

@Bean
public ErrorRegistry errorRegistry(CamelContext camelContext, CamelErrorRegistryConfigurationProperties config) {
// dev profile enables error registry to capture routing errors for tooling (TUI)
if (!config.isEnabled() && "dev".equals(camelContext.getCamelContextExtension().getProfile())) {
config.setEnabled(true);
}
if (!config.isEnabled()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public class CamelSecurityPolicyAutoConfiguration {
SecurityPolicyResult camelSecurityPolicyResult(CamelContext camelContext,
CamelSecurityPolicyConfigurationProperties config, Environment environment) {

// apply profile-based security defaults
String profile = camelContext.getCamelContextExtension().getProfile();
if ("dev".equals(profile) && config.getInsecureDevPolicy() == null) {
config.setInsecureDevPolicy("allow");
} else if ("prod".equals(profile) && "warn".equals(config.getPolicy())) {
config.setPolicy("fail");
}

SecurityConfigurationProperties securityConfig = applySecurityProperties(camelContext, config);

Map<String, Object> camelProperties = extractCamelProperties(environment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class CamelTraceAutoConfiguration {
@Bean
public BacklogTracer backlogTracer(CamelContext camelContext, CamelTraceConfigurationProperties config)
throws Exception {
// dev profile enables tracer standby so tooling (TUI) can activate tracing on demand
if (!config.isStandby() && "dev".equals(camelContext.getCamelContextExtension().getProfile())) {
config.setStandby(true);
}
if (!config.isEnabled() && !config.isStandby()) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion tooling/camel-spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5223,7 +5223,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-start</artifactId>
<version>6.1.0</version>
<version>6.1.1</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
Expand Down
Loading