Search in sources :

Example 1 with InputEvent

use of org.mule.runtime.api.component.execution.InputEvent 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();
}
Also used : Optional.of(java.util.Optional.of) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) CoreEvent.builder(org.mule.runtime.core.api.event.CoreEvent.builder) Event(org.mule.runtime.api.event.Event) ExecutionResult(org.mule.runtime.api.component.execution.ExecutionResult) Inject(javax.inject.Inject) MuleContext(org.mule.runtime.core.api.MuleContext) Mono.from(reactor.core.publisher.Mono.from) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) EventContext(org.mule.runtime.api.event.EventContext) 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) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) NullExceptionHandler(org.mule.runtime.core.api.exception.NullExceptionHandler) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InputEvent(org.mule.runtime.api.component.execution.InputEvent) String.format(java.lang.String.format) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) ComponentExecutionException(org.mule.runtime.api.component.execution.ComponentExecutionException) MessageProcessors(org.mule.runtime.core.privileged.processor.MessageProcessors) ExecutableComponent(org.mule.runtime.api.component.execution.ExecutableComponent) Optional(java.util.Optional) DefaultEventContext.child(org.mule.runtime.core.internal.event.DefaultEventContext.child) CompletableFuture(java.util.concurrent.CompletableFuture) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ComponentExecutionException(org.mule.runtime.api.component.execution.ComponentExecutionException)

Aggregations

String.format (java.lang.String.format)1 Optional (java.util.Optional)1 Optional.of (java.util.Optional.of)1 Optional.ofNullable (java.util.Optional.ofNullable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Function (java.util.function.Function)1 Inject (javax.inject.Inject)1 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)1 ComponentExecutionException (org.mule.runtime.api.component.execution.ComponentExecutionException)1 ExecutableComponent (org.mule.runtime.api.component.execution.ExecutableComponent)1 ExecutionResult (org.mule.runtime.api.component.execution.ExecutionResult)1 InputEvent (org.mule.runtime.api.component.execution.InputEvent)1 Event (org.mule.runtime.api.event.Event)1 EventContext (org.mule.runtime.api.event.EventContext)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 MuleContext (org.mule.runtime.core.api.MuleContext)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 CoreEvent.builder (org.mule.runtime.core.api.event.CoreEvent.builder)1 EventContextFactory.create (org.mule.runtime.core.api.event.EventContextFactory.create)1