Search in sources :

Example 26 with MuleException

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()));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Chain(org.mule.runtime.extension.api.runtime.route.Chain) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 27 with MuleException

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;
}
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 28 with MuleException

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);
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) Service(org.mule.runtime.api.service.Service) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) MuleException(org.mule.runtime.api.exception.MuleException)

Example 29 with MuleException

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));
    }
}
Also used : ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 30 with MuleException

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);
        }
    });
}
Also used : SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext) TestTransactionalConnection(org.mule.test.transactional.connection.TestTransactionalConnection) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) TransactionException(org.mule.runtime.api.tx.TransactionException) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)68 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)21 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Test (org.junit.Test)15 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)14 Processor (org.mule.runtime.core.api.processor.Processor)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 Logger (org.slf4j.Logger)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)6 Map (java.util.Map)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleContext (org.mule.runtime.core.api.MuleContext)5 LifecycleUtils.stopIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded)5 Thread.currentThread (java.lang.Thread.currentThread)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Startable (org.mule.runtime.api.lifecycle.Startable)4