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));
}
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));
}
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);
}
}
});
}
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;
}
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()));
});
}
Aggregations