Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mp-config workaround #571

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import java.util.Collection;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.function.Predicate;

import org.apache.camel.AsyncProcessor;
import org.apache.camel.CamelContext;
Expand All @@ -30,6 +28,7 @@
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.TypeConverter;
import org.apache.camel.component.microprofile.config.CamelMicroProfilePropertiesSource;
import org.apache.camel.health.HealthCheckRegistry;
import org.apache.camel.impl.DefaultExecutorServiceManager;
import org.apache.camel.impl.engine.AbstractCamelContext;
Expand Down Expand Up @@ -85,7 +84,6 @@
import org.apache.camel.spi.Injector;
import org.apache.camel.spi.Language;
import org.apache.camel.spi.LanguageResolver;
import org.apache.camel.spi.LoadablePropertiesSource;
import org.apache.camel.spi.ManagementNameStrategy;
import org.apache.camel.spi.MessageHistoryFactory;
import org.apache.camel.spi.ModelJAXBContextFactory;
Expand All @@ -106,8 +104,6 @@
import org.apache.camel.spi.UnitOfWorkFactory;
import org.apache.camel.spi.UuidGenerator;
import org.apache.camel.spi.ValidatorRegistry;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;

public class FastCamelContext extends AbstractCamelContext {
private Model model;
Expand Down Expand Up @@ -320,57 +316,7 @@ protected BeanIntrospection createBeanIntrospection() {
protected PropertiesComponent createPropertiesComponent() {
org.apache.camel.component.properties.PropertiesComponent pc = new org.apache.camel.component.properties.PropertiesComponent();
pc.setAutoDiscoverPropertiesSources(false);
//
// The CamelMicroProfilePropertiesSource obtains a reference to the Config object using
// ConfigProvider.getConfig() but in 1.0.0.Final there's that make the instance retrieved
// not profile aware that should be solved by https://github.com/quarkusio/quarkus/pull/5387
// which will be available in Quarkus 1.1.0.
//
// As a workaround the instance can be obtained with:
//
// ConfigProviderResolver.instance().getConfig()
//
// so I've replace the CamelMicroProfilePropertiesSource with a temporary custom implementation.
//
// TODO: remove this workaround once 1.1.0 si out
//
pc.addPropertiesSource(new LoadablePropertiesSource() {
@Override
public String getName() {
return "mp-properties-source";
}

@Override
public String getProperty(String name) {
return ConfigProviderResolver.instance().getConfig().getOptionalValue(name, String.class).orElse(null);
}

@Override
public Properties loadProperties() {
final Properties answer = new Properties();
final Config config = ConfigProviderResolver.instance().getConfig();

for (String name : config.getPropertyNames()) {
answer.put(name, config.getValue(name, String.class));
}

return answer;
}

@Override
public Properties loadProperties(Predicate<String> filter) {
final Properties answer = new Properties();
final Config config = ConfigProviderResolver.instance().getConfig();

for (String name : config.getPropertyNames()) {
if (filter.test(name)) {
answer.put(name, config.getValue(name, String.class));
}
}

return answer;
}
});
pc.addPropertiesSource(new CamelMicroProfilePropertiesSource());

return pc;

Expand Down