use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.
the class MessagingExceptionTestCase method causedByWithMuleCauseWithMuleCause.
@Test
public void causedByWithMuleCauseWithMuleCause() {
DefaultMuleException causeCauseException = new DefaultMuleException("");
DefaultMuleException causeException = new DefaultMuleException(causeCauseException);
MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, causeException);
assertThat(exception.causedBy(DefaultMuleException.class), is(true));
assertThat(exception.causedBy(MessagingException.class), is(true));
}
use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.
the class MessagingExceptionTestCase method getCauseExceptionWithNonMuleCauseWithNonMuleCause.
@Test
public void getCauseExceptionWithNonMuleCauseWithNonMuleCause() {
ConnectException causeCauseException = new ConnectException();
IOException causeException = new IOException(causeCauseException);
MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, causeException);
assertThat(exception.getRootCause(), is(causeCauseException));
}
use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.
the class IdempotentRedeliveryPolicyTestCase method setUpTest.
@Before
@SuppressWarnings("rawtypes")
public void setUpTest() throws MuleException {
event = spy(testEvent());
when(mockFailingMessageProcessor.apply(any(Publisher.class))).thenAnswer(invocation -> {
MessagingException me = mock(MessagingException.class, RETURNS_DEEP_STUBS.get());
CoreEvent event = mock(CoreEvent.class);
when(event.getError()).thenReturn(of(mock(Error.class)));
when(me.getEvent()).thenReturn(event);
return error(me).doOnError(e -> count.getAndIncrement());
});
when(mockWaitingMessageProcessor.apply(any(Publisher.class))).thenAnswer(invocationOnMock -> {
Mono<CoreEvent> mono = from(invocationOnMock.getArgumentAt(0, Publisher.class));
return mono.doOnNext(checkedConsumer(event1 -> {
waitingMessageProcessorExecutionLatch.countDown();
waitLatch.await(2000, MILLISECONDS);
})).transform(mockFailingMessageProcessor);
});
MuleLockFactory muleLockFactory = new MuleLockFactory();
muleLockFactory.setLockProvider(new SingleServerLockProvider());
muleLockFactory.initialise();
when(mockMuleContext.getConfiguration().getDefaultEncoding()).thenReturn(UTF_8.name());
final InMemoryObjectStore inMemoryObjectStore = new InMemoryObjectStore();
when(mockObjectStoreManager.getObjectStore(anyString())).thenReturn(inMemoryObjectStore);
when(mockObjectStoreManager.createObjectStore(any(), any())).thenReturn(inMemoryObjectStore);
when(event.getMessage()).thenReturn(message);
IdempotentRedeliveryPolicyTestCase.serializer = SerializationTestUtils.getJavaSerializerWithMockContext();
irp.setExpressionManager(expressionManager);
irp.setMaxRedeliveryCount(MAX_REDELIVERY_COUNT);
irp.setUseSecureHash(true);
irp.setMuleContext(mockMuleContext);
irp.setAnnotations(singletonMap(LOCATION_KEY, TEST_CONNECTOR_LOCATION));
irp.setListener(mockFailingMessageProcessor);
irp.setLockFactory(muleLockFactory);
irp.setObjectStoreManager(mockObjectStoreManager);
}
use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.
the class InvokerMessageProcessor method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
CoreEvent resultEvent = event;
Object[] args = evaluateArguments(event, arguments);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Invoking '%s' of '%s' with arguments: '%s'", method.getName(), object, args));
}
try {
Object result = method.invoke(object, args);
if (!method.getReturnType().equals(void.class)) {
resultEvent = createResultEvent(event, result);
}
} catch (Exception e) {
throw new MessagingException(failedToInvoke(object.toString()), event, e, this);
}
return resultEvent;
}
use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.
the class DefaultPolicyManager method createSourcePolicyInstance.
@Override
public SourcePolicy createSourcePolicyInstance(Component source, CoreEvent sourceEvent, Processor flowExecutionProcessor, MessageSourceResponseParametersProcessor messageSourceResponseParametersProcessor) {
PolicyPointcutParameters sourcePointcutParameters = policyPointcutParametersManager.createSourcePointcutParameters(source, sourceEvent);
List<Policy> parameterizedPolicies = policyProvider.findSourceParameterizedPolicies(sourcePointcutParameters);
if (parameterizedPolicies.isEmpty()) {
return event -> from(process(event, flowExecutionProcessor)).defaultIfEmpty(CoreEvent.builder(sourceEvent).message(of(null)).build()).<Either<SourcePolicyFailureResult, SourcePolicySuccessResult>>map(flowExecutionResult -> right(new SourcePolicySuccessResult(flowExecutionResult, () -> messageSourceResponseParametersProcessor.getSuccessfulExecutionResponseParametersFunction().apply(flowExecutionResult), messageSourceResponseParametersProcessor))).onErrorResume(Exception.class, e -> {
MessagingException messagingException = e instanceof MessagingException ? (MessagingException) e : new MessagingException(event, e, (Component) flowExecutionProcessor);
return just(Either.left(new SourcePolicyFailureResult(messagingException, () -> messageSourceResponseParametersProcessor.getFailedExecutionResponseParametersFunction().apply(messagingException.getEvent()))));
});
}
return new CompositeSourcePolicy(parameterizedPolicies, lookupSourceParametersTransformer(source.getLocation().getComponentIdentifier().getIdentifier()), sourcePolicyProcessorFactory, flowExecutionProcessor, messageSourceResponseParametersProcessor);
}
Aggregations