use of org.mule.runtime.core.internal.util.MessagingExceptionResolver in project mule by mulesoft.
the class MessagingExceptionResolverTestCase method resolveCorrectConnectionException.
@Test
public void resolveCorrectConnectionException() {
ErrorType expected = ErrorTypeBuilder.builder().namespace("NS").identifier("CONNECTION").parentErrorType(CONNECTION).build();
ErrorTypeLocator locator = ErrorTypeLocator.builder(repository).addComponentExceptionMapper(ci, ExceptionMapper.builder().addExceptionMapping(ConnectionException.class, expected).build()).defaultExceptionMapper(ExceptionMapper.builder().build()).defaultError(UNKNOWN).build();
when(((PrivilegedMuleContext) context).getErrorTypeLocator()).thenReturn(locator);
MessagingException me = newMessagingException(CONNECTION_EXCEPTION, event, processor);
MessagingExceptionResolver anotherResolver = new MessagingExceptionResolver(new TestProcessor());
MessagingException resolved = anotherResolver.resolve(me, context);
assertExceptionErrorType(resolved, expected);
assertExceptionMessage(resolved.getMessage(), "CONNECTION PROBLEM");
}
use of org.mule.runtime.core.internal.util.MessagingExceptionResolver in project mule by mulesoft.
the class ReactiveInterceptorAdapter method createMessagingException.
protected MessagingException createMessagingException(CoreEvent event, Throwable cause, Component processor) {
MessagingExceptionResolver exceptionResolver = new MessagingExceptionResolver(processor);
MessagingException me = new MessagingException(event, cause, processor);
return exceptionResolver.resolve(me, muleContext);
}
use of org.mule.runtime.core.internal.util.MessagingExceptionResolver in project mule by mulesoft.
the class ModuleFlowProcessingPhase method runPhase.
@Override
public void runPhase(final ModuleFlowProcessingPhaseTemplate template, final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
try {
final MessageSource messageSource = messageProcessContext.getMessageSource();
final FlowConstruct flowConstruct = (FlowConstruct) componentLocator.find(messageSource.getRootContainerLocation()).get();
final ComponentLocation sourceLocation = messageSource.getLocation();
final Consumer<Either<MessagingException, CoreEvent>> terminateConsumer = getTerminateConsumer(messageSource, template);
final CompletableFuture<Void> responseCompletion = new CompletableFuture<>();
final CoreEvent templateEvent = createEvent(template, sourceLocation, responseCompletion, flowConstruct);
try {
FlowProcessor flowExecutionProcessor = new FlowProcessor(template, flowConstruct.getExceptionListener(), templateEvent);
flowExecutionProcessor.setAnnotations(flowConstruct.getAnnotations());
final SourcePolicy policy = policyManager.createSourcePolicyInstance(messageSource, templateEvent, flowExecutionProcessor, template);
final PhaseContext phaseContext = new PhaseContext(template, messageProcessContext, phaseResultNotifier, terminateConsumer);
just(templateEvent).doOnNext(onMessageReceived(template, messageProcessContext, flowConstruct)).flatMap(request -> from(policy.process(request))).flatMap(policyResult -> policyResult.reduce(policyFailure(phaseContext, flowConstruct, messageSource), policySuccess(phaseContext, flowConstruct, messageSource))).doOnSuccess(aVoid -> phaseResultNotifier.phaseSuccessfully()).doOnError(onFailure(flowConstruct, messageSource, phaseResultNotifier, terminateConsumer)).doAfterTerminate(() -> responseCompletion.complete(null)).subscribe();
} catch (Exception e) {
from(template.sendFailureResponseToClient(new MessagingExceptionResolver(messageProcessContext.getMessageSource()).resolve(new MessagingException(templateEvent, e), muleContext), template.getFailedExecutionResponseParametersFunction().apply(templateEvent))).doOnTerminate(() -> phaseResultNotifier.phaseFailure(e)).subscribe();
}
} catch (Exception t) {
phaseResultNotifier.phaseFailure(t);
}
}
use of org.mule.runtime.core.internal.util.MessagingExceptionResolver in project mule by mulesoft.
the class ErrorHandler method apply.
@Override
public Publisher<CoreEvent> apply(Exception exception) {
if (exception instanceof MessagingException) {
CoreEvent event = addExceptionPayload(exception, ((MessagingException) exception).getEvent());
((MessagingException) exception).setProcessedEvent(event);
try {
for (MessagingExceptionHandlerAcceptor exceptionListener : exceptionListeners) {
if (exceptionListener.accept(event)) {
return exceptionListener.apply(exception);
}
}
throw new MuleRuntimeException(createStaticMessage(MUST_ACCEPT_ANY_EVENT_MESSAGE));
} catch (Exception e) {
return error(new MessagingExceptionResolver(this).resolve(new MessagingException(event, e, this), muleContext));
}
} else {
// This should never occur since all exceptions at this point are ME
return error(exception);
}
}
use of org.mule.runtime.core.internal.util.MessagingExceptionResolver in project mule by mulesoft.
the class IdempotentRedeliveryPolicy method createMessagingException.
private MessagingException createMessagingException(CoreEvent event, Throwable cause, Component processor) {
MessagingExceptionResolver exceptionResolver = new MessagingExceptionResolver(processor);
MessagingException me = new MessagingException(event, cause, processor);
return exceptionResolver.resolve(me, muleContext);
}
Aggregations