use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method messageErrorBinding.
@Test
public void messageErrorBinding() throws Exception {
Error error = mock(Error.class);
when(error.getErrorMessage()).thenReturn(Message.of(new Integer[] { 1, 3, 6 }));
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expression = "error.errorMessage.payload reduce ($$ + $)";
TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
assertThat(result.getValue(), is(10));
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method errorBinding.
@Test
public void errorBinding() throws Exception {
Error error = mock(Error.class);
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
TypedValue result = expressionLanguage.evaluate(ERROR, event, BindingContext.builder().build());
assertThat(result.getValue(), is(sameInstance(error)));
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class ErrorHandlerTestCase method before.
@Before
public void before() throws MuleException {
Error mockError = mock(Error.class);
when(mockError.getErrorType()).thenReturn(mockErrorType);
event = getEventBuilder().message(Message.of("")).error(mockError).build();
mockException = new MessagingException(event, new Exception());
CoreEvent handledEvent = testEvent();
when(mockTestExceptionStrategy1.accept(any(CoreEvent.class))).thenReturn(true);
when(mockTestExceptionStrategy1.apply(any(MessagingException.class))).thenReturn(just(handledEvent));
when(mockTestExceptionStrategy2.accept(any(CoreEvent.class))).thenReturn(true);
when(mockTestExceptionStrategy2.apply(any(MessagingException.class))).thenReturn(just(handledEvent));
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class CausedByFunction method call.
@Override
public Object call(Object[] parameters, BindingContext context) {
Error error = (Error) parameters[0];
checkArgument(error != null, "There's no error to match against.");
String errorIdentifier = (String) parameters[1];
ErrorTypeMatcher errorTypeMatcher = new SingleErrorTypeMatcher(resolveErrorType(errorIdentifier));
return errorTypeMatcher.match(error.getErrorType());
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class LookupFunction method call.
@Override
public Object call(Object[] parameters, BindingContext context) {
String flowName = (String) parameters[0];
Object payload = parameters[1];
Location componentLocation = Location.builder().globalName(flowName).build();
Component component = componentLocator.find(componentLocation).orElseThrow(() -> new IllegalArgumentException(format("There is no component named '%s'.", flowName)));
if (component instanceof Flow) {
try {
Message incomingMessage = lookupValue(context, MESSAGE, Message.builder().nullValue().build());
Map<String, ?> incomingVariables = lookupValue(context, VARS, EMPTY_MAP);
Error incomingError = lookupValue(context, ERROR, null);
Message message = Message.builder(incomingMessage).value(payload).mediaType(APPLICATION_JAVA).build();
CoreEvent event = CoreEvent.builder(PrivilegedEvent.getCurrentEvent().getContext()).variables(incomingVariables).error(incomingError).message(message).build();
return ((ExecutableComponent) component).execute(event).get().getMessage().getPayload();
} catch (ExecutionException e) {
ComponentExecutionException componentExecutionException = (ComponentExecutionException) e.getCause();
Error error = componentExecutionException.getEvent().getError().get();
throw new MuleRuntimeException(createStaticMessage(format("Flow '%s' has failed with error '%s' (%s)", flowName, error.getErrorType(), error.getDescription())), error.getCause());
} catch (InterruptedException e) {
throw new MuleRuntimeException(e);
}
} else {
throw new IllegalArgumentException(format("Component '%s' is not a flow.", flowName));
}
}
Aggregations