Search in sources :

Example 1 with ErrorTypeMatcher

use of org.mule.runtime.core.api.exception.ErrorTypeMatcher 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 2 with ErrorTypeMatcher

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

the class DisjunctiveErrorTypeMatcherTestCase method anyPresenceMatchAll.

@Test
public void anyPresenceMatchAll() {
    ErrorTypeMatcher matcherWithAny = createMatcher(anyErrorType, transformationErrorType);
    assertThat(matcherWithAny.match(anyErrorType), is(true));
    assertThat(matcherWithAny.match(transformationErrorType), is(true));
    assertThat(matcherWithAny.match(expressionErrorType), is(true));
}
Also used : DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Test(org.junit.Test)

Example 3 with ErrorTypeMatcher

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

the class DisjunctiveErrorTypeMatcherTestCase method noMatch.

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

Example 4 with ErrorTypeMatcher

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

the class DisjunctiveErrorTypeMatcherTestCase method oneMatch.

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

Example 5 with ErrorTypeMatcher

use of org.mule.runtime.core.api.exception.ErrorTypeMatcher 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)

Aggregations

ErrorTypeMatcher (org.mule.runtime.core.api.exception.ErrorTypeMatcher)12 SingleErrorTypeMatcher (org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)12 Test (org.junit.Test)9 ErrorType (org.mule.runtime.api.message.ErrorType)6 DisjunctiveErrorTypeMatcher (org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher)4 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)3 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 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