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