use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class NestedProcessorValueResolverTestCase method yieldsNestedProcessor.
@Test
public void yieldsNestedProcessor() throws Exception {
ProcessorChainValueResolver resolver = new ProcessorChainValueResolver(muleContext, messageProcessor);
final CoreEvent event = testEvent();
Chain nestedProcessor = resolver.resolve(ValueResolvingContext.from(event));
nestedProcessor.process(result -> {
assertThat(result.getOutput(), is(TEST_PAYLOAD));
ArgumentCaptor<CoreEvent> captor = ArgumentCaptor.forClass(CoreEvent.class);
try {
verify(messageProcessor).process(captor.capture());
} catch (MuleException e) {
throw new RuntimeException(e);
}
CoreEvent capturedEvent = captor.getValue();
assertThat(capturedEvent, is(event));
}, (e, r) -> fail(e.getMessage()));
}
use of org.mule.runtime.api.exception.MuleException 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;
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class BasicRuntimeServicesConfigurationBuilder method doConfigure.
@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
new SpiServiceRegistry().lookupProviders(Service.class, BasicRuntimeServicesConfigurationBuilder.class.getClassLoader()).forEach(service -> {
try {
startIfNeeded(service);
registerObject(muleContext, service.getName(), service);
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
});
DefaultExpressionLanguageFactoryService weaveExpressionExecutor = new WeaveDefaultExpressionLanguageFactoryService();
registerObject(muleContext, weaveExpressionExecutor.getName(), weaveExpressionExecutor);
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class ReconectionSource method onStart.
@Override
public void onStart(SourceCallback<ReconnectableConnection, Void> sourceCallback) throws MuleException {
ReconnectableConnection connection;
try {
connection = connectionProvider.connect();
scheduler = schedulerService.ioScheduler();
scheduler.execute(() -> {
boolean shouldFinish = false;
while (!shouldFinish) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
shouldFinish = true;
}
if (ReconnectableConnectionProvider.fail) {
sourceCallback.onConnectionException(new ConnectionException(new RuntimeException(), connection));
shouldFinish = true;
} else {
sourceCallback.handle(Result.<ReconnectableConnection, Void>builder().output(connection).build());
}
}
});
} catch (Exception e) {
sourceCallback.onConnectionException(new ConnectionException(e));
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class TransactionalSource method onStart.
@Override
public void onStart(SourceCallback<TestTransactionalConnection, Object> sourceCallback) throws MuleException {
connectExecutor = newFixedThreadPool(1);
connectExecutor.execute(() -> {
SourceCallbackContext ctx = sourceCallback.createContext();
try {
TestTransactionalConnection connection = connectionProvider.connect();
boolean isXa = false;
if (connection instanceof XATransactionalConnection) {
isXa = true;
xaResource = (DummyXaResource) ((XATransactionalConnection) connection).getXAResource();
}
ctx.addVariable(IS_XA, isXa);
ctx.bindConnection(connection);
sourceCallback.handle(Result.<TestTransactionalConnection, Object>builder().output(connection).build(), ctx);
} catch (ConnectionException e) {
sourceCallback.onConnectionException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
Aggregations