Search in sources :

Example 1 with MuleContext

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

the class DataWeaveExpressionLanguageAdaptorTestCase method payloadExpressionShouldNotBeEvaluate.

@Test
public void payloadExpressionShouldNotBeEvaluate() throws MuleException {
    BindingContext bindingContext = BindingContext.builder().build();
    MuleContext muleContext = mock(MuleContext.class);
    DefaultExpressionLanguageFactoryService languageFactory = mock(DefaultExpressionLanguageFactoryService.class);
    ExpressionLanguage expressionLanguage = spy(ExpressionLanguage.class);
    when(languageFactory.create()).thenReturn(expressionLanguage);
    CoreEvent event = testEvent();
    new DataWeaveExpressionLanguageAdaptor(muleContext, registry, languageFactory).evaluate("#[payload]", event, bindingContext);
    verify(expressionLanguage, never()).evaluate(eq("payload"), any(BindingContext.class));
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) BindingContext(org.mule.runtime.api.el.BindingContext) ExpressionLanguage(org.mule.runtime.api.el.ExpressionLanguage) Test(org.junit.Test)

Example 2 with MuleContext

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

the class DefaultMuleContextBuilderTestCase method testBuildMuleContextDefault.

@Test
public void testBuildMuleContextDefault() {
    // Build
    DefaultMuleContextBuilder builder = new DefaultMuleContextBuilder(APP);
    MuleContext muleContext = builder.buildMuleContext();
    // Assert
    assertThat(muleContext, notNullValue());
    assertThat(muleContext.getConfiguration(), instanceOf(DefaultMuleConfiguration.class));
    assertThat(muleContext.getLifecycleManager(), instanceOf(MuleContextLifecycleManager.class));
    assertThat(muleContext.getNotificationManager(), instanceOf(ServerNotificationManager.class));
}
Also used : MuleContextLifecycleManager(org.mule.runtime.core.internal.lifecycle.MuleContextLifecycleManager) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultMuleConfiguration(org.mule.runtime.core.api.config.DefaultMuleConfiguration) ServerNotificationManager(org.mule.runtime.core.api.context.notification.ServerNotificationManager) Test(org.junit.Test)

Example 3 with MuleContext

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

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

the class DefaultMuleContextFactory method doCreateMuleContext.

private MuleContext doCreateMuleContext(MuleContextBuilder muleContextBuilder, ContextConfigurator configurator) throws InitialisationException, ConfigurationException {
    MuleContext muleContext = buildMuleContext(muleContextBuilder);
    listeners.forEach(l -> l.onCreation(muleContext));
    try {
        configurator.configure(muleContext);
        muleContext.initialise();
    } catch (ConfigurationException e) {
        if (muleContext != null && !muleContext.isDisposed()) {
            try {
                muleContext.dispose();
            } catch (Exception e1) {
                logger.warn("Can not dispose context. " + getMessage(e1));
                if (logger.isDebugEnabled()) {
                    logger.debug("Can not dispose context. " + getStackTrace(e1));
                }
            }
        }
        throw e;
    }
    return muleContext;
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException)

Example 5 with MuleContext

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

the class PolicyNextActionMessageProcessor method apply.

@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
    return from(publisher).doOnNext(coreEvent -> logExecuteNextEvent("Before execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId())).flatMap(event -> {
        Processor nextOperation = policyStateHandler.retrieveNextOperation(event.getContext().getCorrelationId());
        if (nextOperation == null) {
            return error(new MuleRuntimeException(createStaticMessage("There's no next operation configured for event context id " + event.getContext().getCorrelationId())));
        }
        popBeforeNextFlowFlowStackElement().accept(event);
        notificationHelper.notification(BEFORE_NEXT).accept(event);
        return from(processWithChildContext(event, nextOperation, ofNullable(getLocation()))).doOnSuccessOrError(notificationHelper.successOrErrorNotification(AFTER_NEXT).andThen((ev, t) -> pushAfterNextFlowStackElement().accept(event))).onErrorResume(MessagingException.class, t -> {
            PolicyStateId policyStateId = new PolicyStateId(event.getContext().getCorrelationId(), muleContext.getConfiguration().getId());
            policyStateHandler.getLatestState(policyStateId).ifPresent(latestStateEvent -> t.setProcessedEvent(policyEventConverter.createEvent((PrivilegedEvent) t.getEvent(), (PrivilegedEvent) latestStateEvent)));
            // Given we've used child context to ensure AFTER_NEXT notifications are fired at exactly the right time we need
            // to propagate the error to parent context manually.
            ((BaseEventContext) event.getContext()).error(resolveMessagingException(t.getFailingComponent(), muleContext).apply(t));
            return empty();
        }).doOnNext(coreEvent -> logExecuteNextEvent("After execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId()));
    });
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Processor(org.mule.runtime.core.api.processor.Processor) Function(java.util.function.Function) BEFORE_NEXT(org.mule.runtime.api.notification.PolicyNotification.BEFORE_NEXT) Inject(javax.inject.Inject) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) Component(org.mule.runtime.api.component.Component) Mono.from(reactor.core.publisher.Mono.from) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Mono.empty(reactor.core.publisher.Mono.empty) Mono.error(reactor.core.publisher.Mono.error) AFTER_NEXT(org.mule.runtime.api.notification.PolicyNotification.AFTER_NEXT) EventContext(org.mule.runtime.api.event.EventContext) MessagingExceptionResolver(org.mule.runtime.core.internal.util.MessagingExceptionResolver) PolicyStateId(org.mule.runtime.core.api.policy.PolicyStateId) PolicyStateHandler(org.mule.runtime.core.api.policy.PolicyStateHandler) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) 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) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) Consumer(java.util.function.Consumer) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) DefaultFlowCallStack(org.mule.runtime.core.internal.context.notification.DefaultFlowCallStack) FlowStackElement(org.mule.runtime.core.api.context.notification.FlowStackElement) Processor(org.mule.runtime.core.api.processor.Processor) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) PolicyStateId(org.mule.runtime.core.api.policy.PolicyStateId) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

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