Search in sources :

Example 6 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class ApplicationDeploymentTestCase method synchronizesDeploymentOnStart.

@Test
public void synchronizesDeploymentOnStart() throws Exception {
    addPackedAppFromBuilder(emptyAppFileBuilder);
    Thread deploymentServiceThread = new Thread(() -> {
        try {
            startDeployment();
        } catch (MuleException e) {
            throw new RuntimeException(e);
        }
    });
    final boolean[] lockedFromClient = new boolean[1];
    doAnswer(invocation -> {
        Thread deploymentClientThread = new Thread(() -> {
            ReentrantLock deploymentLock = deploymentService.getLock();
            try {
                try {
                    lockedFromClient[0] = deploymentLock.tryLock(1000, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                // Ignore
                }
            } finally {
                if (deploymentLock.isHeldByCurrentThread()) {
                    deploymentLock.unlock();
                }
            }
        });
        deploymentClientThread.start();
        deploymentClientThread.join();
        return null;
    }).when(applicationDeploymentListener).onDeploymentStart(emptyAppFileBuilder.getId());
    deploymentServiceThread.start();
    assertApplicationDeploymentSuccess(applicationDeploymentListener, emptyAppFileBuilder.getId());
    assertFalse("Able to lock deployment service during start", lockedFromClient[0]);
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 7 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class TransformerChainingTestCase method testIgnoreBadInputBreaksChainWithTransformationOrderValidInvalid.

@Test
public void testIgnoreBadInputBreaksChainWithTransformationOrderValidInvalid() throws Exception {
    AbstractTransformer invalidTransformer = (AbstractTransformer) this.getInvalidTransformer();
    assertNotNull(invalidTransformer);
    invalidTransformer.setIgnoreBadInput(false);
    AbstractTransformer validTransformer = (AbstractTransformer) this.getIncreaseByOneTransformer();
    assertNotNull(validTransformer);
    Message message = of(new Integer(0));
    Transformer messageTransformer = new TransformerChain(validTransformer, invalidTransformer);
    try {
        transformationService.applyTransformers(message, eventBuilder(muleContext).message(of(0)).build(), messageTransformer);
        fail("Transformer chain is expected to fail because of invalid transformer within chain.");
    } catch (MuleException tfe) {
        assertNotNull(tfe);
    }
}
Also used : Message(org.mule.runtime.api.message.Message) TransformerChain(org.mule.runtime.core.privileged.transformer.TransformerChain) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 8 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class ErrorBuilderTestCase method buildErrorFromMuleException.

@Test
public void buildErrorFromMuleException() {
    MuleException exception = new DefaultMuleException(new RuntimeException(EXCEPTION_MESSAGE));
    Error error = builder(exception).errorType(mockErrorType).build();
    assertThat(error.getCause(), is(exception));
    assertThat(error.getDescription(), containsString(EXCEPTION_MESSAGE));
    assertThat(error.getDetailedDescription(), containsString(EXCEPTION_MESSAGE));
    assertThat(error.getErrorType(), is(mockErrorType));
    assertThat(error.getChildErrors(), is(empty()));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) Error(org.mule.runtime.api.message.Error) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 9 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class FlowProcessingPhase method runPhase.

@Override
public void runPhase(final FlowProcessingPhaseTemplate flowProcessingPhaseTemplate, final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
    Runnable flowExecutionWork = () -> {
        try {
            FlowConstruct flowConstruct = registry.<FlowConstruct>lookupByName(messageProcessContext.getMessageSource().getRootContainerLocation().toString()).get();
            try {
                final AtomicReference exceptionThrownDuringFlowProcessing = new AtomicReference();
                TransactionalExecutionTemplate<CoreEvent> transactionTemplate = createTransactionalExecutionTemplate(muleContext, messageProcessContext.getTransactionConfig().orElse(new MuleTransactionConfig()));
                CoreEvent response = transactionTemplate.execute(() -> {
                    try {
                        Object message = flowProcessingPhaseTemplate.getOriginalMessage();
                        if (message == null) {
                            return null;
                        }
                        CoreEvent muleEvent = flowProcessingPhaseTemplate.getEvent();
                        muleEvent = flowProcessingPhaseTemplate.beforeRouteEvent(muleEvent);
                        muleEvent = flowProcessingPhaseTemplate.routeEvent(muleEvent);
                        muleEvent = flowProcessingPhaseTemplate.afterRouteEvent(muleEvent);
                        sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, muleEvent, flowProcessingPhaseTemplate);
                        return muleEvent;
                    } catch (Exception e) {
                        exceptionThrownDuringFlowProcessing.set(e);
                        throw e;
                    }
                });
                if (exceptionThrownDuringFlowProcessing.get() != null && !(exceptionThrownDuringFlowProcessing.get() instanceof ResponseDispatchException)) {
                    sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, response, flowProcessingPhaseTemplate);
                }
                flowProcessingPhaseTemplate.afterSuccessfulProcessingFlow(response);
            } catch (ResponseDispatchException e) {
                flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
            } catch (MessagingException e) {
                sendFailureResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, e, flowProcessingPhaseTemplate);
                flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
            }
            phaseResultNotifier.phaseSuccessfully();
        } catch (Exception e) {
            MuleException me = new DefaultMuleException(e);
            try {
                flowProcessingPhaseTemplate.afterFailureProcessingFlow(me);
            } catch (MuleException e1) {
                logger.warn("Failure during exception processing in flow template: " + e.getMessage());
                if (logger.isDebugEnabled()) {
                    logger.debug("Failure during exception processing in flow template: ", e);
                }
            }
            phaseResultNotifier.phaseFailure(e);
        }
    };
    if (messageProcessContext.supportsAsynchronousProcessing()) {
        try {
            messageProcessContext.getFlowExecutionExecutor().execute(flowExecutionWork);
        } catch (SchedulerBusyException e) {
            phaseResultNotifier.phaseFailure(e);
        }
    } else {
        flowExecutionWork.run();
    }
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) AtomicReference(java.util.concurrent.atomic.AtomicReference) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SchedulerBusyException(org.mule.runtime.api.scheduler.SchedulerBusyException) ResponseDispatchException(org.mule.runtime.core.privileged.exception.ResponseDispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) TransactionalExecutionTemplate.createTransactionalExecutionTemplate(org.mule.runtime.core.api.execution.TransactionalExecutionTemplate.createTransactionalExecutionTemplate) TransactionalExecutionTemplate(org.mule.runtime.core.api.execution.TransactionalExecutionTemplate) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ResponseDispatchException(org.mule.runtime.core.privileged.exception.ResponseDispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) SchedulerBusyException(org.mule.runtime.api.scheduler.SchedulerBusyException)

