use of org.mule.runtime.core.api.config.ConfigurationBuilder in project mule by mulesoft.
the class DefaultMuleContextFactory method createMuleContext.
/**
* Creates a new MuleContext using the given configurationBuilder and configuration. Properties if provided are used to replace
* "property placeholder" value in configuration files.
*/
public MuleContext createMuleContext(final List<ConfigurationBuilder> configurationBuilders, final Map<String, Object> properties, MuleConfiguration configuration) throws InitialisationException, ConfigurationException {
// Create MuleContext
MuleContextBuilder contextBuilder = MuleContextBuilder.builder(APP);
contextBuilder.setMuleConfiguration(configuration);
return doCreateMuleContext(contextBuilder, new ContextConfigurator() {
@Override
public void configure(MuleContext muleContext) throws ConfigurationException {
// Configure with startup properties
if (properties != null && !properties.isEmpty()) {
new SimpleConfigurationBuilder(properties).configure(muleContext);
}
// Configure with configurationBuilder
for (ConfigurationBuilder configurationBuilder : configurationBuilders) {
configurationBuilder.configure(muleContext);
}
}
});
}
use of org.mule.runtime.core.api.config.ConfigurationBuilder in project mule by mulesoft.
the class AutoConfigurationBuilder method autoConfigure.
protected void autoConfigure(MuleContext muleContext, ConfigResource[] resources) throws ConfigurationException {
Map<String, List<ConfigResource>> configsMap = new LinkedHashMap<String, List<ConfigResource>>();
for (ConfigResource resource : resources) {
String configExtension = substringAfterLast(resource.getUrl().getPath(), ".");
List<ConfigResource> configs = configsMap.get(configExtension);
if (configs == null) {
configs = new ArrayList<ConfigResource>();
configsMap.put(configExtension, configs);
}
configs.add(resource);
}
try {
Properties props = loadProperties(getResource("configuration-builders.properties", this.getClass()).openStream());
for (Map.Entry<String, List<ConfigResource>> e : configsMap.entrySet()) {
String extension = e.getKey();
List<ConfigResource> configs = e.getValue();
String className = (String) props.get(extension);
if (className == null || !ClassUtils.isClassOnPath(className, this.getClass())) {
throw new ConfigurationException(configurationBuilderNoMatching(createConfigResourcesString()));
}
ConfigurationBuilder cb = (ConfigurationBuilder) ClassUtils.instantiateClass(className, new Object[] { configs.stream().map(ConfigResource::getResourceName).toArray(String[]::new), getArtifactProperties(), artifactType });
if (parentContext != null && cb instanceof ParentMuleContextAwareConfigurationBuilder) {
((ParentMuleContextAwareConfigurationBuilder) cb).setParentContext(parentContext);
} else if (parentContext != null) {
throw new MuleRuntimeException(createStaticMessage(format("ConfigurationBuilder %s does not support domain context", cb.getClass().getCanonicalName())));
}
cb.configure(muleContext);
}
} catch (ConfigurationException e) {
throw e;
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
use of org.mule.runtime.core.api.config.ConfigurationBuilder in project mule by mulesoft.
the class AbstractXmlExtensionMuleArtifactFunctionalTestCase method addBuilders.
@Override
protected void addBuilders(List<ConfigurationBuilder> builders) {
super.addBuilders(builders);
builders.add(new AbstractConfigurationBuilder() {
@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
ExtensionManager extensionManager;
if (muleContext.getExtensionManager() == null) {
extensionManager = createDefaultExtensionManager();
muleContext.setExtensionManager(extensionManager);
initialiseIfNeeded(extensionManager, muleContext);
}
extensionManager = muleContext.getExtensionManager();
registerXmlExtensions(extensionManager);
}
private void registerXmlExtensions(ExtensionManager extensionManager) {
// take all the plugins loaded by org.mule.test.runner.api.IsolatedClassLoaderExtensionsManagerConfigurationBuilder in the extension manager
final Set<ExtensionModel> extensions = new HashSet<>(extensionManager.getExtensions());
for (String modulePath : getModulePaths()) {
Map<String, Object> params = new HashMap<>();
params.put(XmlExtensionModelLoader.RESOURCE_XML, modulePath);
params.put(XmlExtensionModelLoader.VALIDATE_XML, shouldValidateXml());
operationsOutputPath().ifPresent(path -> params.put(XmlExtensionModelLoader.RESOURCE_DECLARATION, path));
final DslResolvingContext dslResolvingContext = getDefault(extensions);
final ExtensionModel extensionModel = new XmlExtensionModelLoader().loadExtensionModel(getClass().getClassLoader(), dslResolvingContext, params);
extensions.add(extensionModel);
}
for (ExtensionModel extension : extensions) {
extensionManager.registerExtension(extension);
}
}
});
}
use of org.mule.runtime.core.api.config.ConfigurationBuilder in project mule by mulesoft.
the class DomainContextBuilder method build.
public MuleContext build() throws Exception {
List<ConfigurationBuilder> builders = new ArrayList<>(3);
ConfigurationBuilder cfgBuilder = getDomainBuilder(domainConfig);
builders.add(cfgBuilder);
addBuilders(builders);
DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContext domainContext = muleContextFactory.createMuleContext(builders, muleContextBuilder);
domainContext.start();
return domainContext;
}
use of org.mule.runtime.core.api.config.ConfigurationBuilder in project mule by mulesoft.
the class DomainFunctionalTestCase method setUpMuleContexts.
@Before
public void setUpMuleContexts() throws Exception {
final DomainContextBuilder domainContextBuilder = new DomainContextBuilder() {
@Override
protected void addBuilders(List<ConfigurationBuilder> builders) {
super.addBuilders(builders);
builders.add(new SimpleConfigurationBuilder(getDomainStartUpRegistryObjects()));
if (getBuilder() != null) {
builders.add(getBuilder());
}
}
}.setDomainConfig(getDomainConfigs());
domainContext = domainContextBuilder.build();
domainInfrastructure = new ArtifactInstanceInfrastructure();
domainContext.getInjector().inject(domainInfrastructure);
ApplicationConfig[] applicationConfigs = getConfigResources();
for (ApplicationConfig applicationConfig : applicationConfigs) {
MuleContext muleContext = createAppMuleContext(applicationConfig.applicationResources);
muleContexts.put(applicationConfig.applicationName, muleContext);
ArtifactInstanceInfrastructure appInfrasturcture = new ArtifactInstanceInfrastructure();
muleContext.getInjector().inject(appInfrasturcture);
applsInfrastructures.put(applicationConfig.applicationName, appInfrasturcture);
}
}
Aggregations