Search in sources :

Example 1 with SingleErrorTypeMatcher

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

the class MessagingExceptionResolver method findRoot.

private Optional<Pair<Throwable, ErrorType>> findRoot(Component obj, MessagingException me, ErrorTypeLocator locator) {
    List<Pair<Throwable, ErrorType>> errors = collectErrors(obj, me, locator);
    if (errors.isEmpty()) {
        return collectCritical(obj, me, locator).stream().findFirst();
    }
    // We look if there is a more specific error in the chain that matches with the root error (is child or has the same error)
    SingleErrorTypeMatcher matcher = new SingleErrorTypeMatcher(errors.get(0).getSecond());
    Reference<Pair<Throwable, ErrorType>> result = new Reference<>();
    errors.forEach(p -> {
        if (matcher.match(p.getSecond())) {
            result.set(p);
        }
    });
    return Optional.ofNullable(result.get());
}
Also used : Reference(org.mule.runtime.api.util.Reference) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Pair(org.mule.runtime.api.util.Pair)

Example 2 with SingleErrorTypeMatcher

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

the class TemplateOnErrorHandler method createErrorType.

public static ErrorTypeMatcher createErrorType(ErrorTypeRepository errorTypeRepository, String errorTypeNames) {
    if (errorTypeNames == null) {
        return null;
    }
    String[] errorTypeIdentifiers = errorTypeNames.split(",");
    List<ErrorTypeMatcher> matchers = stream(errorTypeIdentifiers).map((identifier) -> {
        String parsedIdentifier = identifier.trim();
        return new SingleErrorTypeMatcher(errorTypeRepository.lookupErrorType(buildFromStringRepresentation(parsedIdentifier)).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not find ErrorType for the given identifier: '%s'", parsedIdentifier))));
    }).collect(toList());
    return new DisjunctiveErrorTypeMatcher(matchers);
}
Also used : ReplyToPropertyRequestReplyReplier(org.mule.runtime.core.privileged.routing.requestreply.ReplyToPropertyRequestReplyReplier) Optional.empty(java.util.Optional.empty) MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) ComponentIdentifier.buildFromStringRepresentation(org.mule.runtime.api.component.ComponentIdentifier.buildFromStringRepresentation) Exceptions.unwrap(org.mule.runtime.core.api.rx.Exceptions.unwrap) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) Processor(org.mule.runtime.core.api.processor.Processor) Function(java.util.function.Function) PROCESS_START(org.mule.runtime.api.notification.ErrorHandlerNotification.PROCESS_START) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) ErrorHandlerNotification(org.mule.runtime.api.notification.ErrorHandlerNotification) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DefaultExceptionPayload(org.mule.runtime.core.internal.message.DefaultExceptionPayload) ComponentAnnotations.updateRootContainerName(org.mule.runtime.core.internal.component.ComponentAnnotations.updateRootContainerName) 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) NullExceptionHandler(org.mule.runtime.core.api.exception.NullExceptionHandler) EnrichedNotificationInfo.createInfo(org.mule.runtime.api.notification.EnrichedNotificationInfo.createInfo) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) NoExtend(org.mule.api.annotation.NoExtend) TransactionCoordination(org.mule.runtime.core.api.transaction.TransactionCoordination) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) PROCESS_END(org.mule.runtime.api.notification.ErrorHandlerNotification.PROCESS_END) Optional(java.util.Optional) TRUE(java.lang.Boolean.TRUE) Arrays.stream(java.util.Arrays.stream) MessageProcessors.getProcessingStrategy(org.mule.runtime.core.privileged.processor.MessageProcessors.getProcessingStrategy) DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)

Example 3 with SingleErrorTypeMatcher

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

the class SingleErrorTypeMatcherTestCase method matchChild.

@Test
public void matchChild() {
    ComponentIdentifier customTransformerIdentifier = ComponentIdentifier.builder().name("custom").namespace(CORE_NAMESPACE_NAME).build();
    ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
    ErrorType customTransformerErrorType = errorTypeRepository.addErrorType(customTransformerIdentifier, transformationErrorType);
    ErrorTypeMatcher transformationMatcher = new SingleErrorTypeMatcher(transformationErrorType);
    assertThat(transformationMatcher.match(customTransformerErrorType), is(true));
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorType(org.mule.runtime.api.message.ErrorType) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Test(org.junit.Test)

Example 4 with SingleErrorTypeMatcher

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

the class SingleErrorTypeMatcherTestCase method matchEqual.

@Test
public void matchEqual() {
    ErrorTypeMatcher transformationMatcher = new SingleErrorTypeMatcher(transformationErrorType);
    assertThat(transformationMatcher.match(transformationErrorType), is(true));
}
Also used : ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Test(org.junit.Test)

Example 5 with SingleErrorTypeMatcher

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

the class SingleErrorTypeMatcherTestCase method anyMatchsAll.

@Test
public void anyMatchsAll() {
    ErrorType mockErrorType = mock(ErrorType.class);
    when(mockErrorType.getParentErrorType()).thenReturn(transformationErrorType);
    ErrorTypeMatcher anyMatcher = new SingleErrorTypeMatcher(anyErrorType);
    assertThat(anyMatcher.match(anyErrorType), is(true));
    assertThat(anyMatcher.match(transformationErrorType), is(true));
    assertThat(anyMatcher.match(expressionErrorType), is(true));
    assertThat(anyMatcher.match(mockErrorType), is(true));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Test(org.junit.Test)

Aggregations

SingleErrorTypeMatcher (org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)10 ErrorTypeMatcher (org.mule.runtime.core.api.exception.ErrorTypeMatcher)8 Test (org.junit.Test)5 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)4 ErrorType (org.mule.runtime.api.message.ErrorType)4 List (java.util.List)2 Optional (java.util.Optional)2 Consumer (java.util.function.Consumer)2 Collectors.toList (java.util.stream.Collectors.toList)2 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)2 ComponentIdentifier.buildFromStringRepresentation (org.mule.runtime.api.component.ComponentIdentifier.buildFromStringRepresentation)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 TRUE (java.lang.Boolean.TRUE)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Arrays.stream (java.util.Arrays.stream)1 Collections.singletonList (java.util.Collections.singletonList)1