use of org.mule.runtime.api.component.execution.ComponentExecutionException in project mule by mulesoft.
the class AbstractExecutableComponent method execute.
@Override
public final CompletableFuture<ExecutionResult> execute(InputEvent inputEvent) {
CompletableFuture completableFuture = new CompletableFuture();
CoreEvent.Builder builder = CoreEvent.builder(createEventContext(of(completableFuture)));
CoreEvent event = builder.message(inputEvent.getMessage()).error(inputEvent.getError().orElse(null)).variables(inputEvent.getVariables()).build();
return from(MessageProcessors.process(event, getExecutableFunction())).onErrorMap(throwable -> {
MessagingException messagingException = (MessagingException) throwable;
CoreEvent messagingExceptionEvent = messagingException.getEvent();
return new ComponentExecutionException(messagingExceptionEvent.getError().get().getCause(), messagingExceptionEvent);
}).<ExecutionResult>map(result -> new ExecutionResultImplementation(result, completableFuture)).toFuture();
}
use of org.mule.runtime.api.component.execution.ComponentExecutionException 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));
}
}
use of org.mule.runtime.api.component.execution.ComponentExecutionException in project mule by mulesoft.
the class AbstractExecutableComponent method execute.
@Override
public final CompletableFuture<Event> execute(Event event) {
CoreEvent internalEvent;
BaseEventContext child = createChildEventContext(event.getContext());
if (event instanceof CoreEvent) {
internalEvent = builder(child, (CoreEvent) event).build();
} else {
internalEvent = CoreEvent.builder(createEventContext(null)).message(event.getMessage()).error(event.getError().orElse(null)).variables(event.getVariables()).build();
}
return from(MessageProcessors.process(internalEvent, getExecutableFunction())).onErrorMap(throwable -> {
MessagingException messagingException = (MessagingException) throwable;
CoreEvent messagingExceptionEvent = messagingException.getEvent();
return new ComponentExecutionException(messagingExceptionEvent.getError().get().getCause(), messagingExceptionEvent);
}).map(r -> builder(event.getContext(), r).build()).cast(Event.class).toFuture();
}
Aggregations