Search in sources :

Example 1 with Builder

use of org.mule.runtime.core.internal.message.InternalEvent.Builder in project mule by mulesoft.

the class ModuleFlowProcessingPhase method createEvent.

private CoreEvent createEvent(ModuleFlowProcessingPhaseTemplate template, ComponentLocation sourceLocation, CompletableFuture responseCompletion, FlowConstruct flowConstruct) {
    Message message = template.getMessage();
    Builder eventBuilder;
    if (message.getPayload().getValue() instanceof SourceResultAdapter) {
        SourceResultAdapter adapter = (SourceResultAdapter) message.getPayload().getValue();
        eventBuilder = createEventBuilder(sourceLocation, responseCompletion, flowConstruct, adapter.getCorrelationId().orElse(null), message);
        CoreEvent templateEvent = eventBuilder.build();
        final Result<?, ?> result = adapter.getResult();
        final Object resultValue = result.getOutput();
        if (resultValue instanceof Collection && adapter.isCollection()) {
            message = toMessage(Result.<Collection<Message>, TypedValue>builder().output(toMessageCollection((Collection<Result>) resultValue, adapter.getCursorProviderFactory(), templateEvent)).mediaType(result.getMediaType().orElse(ANY)).build());
        } else {
            message = toMessage(result, adapter.getMediaType(), adapter.getCursorProviderFactory(), templateEvent);
        }
        return eventBuilder.message(message).build();
    }
    return createEventBuilder(sourceLocation, responseCompletion, flowConstruct, null, message).build();
}
Also used : Message(org.mule.runtime.api.message.Message) MessageUtils.toMessage(org.mule.runtime.core.internal.util.message.MessageUtils.toMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Builder(org.mule.runtime.core.internal.message.InternalEvent.Builder) Collection(java.util.Collection) MessageUtils.toMessageCollection(org.mule.runtime.core.internal.util.message.MessageUtils.toMessageCollection)

Aggregations

Collection (java.util.Collection)1 Message (org.mule.runtime.api.message.Message)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 Builder (org.mule.runtime.core.internal.message.InternalEvent.Builder)1 MessageUtils.toMessage (org.mule.runtime.core.internal.util.message.MessageUtils.toMessage)1 MessageUtils.toMessageCollection (org.mule.runtime.core.internal.util.message.MessageUtils.toMessageCollection)1