Search in sources :

Example 16 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class FlowRefFactoryBean method getReferencedFlow.

protected Processor getReferencedFlow(String name, FlowRefMessageProcessor flowRefMessageProcessor) throws MuleException {
    if (name == null) {
        throw new RoutePathNotFoundException(createStaticMessage("flow-ref name expression returned 'null'"), flowRefMessageProcessor);
    }
    Component referencedFlow = getReferencedProcessor(name);
    if (referencedFlow == null) {
        throw new RoutePathNotFoundException(createStaticMessage("No flow/sub-flow with name '%s' found", name), flowRefMessageProcessor);
    }
    // for subflows, we create a new one so it must be initialised manually
    if (!(referencedFlow instanceof Flow)) {
        if (referencedFlow instanceof SubflowMessageProcessorChainBuilder) {
            MessageProcessorChainBuilder chainBuilder = (MessageProcessorChainBuilder) referencedFlow;
            locator.find(flowRefMessageProcessor.getRootContainerLocation()).filter(c -> c instanceof Flow).map(c -> (Flow) c).ifPresent(f -> chainBuilder.setProcessingStrategy(f.getProcessingStrategy()));
            referencedFlow = chainBuilder.build();
        }
        initialiseIfNeeded(referencedFlow, muleContext);
        Map<QName, Object> annotations = new HashMap<>(referencedFlow.getAnnotations());
        annotations.put(ROOT_CONTAINER_NAME_KEY, getRootContainerLocation().toString());
        referencedFlow.setAnnotations(annotations);
        startIfNeeded(referencedFlow);
    }
    return (Processor) referencedFlow;
}
Also used : Flux.just(reactor.core.publisher.Flux.just) LoadingCache(com.google.common.cache.LoadingCache) Map(java.util.Map) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Operators.outputToTarget(org.mule.runtime.core.internal.util.rx.Operators.outputToTarget) Flow(org.mule.runtime.core.api.construct.Flow) CacheLoader(com.google.common.cache.CacheLoader) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) MessageProcessors(org.mule.runtime.core.privileged.processor.MessageProcessors) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) QName(javax.xml.namespace.QName) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) ApplicationContextAware(org.springframework.context.ApplicationContextAware) Flux.from(reactor.core.publisher.Flux.from) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Inject(javax.inject.Inject) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Component(org.mule.runtime.api.component.Component) Flux.error(reactor.core.publisher.Flux.error) Disposable(org.mule.runtime.api.lifecycle.Disposable) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) AbstractComponentFactory(org.mule.runtime.dsl.api.component.AbstractComponentFactory) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) RoutePathNotFoundException(org.mule.runtime.core.privileged.routing.RoutePathNotFoundException) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) BeansException(org.springframework.beans.BeansException) Mono(reactor.core.publisher.Mono) ApplicationContext(org.springframework.context.ApplicationContext) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) Flux(reactor.core.publisher.Flux) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MuleArtifactContext(org.mule.runtime.config.internal.MuleArtifactContext) RoutePathNotFoundException(org.mule.runtime.core.privileged.routing.RoutePathNotFoundException) Processor(org.mule.runtime.core.api.processor.Processor) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Flow(org.mule.runtime.core.api.construct.Flow)

Example 17 with MuleContext

use of org.mule.runtime.core.api.MuleContext 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 18 with MuleContext

use of org.mule.runtime.core.api.MuleContext 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)

Example 19 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class DomainFunctionalTestCase method disposeMuleContexts.

@After
public void disposeMuleContexts() {
    for (MuleContext muleContext : muleContexts.values()) {
        try {
            disposeMuleContext(muleContext);
        } catch (Exception e) {
        // Nothing to do
        }
    }
    muleContexts.clear();
    applsInfrastructures.clear();
    disposeMuleContext(domainContext);
    domainInfrastructure = null;
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) After(org.junit.After)

Example 20 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class ExtensionFunctionalTestCase method addBuilders.

/**
 * Adds a {@link ConfigurationBuilder} that sets the {@link #extensionManager} into the {@link #muleContext}. This
 * {@link ConfigurationBuilder} is set as the first element of the {@code builders} {@link List}
 *
 * @param builders the list of {@link ConfigurationBuilder}s that will be used to initialise the {@link #muleContext}
 */
@Override
protected // TODO - MULE-11119: Make final again once we can add the HTTP service injection as the scehduler's is
void addBuilders(List<ConfigurationBuilder> builders) {
    super.addBuilders(builders);
    builders.add(0, new AbstractConfigurationBuilder() {

        @Override
        protected void doConfigure(MuleContext muleContext) throws Exception {
            createExtensionsManager(muleContext);
        }
    });
}
Also used : AbstractConfigurationBuilder(org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder) MuleContext(org.mule.runtime.core.api.MuleContext)

Aggregations

MuleContext (org.mule.runtime.core.api.MuleContext)46 Test (org.junit.Test)17 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Before (org.junit.Before)8 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)8 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)8 MuleException (org.mule.runtime.api.exception.MuleException)7 LifecycleUtils.initialiseIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded)7 Map (java.util.Map)6 Optional (java.util.Optional)6 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)6 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)5 ConfigurationBuilder (org.mule.runtime.core.api.config.ConfigurationBuilder)5 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 Optional.ofNullable (java.util.Optional.ofNullable)4 MuleConfiguration (org.mule.runtime.core.api.config.MuleConfiguration)4