use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class AbstractMessageSequenceSplitter method initEventBuilder.
private void initEventBuilder(Object sequenceValue, CoreEvent originalEvent, Builder builder, Map<String, ?> flowVarsFromLastResult) {
if (sequenceValue instanceof EventBuilderConfigurer) {
((EventBuilderConfigurer) sequenceValue).configure(builder);
} else if (sequenceValue instanceof CoreEvent) {
final CoreEvent payloadAsEvent = (CoreEvent) sequenceValue;
builder.message(payloadAsEvent.getMessage());
for (String flowVarName : payloadAsEvent.getVariables().keySet()) {
if (!flowVarsFromLastResult.containsKey(flowVarName)) {
builder.addVariable(flowVarName, payloadAsEvent.getVariables().get(flowVarName).getValue(), payloadAsEvent.getVariables().get(flowVarName).getDataType());
}
}
} else if (sequenceValue instanceof Message) {
final Message message = (Message) sequenceValue;
builder.message(message);
} else if (sequenceValue instanceof TypedValue) {
builder.message(Message.builder().payload((TypedValue) sequenceValue).build());
} else if (sequenceValue instanceof Collection) {
builder.message(Message.builder(originalEvent.getMessage()).value(((Collection) sequenceValue).stream().map(v -> v instanceof TypedValue ? ((TypedValue) v).getValue() : v).collect(toList())).build());
} else {
builder.message(Message.builder(originalEvent.getMessage()).value(sequenceValue).build());
}
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultSchedulerMessageSource method poll.
/**
* Triggers the forced execution of the polling message processor ignoring the configured scheduler.
*/
private void poll() {
boolean execute = false;
synchronized (this) {
if (disallowConcurrentExecution && executing) {
execute = false;
} else {
execute = true;
executing = true;
}
}
if (execute) {
Message request = of(null);
pollWith(request);
} else {
LOGGER.info("Flow '{}' is already running and 'disallowConcurrentExecution' is set to 'true'. Execution skipped.", flowConstruct.getRootContainerLocation().getGlobalName());
}
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class ExtendedTransformationService method applyAllTransformers.
private Message applyAllTransformers(final Message message, final CoreEvent event, final List<? extends Transformer> transformers) throws MuleException {
Message result = message;
if (!transformers.isEmpty()) {
for (int index = 0; index < transformers.size(); index++) {
Transformer transformer = transformers.get(index);
Class<?> srcCls = result.getPayload().getDataType().getType();
DataType originalSourceType = DataType.fromType(srcCls);
if (transformer.isSourceDataTypeSupported(originalSourceType)) {
if (logger.isDebugEnabled()) {
logger.debug("Using " + transformer + " to transform payload.");
}
result = transformMessage(result, event, transformer);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Transformer " + transformer + " doesn't support the source payload: " + srcCls);
}
if (canSkipTransformer(result, transformers, index)) {
continue;
}
// Resolves implicit conversion if possible
Transformer implicitTransformer = muleContext.getDataTypeConverterResolver().resolve(originalSourceType, transformer.getSourceDataTypes());
if (implicitTransformer != null) {
if (logger.isDebugEnabled()) {
logger.debug("Performing implicit transformation with: " + transformer);
}
result = transformMessage(result, event, implicitTransformer);
result = transformMessage(result, event, transformer);
} else {
throw new IllegalArgumentException("Cannot apply transformer " + transformer + " on source payload: " + srcCls);
}
}
}
Transformer lastTransformer = transformers.get(transformers.size() - 1);
DataType returnDataType = lastTransformer.getReturnDataType();
checkResultDataType(message, returnDataType, result.getPayload().getValue());
}
return result;
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class TransformerChain method transformMessage.
@Override
public Object transformMessage(CoreEvent event, Charset outputEncoding) throws MessageTransformerException {
Message result = event.getMessage();
Object temp = event.getMessage();
Transformer lastTransformer = null;
for (Object element : transformers) {
lastTransformer = (Transformer) element;
try {
temp = lastTransformer.transform(temp);
} catch (TransformerException e) {
throw new MessageTransformerException(lastTransformer, e, event.getMessage());
}
if (temp instanceof Message) {
result = (Message) temp;
} else {
result = Message.builder(event.getMessage()).value(temp).build();
event = CoreEvent.builder(event).message(result).build();
}
}
if (lastTransformer != null && Message.class.isAssignableFrom(lastTransformer.getReturnDataType().getType())) {
return result;
} else {
return result.getPayload().getValue();
}
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class BytesStreamingExtensionTestCase method rewind.
@Test
@Description("Rewing a stream and consume it twice")
public void rewind() throws Exception {
CoreEvent result = flowRunner("rewind").withPayload(data).run();
Message firstRead = (Message) result.getVariables().get("firstRead").getValue();
Message secondRead = (Message) result.getVariables().get("secondRead").getValue();
assertThat(firstRead.getPayload().getValue(), equalTo(data));
assertThat(secondRead.getPayload().getValue(), equalTo(data));
}
Aggregations