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 @@ -47,6 +47,7 @@
import org.apache.camel.spi.CliConnectorFactory;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.PackageScanResourceResolver;
import org.apache.camel.spi.RuntimePropertiesProvider;
import org.apache.camel.spi.StartupConditionStrategy;
import org.apache.camel.spi.StartupStepRecorder;
import org.apache.camel.spi.VariableRepository;
Expand Down Expand Up @@ -405,6 +406,12 @@ ConsumerTemplate consumerTemplate(CamelContext camelContext, CamelConfigurationP

// SpringCamelContext integration

@Bean
@ConditionalOnMissingBean(RuntimePropertiesProvider.class)
RuntimePropertiesProvider runtimePropertiesProvider(Environment env) {
return new SpringBootRuntimePropertiesProvider((ConfigurableEnvironment) env);
}

@Bean
@ConditionalOnMissingBean(PropertiesParser.class)
PropertiesParser propertiesParser(Environment env) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.
*/
package org.apache.camel.spring.boot;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.camel.spi.RuntimePropertiesProvider;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;

/**
* {@link RuntimePropertiesProvider} that enumerates application properties from the Spring Boot {@link
* ConfigurableEnvironment}. These properties are used for display purposes only (e.g. the Properties dev console) and
* do not affect Camel's placeholder resolution.
* <p>
* Property sources that represent environment variables, JVM system properties, and Spring Boot internals are skipped
* to avoid noise — only application-level configuration is included. However, camel/spring/server/management keys from
* env/sys sources are still included since they represent application configuration.
*/
public class SpringBootRuntimePropertiesProvider implements RuntimePropertiesProvider {

private static final Set<String> SKIP_SOURCES = Set.of(
"systemProperties",
"systemEnvironment",
"configurationProperties",
"random");

private final ConfigurableEnvironment environment;

public SpringBootRuntimePropertiesProvider(ConfigurableEnvironment environment) {
this.environment = environment;
}

@Override
public Collection<Property> getProperties() {
Collection<Property> answer = new ArrayList<>();
Set<String> seen = new LinkedHashSet<>();
environment.getPropertySources().forEach(ps -> {
boolean skipped = SKIP_SOURCES.contains(ps.getName());
String source = toSourceLabel(ps.getName());
if (ps instanceof EnumerablePropertySource<?> eps) {
for (String name : eps.getPropertyNames()) {
if (!seen.contains(name)) {
if (skipped && !isApplicationKey(name)) {
continue;
}
seen.add(name);
try {
Object value = environment.getProperty(name);
answer.add(new Property(name, value, source));
} catch (Exception e) {
// ignore properties that cannot be resolved
}
}
}
}
});
return answer;
}

private static boolean isApplicationKey(String name) {
String lower = name.toLowerCase();
return lower.startsWith("camel.") || lower.startsWith("camel_")
|| lower.startsWith("spring.") || lower.startsWith("spring_")
|| lower.startsWith("server.") || lower.startsWith("server_")
|| lower.startsWith("management.") || lower.startsWith("management_");
}

private static String toSourceLabel(String sourceName) {
if ("systemProperties".equals(sourceName)) {
return "JVM";
} else if ("systemEnvironment".equals(sourceName)) {
return "ENV";
} else if ("server.ports".equals(sourceName)) {
return "Spring Boot";
} else {
return "Spring Boot";
}
}
}
Loading