Search in sources :

Example 1 with ErrorTypeRepository

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

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

the class AbstractErrorTypeMatcherTestCase method setUp.

@Before
public void setUp() {
    ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
    anyErrorType = errorTypeRepository.getAnyErrorType();
    ComponentIdentifier transformationIdentifier = ComponentIdentifier.builder().name(TRANSFORMATION_ERROR_IDENTIFIER).namespace(CORE_NAMESPACE_NAME).build();
    transformationErrorType = errorTypeRepository.lookupErrorType(transformationIdentifier).get();
    ComponentIdentifier expressionIdentifier = ComponentIdentifier.builder().name(EXPRESSION_ERROR_IDENTIFIER).namespace(CORE_NAMESPACE_NAME).build();
    expressionErrorType = errorTypeRepository.lookupErrorType(expressionIdentifier).get();
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) Before(org.junit.Before)

Example 3 with ErrorTypeRepository

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

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

the class ModuleFlowProcessingPhase method initialise.

@Override
public void initialise() throws InitialisationException {
    final ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
    componentLocator = muleContext.getConfigurationComponentLocator();
    sourceResponseGenerateErrorType = errorTypeRepository.getErrorType(SOURCE_RESPONSE_GENERATE).get();
    sourceResponseSendErrorType = errorTypeRepository.getErrorType(SOURCE_RESPONSE_SEND).get();
    sourceErrorResponseGenerateErrorType = errorTypeRepository.getErrorType(SOURCE_ERROR_RESPONSE_GENERATE).get();
    sourceErrorResponseSendErrorType = errorTypeRepository.getErrorType(SOURCE_ERROR_RESPONSE_SEND).get();
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository)

Example 5 with ErrorTypeRepository

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

the class ExtensionErrorsRegistrantTestCase method operationTriesToAddInternalErrorType.

@Test
public void operationTriesToAddInternalErrorType() {
    ErrorTypeRepository repository = mock(ErrorTypeRepository.class);
    when(repository.getErrorType(any())).then((e) -> typeRepository.getErrorType(((ComponentIdentifier) e.getArguments()[0])));
    ErrorModel internalRepeatedError = ErrorModelBuilder.newError(SOURCE_RESPONSE_GENERATE).build();
    when(operationWithError.getErrorModels()).thenReturn(singleton(internalRepeatedError));
    when(extensionModel.getOperationModels()).thenReturn(singletonList(operationWithError));
    when(extensionModel.getErrorModels()).thenReturn(singleton(internalRepeatedError));
    ErrorTypeLocator mockTypeLocator = mock(ErrorTypeLocator.class);
    errorsRegistrant = new ExtensionErrorsRegistrant(typeRepository, mockTypeLocator);
    errorsRegistrant.registerErrors(extensionModel);
    verify(repository, times(0)).addErrorType(any(), any());
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)11 ErrorType (org.mule.runtime.api.message.ErrorType)4 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)3 SingleErrorTypeMatcher (org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ConfigurationComponentLocator (org.mule.runtime.api.component.location.ConfigurationComponentLocator)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 ErrorTypeMatcher (org.mule.runtime.core.api.exception.ErrorTypeMatcher)2 TRUE (java.lang.Boolean.TRUE)1 ArrayList (java.util.ArrayList)1 Arrays.stream (java.util.Arrays.stream)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1