use of org.mule.runtime.api.exception.ErrorTypeRepository in project mule by mulesoft.
the class ThrowProcessor method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
if (count == -1 || count-- > 0) {
try {
Throwable instantiatedException = exception.newInstance();
if (error != null) {
ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
ErrorType errorType = errorTypeRepository.lookupErrorType(buildFromStringRepresentation(error)).orElseThrow(() -> new DefaultMuleException(format("Could not find error: '%s'", error)));
throw new TypedException(instantiatedException, errorType);
} else {
checkArgument(instantiatedException instanceof TypedException, EXCEPTION_ERROR);
throw (TypedException) instantiatedException;
}
} catch (InstantiationException | IllegalAccessException e) {
throw new DefaultMuleException(format("Failed to instantiate exception class '%s'", exception.getSimpleName()));
}
} else {
return event;
}
}
use of org.mule.runtime.api.exception.ErrorTypeRepository in project mule by mulesoft.
the class MuleContextUtils method mockContextWithServices.
/**
* Creates and configures a mock {@link MuleContext} to return testing services implementations.
*
* @return the created {@code muleContext}.
*/
public static MuleContextWithRegistries mockContextWithServices() {
final MuleContextWithRegistries muleContext = mockMuleContext();
SchedulerService schedulerService = spy(new SimpleUnitTestSupportSchedulerService());
when(muleContext.getSchedulerService()).thenReturn(schedulerService);
ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class);
when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository);
when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class)));
final MuleRegistry registry = muleContext.getRegistry();
NotificationListenerRegistry notificationListenerRegistry = mock(NotificationListenerRegistry.class);
ConfigurationProperties configProps = mock(ConfigurationProperties.class);
when(configProps.resolveBooleanProperty(any())).thenReturn(empty());
ConfigurationComponentLocator configurationComponentLocator = mock(ConfigurationComponentLocator.class);
when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty());
when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
try {
when(registry.lookupObject(NotificationListenerRegistry.class)).thenReturn(notificationListenerRegistry);
Map<Class, Object> injectableObjects = new HashMap<>();
injectableObjects.put(MuleContext.class, muleContext);
injectableObjects.put(SchedulerService.class, schedulerService);
injectableObjects.put(ErrorTypeRepository.class, errorTypeRepository);
injectableObjects.put(ExtendedExpressionManager.class, muleContext.getExpressionManager());
injectableObjects.put(StreamingManager.class, muleContext.getRegistry().lookupObject(StreamingManager.class));
injectableObjects.put(ObjectStoreManager.class, muleContext.getRegistry().lookupObject(OBJECT_STORE_MANAGER));
injectableObjects.put(NotificationDispatcher.class, muleContext.getRegistry().lookupObject(NotificationDispatcher.class));
injectableObjects.put(NotificationListenerRegistry.class, notificationListenerRegistry);
injectableObjects.put(ConfigurationComponentLocator.class, configurationComponentLocator);
injectableObjects.put(ConfigurationProperties.class, configProps);
// Ensure injection of consistent mock objects
when(muleContext.getInjector()).thenReturn(new MocksInjector(injectableObjects));
} catch (RegistrationException e1) {
throw new MuleRuntimeException(e1);
}
return muleContext;
}
use of org.mule.runtime.api.exception.ErrorTypeRepository in project mule by mulesoft.
the class ErrorTypeRepositoryFactory method createDefaultErrorTypeRepository.
/**
* Creates the default {@link ErrorTypeRepository} to use in mule.
* <p>
* The {@link ErrorTypeRepository} gets populated with the default mappings between common core exceptions and core error types.
*
* @return a new {@link ErrorTypeRepository}.
*/
public static ErrorTypeRepository createDefaultErrorTypeRepository() {
ErrorTypeRepository errorTypeRepository = new DefaultErrorTypeRepository();
errorTypeRepository.addErrorType(TRANSFORMATION, errorTypeRepository.getAnyErrorType());
errorTypeRepository.addErrorType(EXPRESSION, errorTypeRepository.getAnyErrorType());
final ErrorType validationErrorType = errorTypeRepository.addErrorType(VALIDATION, errorTypeRepository.getAnyErrorType());
errorTypeRepository.addErrorType(DUPLICATE_MESSAGE, validationErrorType);
errorTypeRepository.addErrorType(REDELIVERY_EXHAUSTED, errorTypeRepository.getAnyErrorType());
final ErrorType connectivityErrorType = errorTypeRepository.addErrorType(CONNECTIVITY, errorTypeRepository.getAnyErrorType());
errorTypeRepository.addErrorType(RETRY_EXHAUSTED, connectivityErrorType);
errorTypeRepository.addErrorType(ROUTING, errorTypeRepository.getAnyErrorType());
errorTypeRepository.addErrorType(SECURITY, errorTypeRepository.getAnyErrorType());
errorTypeRepository.addErrorType(CLIENT_SECURITY, errorTypeRepository.getErrorType(SECURITY).get());
errorTypeRepository.addErrorType(SERVER_SECURITY, errorTypeRepository.getErrorType(SECURITY).get());
errorTypeRepository.addErrorType(NOT_PERMITTED, errorTypeRepository.getErrorType(SERVER_SECURITY).get());
errorTypeRepository.addErrorType(STREAM_MAXIMUM_SIZE_EXCEEDED, errorTypeRepository.getAnyErrorType());
errorTypeRepository.addInternalErrorType(OVERLOAD, errorTypeRepository.getCriticalErrorType());
errorTypeRepository.addInternalErrorType(FLOW_BACK_PRESSURE, errorTypeRepository.getErrorType(OVERLOAD).get());
errorTypeRepository.addInternalErrorType(FATAL, errorTypeRepository.getCriticalErrorType());
errorTypeRepository.addErrorType(TIMEOUT, errorTypeRepository.getAnyErrorType());
errorTypeRepository.addErrorType(COMPOSITE_ROUTING, errorTypeRepository.getErrorType(ROUTING).get());
final ErrorType sourceErrorType = errorTypeRepository.getSourceErrorType();
errorTypeRepository.addErrorType(SOURCE_RESPONSE_GENERATE, errorTypeRepository.getSourceResponseErrorType());
errorTypeRepository.addErrorType(SOURCE_RESPONSE_SEND, errorTypeRepository.getSourceResponseErrorType());
errorTypeRepository.addInternalErrorType(SOURCE_ERROR_RESPONSE_GENERATE, sourceErrorType);
errorTypeRepository.addInternalErrorType(SOURCE_ERROR_RESPONSE_SEND, sourceErrorType);
return errorTypeRepository;
}
use of org.mule.runtime.api.exception.ErrorTypeRepository in project mule by mulesoft.
the class OnErrorContinueHandler method doInitialise.
@Override
protected void doInitialise(MuleContext muleContext) throws InitialisationException {
super.doInitialise(muleContext);
ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
sourceErrorMatcher = new SingleErrorTypeMatcher(errorTypeRepository.getSourceResponseErrorType());
if (errorType != null) {
String[] errors = errorType.split(",");
for (String error : errors) {
// Since the partial initialisation was successful, we know this error ids are safe
String sanitizedError = error.trim();
ErrorType errorType = errorTypeRepository.lookupErrorType(buildFromStringRepresentation(sanitizedError)).get();
if (sourceErrorMatcher.match(errorType)) {
throw new InitialisationException(getInitialisationError(sanitizedError), this);
}
}
} else if (when == null) {
// No error type and no expression, force ANY matcher
errorTypeMatcher = new SingleErrorTypeMatcher(errorTypeRepository.getAnyErrorType());
}
}
use of org.mule.runtime.api.exception.ErrorTypeRepository in project mule by mulesoft.
the class ExtensionPluginMetadataGenerator method createExtensionManager.
/**
* Creates a {@link ExtensionManager} needed for generating the metadata for an extension. It would be later discarded due to
* the manager would have references to classes loaded with the launcher class loader instead of the hierarchical class loaders
* created as result of the classification process.
*
* @return an {@link ExtensionManager} that would be used to register the extensions.
*/
private ExtensionManager createExtensionManager() {
DefaultExtensionManager extensionManager = new DefaultExtensionManager();
extensionManager.setMuleContext(new DefaultMuleContext() {
private ErrorTypeRepository errorTypeRepository = createDefaultErrorTypeRepository();
private ErrorTypeLocator errorTypeLocator = createDefaultErrorTypeLocator(errorTypeRepository);
@Override
public MuleRegistry getRegistry() {
return new MuleRegistryHelper(new DefaultRegistryBroker(this, new MuleLifecycleInterceptor()), this);
}
@Override
public ErrorTypeLocator getErrorTypeLocator() {
return errorTypeLocator;
}
@Override
public ErrorTypeRepository getErrorTypeRepository() {
return errorTypeRepository;
}
});
try {
extensionManager.initialise();
} catch (InitialisationException e) {
throw new RuntimeException("Error while initialising the extension manager", e);
}
return extensionManager;
}
Aggregations