Search in sources :

Example 1 with ConfigurationBuilder

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);
            }
        }
    });
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) AutoConfigurationBuilder(org.mule.runtime.core.internal.config.builders.AutoConfigurationBuilder) ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) DefaultMuleContextBuilder(org.mule.runtime.core.internal.context.DefaultMuleContextBuilder)

Example 2 with ConfigurationBuilder

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);
    }
}
Also used : ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) ParentMuleContextAwareConfigurationBuilder(org.mule.runtime.core.internal.config.ParentMuleContextAwareConfigurationBuilder) AbstractResourceConfigurationBuilder(org.mule.runtime.core.api.config.builders.AbstractResourceConfigurationBuilder) Properties(java.util.Properties) PropertiesUtils.loadProperties(org.mule.runtime.core.api.util.PropertiesUtils.loadProperties) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) LinkedHashMap(java.util.LinkedHashMap) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) ParentMuleContextAwareConfigurationBuilder(org.mule.runtime.core.internal.config.ParentMuleContextAwareConfigurationBuilder) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with ConfigurationBuilder

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);
            }
        }
    });
}
Also used : XmlExtensionModelLoader(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader) AbstractConfigurationBuilder(org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder) Set(java.util.Set) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) MuleExtensionUtils.createDefaultExtensionManager(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.createDefaultExtensionManager) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) XmlExtensionLoaderDelegate(org.mule.runtime.extension.internal.loader.XmlExtensionLoaderDelegate) HashSet(java.util.HashSet) List(java.util.List) MuleContext(org.mule.runtime.core.api.MuleContext) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) Map(java.util.Map) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) Optional(java.util.Optional) MuleArtifactFunctionalTestCase(org.mule.functional.junit4.MuleArtifactFunctionalTestCase) ArtifactClassLoaderRunnerConfig(org.mule.test.runner.ArtifactClassLoaderRunnerConfig) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) AbstractConfigurationBuilder(org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder) Set(java.util.Set) HashSet(java.util.HashSet) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MuleContext(org.mule.runtime.core.api.MuleContext) MuleExtensionUtils.createDefaultExtensionManager(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.createDefaultExtensionManager) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) HashMap(java.util.HashMap) Map(java.util.Map) XmlExtensionModelLoader(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader)

Example 4 with ConfigurationBuilder

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;
}
Also used : SpringXmlConfigurationBuilderFactory.createConfigurationBuilder(org.mule.runtime.config.api.SpringXmlConfigurationBuilderFactory.createConfigurationBuilder) ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) TestServicesConfigurationBuilder(org.mule.tck.config.TestServicesConfigurationBuilder) DefaultMuleContextFactory(org.mule.runtime.core.api.context.DefaultMuleContextFactory) MuleContext(org.mule.runtime.core.api.MuleContext) ArrayList(java.util.ArrayList)

Example 5 with ConfigurationBuilder

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);
    }
}
Also used : ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) MuleContext(org.mule.runtime.core.api.MuleContext) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) Before(org.junit.Before)

Aggregations

ConfigurationBuilder (org.mule.runtime.core.api.config.ConfigurationBuilder)11 MuleContext (org.mule.runtime.core.api.MuleContext)7 ArrayList (java.util.ArrayList)6 SimpleConfigurationBuilder (org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder)6 DefaultMuleContextFactory (org.mule.runtime.core.api.context.DefaultMuleContextFactory)5 List (java.util.List)3 Map (java.util.Map)3 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)3 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 Properties (java.util.Properties)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 SpringXmlConfigurationBuilderFactory.createConfigurationBuilder (org.mule.runtime.config.api.SpringXmlConfigurationBuilderFactory.createConfigurationBuilder)2 DefaultMuleConfiguration (org.mule.runtime.core.api.config.DefaultMuleConfiguration)2 MuleContextFactory (org.mule.runtime.core.api.context.MuleContextFactory)2 MuleContextListener (org.mule.runtime.core.api.context.notification.MuleContextListener)2 DefaultsConfigurationBuilder (org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder)2 TestServicesConfigurationBuilder (org.mule.tck.config.TestServicesConfigurationBuilder)2 File (java.io.File)1 Arrays.asList (java.util.Arrays.asList)1