use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class ModuleFlowProcessingPhase method runPhase.
@Override
public void runPhase(final ModuleFlowProcessingPhaseTemplate template, final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
try {
final MessageSource messageSource = messageProcessContext.getMessageSource();
final FlowConstruct flowConstruct = (FlowConstruct) componentLocator.find(messageSource.getRootContainerLocation()).get();
final ComponentLocation sourceLocation = messageSource.getLocation();
final Consumer<Either<MessagingException, CoreEvent>> terminateConsumer = getTerminateConsumer(messageSource, template);
final CompletableFuture<Void> responseCompletion = new CompletableFuture<>();
final CoreEvent templateEvent = createEvent(template, sourceLocation, responseCompletion, flowConstruct);
try {
FlowProcessor flowExecutionProcessor = new FlowProcessor(template, flowConstruct.getExceptionListener(), templateEvent);
flowExecutionProcessor.setAnnotations(flowConstruct.getAnnotations());
final SourcePolicy policy = policyManager.createSourcePolicyInstance(messageSource, templateEvent, flowExecutionProcessor, template);
final PhaseContext phaseContext = new PhaseContext(template, messageProcessContext, phaseResultNotifier, terminateConsumer);
just(templateEvent).doOnNext(onMessageReceived(template, messageProcessContext, flowConstruct)).flatMap(request -> from(policy.process(request))).flatMap(policyResult -> policyResult.reduce(policyFailure(phaseContext, flowConstruct, messageSource), policySuccess(phaseContext, flowConstruct, messageSource))).doOnSuccess(aVoid -> phaseResultNotifier.phaseSuccessfully()).doOnError(onFailure(flowConstruct, messageSource, phaseResultNotifier, terminateConsumer)).doAfterTerminate(() -> responseCompletion.complete(null)).subscribe();
} catch (Exception e) {
from(template.sendFailureResponseToClient(new MessagingExceptionResolver(messageProcessContext.getMessageSource()).resolve(new MessagingException(templateEvent, e), muleContext), template.getFailedExecutionResponseParametersFunction().apply(templateEvent))).doOnTerminate(() -> phaseResultNotifier.phaseFailure(e)).subscribe();
}
} catch (Exception t) {
phaseResultNotifier.phaseFailure(t);
}
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class OperationMessageProcessorTestCase method operationWithoutExpressionInTargetValueParameter.
@Test
public void operationWithoutExpressionInTargetValueParameter() throws Exception {
String flowName = "flowName";
expectedException.expect(IllegalOperationException.class);
expectedException.expectMessage(format(INVALID_TARGET_MESSAGE, flowName, operationModel.getName(), "something that is not an expression", TARGET_VALUE_PARAMETER_NAME));
target = TARGET_VAR;
targetValue = TARGET_VAR;
messageProcessor = createOperationMessageProcessor();
when(context.getRegistry().lookupObject(OBJECT_EXPRESSION_LANGUAGE)).thenReturn(new MVELExpressionLanguage(context));
when(context.getRegistry().lookupObject(DefaultExpressionLanguageFactoryService.class)).thenReturn(new WeaveDefaultExpressionLanguageFactoryService());
doReturn(new DefaultExpressionManager()).when(context).getExpressionManager();
FlowConstruct flowConstruct = mock(FlowConstruct.class);
when(flowConstruct.getName()).thenReturn(flowName);
messageProcessor.setMuleContext(context);
messageProcessor.initialise();
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class OperationMessageProcessorTestCase method operationWithExpressionInTargetParameter.
@Test
public void operationWithExpressionInTargetParameter() throws Exception {
String flowName = FLOW_NAME;
expectedException.expect(IllegalOperationException.class);
expectedException.expectMessage(format(INVALID_TARGET_MESSAGE, flowName, operationModel.getName(), "an expression", TARGET_PARAMETER_NAME));
target = "#[mel:someExpression]";
messageProcessor = createOperationMessageProcessor();
registerIntoMockContext(context, OBJECT_EXPRESSION_LANGUAGE, new MVELExpressionLanguage(context));
registerIntoMockContext(context, DefaultExpressionLanguageFactoryService.class, new WeaveDefaultExpressionLanguageFactoryService());
doReturn(new DefaultExpressionManager()).when(context).getExpressionManager();
FlowConstruct flowConstruct = mock(FlowConstruct.class);
when(flowConstruct.getName()).thenReturn(flowName);
messageProcessor.setMuleContext(context);
messageProcessor.initialise();
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method setupMVEL.
@Before
public void setupMVEL() throws InitialisationException {
mvel = new MVELExpressionLanguage(muleContext);
mvel.initialise();
flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class));
when(flowConstruct.getName()).thenReturn("myFlow");
final DefaultComponentLocation location = fromSingleComponent("myFlow");
when(((Component) flowConstruct).getAnnotation(LOCATION_KEY)).thenReturn(location);
when(((Component) flowConstruct).getLocation()).thenReturn(location);
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class AbstractFlowConstructTestCase method testRegisterUnregister.
@Test
public void testRegisterUnregister() throws MuleException, Exception {
FlowConstruct construct = getFlowConstruct();
((MuleContextWithRegistries) muleContext).getRegistry().registerFlowConstruct(construct);
assertNotNull(((MuleContextWithRegistries) muleContext).getRegistry().lookupFlowConstruct(construct.getName()));
}
Aggregations