Example 10 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class TypeBasedTransformerResolver method resolve.

public Transformer resolve(DataType source, DataType result) throws ResolverException {
    Transformer transformer = exactTransformerCache.get(source.toString() + result.toString());
    if (transformer != null) {
        return transformer;
    }
    MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
    List<Transformer> trans = registry.lookupTransformers(source, result);
    Transformer compositeTransformer = graphTransformerResolver.resolve(source, result);
    if (compositeTransformer != null) {
        // Needs to create a new list because the lookup returns a cached instance
        trans = new LinkedList<>(trans);
        trans.add(compositeTransformer);
    }
    transformer = getNearestTransformerMatch(trans, source.getType(), result.getType());
    // If an exact mach is not found, we have a 'second pass' transformer that can be used to converting to String or
    // byte[]
    Transformer secondPass;
    if (transformer == null) {
        // using Object.class and then convert to String or byte[] using the second pass transformer
        if (String.class.equals(result.getType())) {
            secondPass = objectToString;
        } else if (byte[].class.equals(result.getType())) {
            secondPass = objectToByteArray;
        } else {
            return null;
        }
        // Perform a more general search
        trans = registry.lookupTransformers(source, DataType.OBJECT);
        transformer = getNearestTransformerMatch(trans, source.getType(), result.getType());
        if (transformer != null) {
            transformer = new TransformerChain(transformer, secondPass);
            try {
                registry.registerTransformer(transformer);
            } catch (MuleException e) {
                throw new ResolverException(e.getI18nMessage(), e);
            }
        }
    }
    if (transformer != null) {
        exactTransformerCache.put(source.toString() + result.toString(), transformer);
    }
    return transformer;
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) ResolverException(org.mule.runtime.core.internal.transformer.ResolverException) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) TransformerChain(org.mule.runtime.core.privileged.transformer.TransformerChain) 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