use of org.mule.runtime.core.privileged.PrivilegedMuleContext 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.privileged.PrivilegedMuleContext in project mule by mulesoft.
the class MessagingExceptionResolver method resolve.
/**
* Resolves a new {@link MessagingException} with the real cause of the problem based on the content of an Incoming
* {@link MessagingException} with a chain of causes inside it and the current event that the exception is carrying.
* <p>
* This method will pick the FIRST cause exception that has a mule or extension KNOWN error as the real cause, if there is not
* an exception in the causes that match with an Known error type then this method will try to find the error that the current
* {@link Event} is carrying.
* <p>
* When there are multiple exceptions that contains the same root error type, then this method will wrap the one that has
* highest position in the causes list
*
* @return a {@link MessagingException} with the proper {@link Error} associated to it's {@link CoreEvent}
*/
public MessagingException resolve(final MessagingException me, MuleContext context) {
ErrorTypeLocator locator = ((PrivilegedMuleContext) context).getErrorTypeLocator();
Optional<Pair<Throwable, ErrorType>> rootCause = findRoot(component, me, locator);
if (!rootCause.isPresent()) {
return updateCurrent(me, component, context);
}
Throwable root = rootCause.get().getFirst();
ErrorType rootErrorType = rootCause.get().getSecond();
Component failingComponent = getFailingProcessor(me, root).orElse(component);
ErrorType errorType = getErrorMappings(component).stream().filter(m -> m.match(rootErrorType)).findFirst().map(ErrorMapping::getTarget).orElse(rootErrorType);
Error error = ErrorBuilder.builder(getMessagingExceptionCause(root)).errorType(errorType).build();
CoreEvent event = CoreEvent.builder(me.getEvent()).error(error).build();
MessagingException result;
if (root instanceof MessagingException) {
((MessagingException) root).setProcessedEvent(event);
result = ((MessagingException) root);
} else {
result = me instanceof FlowExecutionException ? new FlowExecutionException(event, root, failingComponent) : new MessagingException(event, root, failingComponent);
}
if (me.getInfo().containsKey(INFO_ALREADY_LOGGED_KEY)) {
result.addInfo(INFO_ALREADY_LOGGED_KEY, me.getInfo().get(INFO_ALREADY_LOGGED_KEY));
}
return enrich(result, failingComponent, event, context);
}
use of org.mule.runtime.core.privileged.PrivilegedMuleContext in project mule by mulesoft.
the class PipelineMessageNotificationTestCase method mockErrorTypeLocator.
private void mockErrorTypeLocator() {
ErrorTypeLocator typeLocator = mock(ErrorTypeLocator.class);
ErrorType errorType = mock(ErrorType.class);
when(errorType.getIdentifier()).thenReturn("ID");
when(errorType.getNamespace()).thenReturn("NS");
when(typeLocator.lookupErrorType(any(Throwable.class))).thenReturn(errorType);
when(typeLocator.<String, Throwable>lookupComponentErrorType(any(ComponentIdentifier.class), any(Throwable.class))).thenReturn(errorType);
when(((PrivilegedMuleContext) muleContext).getErrorTypeLocator()).thenReturn(typeLocator);
}
use of org.mule.runtime.core.privileged.PrivilegedMuleContext in project mule by mulesoft.
the class DefaultMessageProcessorChainTestCase method before.
@Before
public void before() throws MuleException {
nonBlockingProcessorsExecuted.set(0);
muleContext = spy(super.muleContext);
ErrorTypeLocator errorTypeLocator = mock(ErrorTypeLocator.class);
ErrorType errorType = mock(ErrorType.class);
ExceptionContextProvider exceptionContextProvider = mock(ExceptionContextProvider.class);
MuleConfiguration muleConfiguration = mock(MuleConfiguration.class);
when(muleConfiguration.isContainerMode()).thenReturn(false);
when(muleConfiguration.getId()).thenReturn(randomNumeric(3));
when(muleConfiguration.getShutdownTimeout()).thenReturn(1000L);
when(muleContext.getConfiguration()).thenReturn(muleConfiguration);
when(((PrivilegedMuleContext) muleContext).getErrorTypeLocator()).thenReturn(errorTypeLocator);
when(muleContext.getExceptionContextProviders()).thenReturn(singletonList(exceptionContextProvider));
when(errorTypeLocator.lookupErrorType((Exception) any())).thenReturn(errorType);
flow = builder("flow", muleContext).processingStrategyFactory(processingStrategyFactory).build();
flow.initialise();
flow.start();
}
use of org.mule.runtime.core.privileged.PrivilegedMuleContext in project mule by mulesoft.
the class ReactiveAroundInterceptorAdapter method doAround.
private CompletableFuture<InternalEvent> doAround(InternalEvent event, ProcessorInterceptor interceptor, Processor component, Map<String, String> dslParameters, ReactiveProcessor next) {
final InternalEvent eventWithResolvedParams = addResolvedParameters(event, component, dslParameters);
DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(eventWithResolvedParams);
final ReactiveInterceptionAction reactiveInterceptionAction = new ReactiveInterceptionAction(interceptionEvent, next, component, ((PrivilegedMuleContext) getMuleContext()).getErrorTypeLocator());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Calling around() for '{}' in processor '{}'...", interceptor, ((Component) component).getLocation().getLocation());
}
try {
return withContextClassLoader(interceptor.getClass().getClassLoader(), () -> interceptor.around(((Component) component).getLocation(), getResolvedParams(eventWithResolvedParams), interceptionEvent, reactiveInterceptionAction)).exceptionally(t -> {
if (t instanceof MessagingException) {
throw new CompletionException(t);
} else {
throw new CompletionException(createMessagingException(eventWithResolvedParams, t instanceof CompletionException ? t.getCause() : t, ((Component) component)));
}
}).thenApply(interceptedEvent -> interceptedEvent != null ? ((DefaultInterceptionEvent) interceptedEvent).resolve() : null);
} catch (Exception e) {
throw propagate(createMessagingException(interceptionEvent.resolve(), e, (Component) component));
}
}
Aggregations