use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class SetPayloadMessageProcessorTestCase method setsExpressionPayload.
@Test
public void setsExpressionPayload() throws MuleException {
setPayloadMessageProcessor.setValue(EXPRESSION);
when(expressionManager.isExpression(EXPRESSION)).thenReturn(true);
setPayloadMessageProcessor.initialise();
TypedValue typedValue = new TypedValue(PLAIN_TEXT, DataType.STRING);
when(expressionManager.evaluate(EXPRESSION, testEvent())).thenReturn(typedValue);
when(expressionManager.evaluate(eq(EXPRESSION), eq(testEvent()), any(CoreEvent.Builder.class), eq(null))).thenReturn(typedValue);
CoreEvent response = setPayloadMessageProcessor.process(testEvent());
assertThat(response.getMessage().getPayload().getValue(), is(PLAIN_TEXT));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class SetPayloadTransformerTestCase method testSetPayloadTransformerExpression.
@Test
public void testSetPayloadTransformerExpression() throws InitialisationException, MessageTransformerException {
setPayloadTransformer.setValue(EXPRESSION);
when(mockExpressionManager.isExpression(EXPRESSION)).thenReturn(true);
setPayloadTransformer.initialise();
TypedValue typedValue = new TypedValue<>(PLAIN_TEXT, STRING);
when(mockExpressionManager.evaluate(EXPRESSION, mockMuleEvent)).thenReturn(typedValue);
Object response = setPayloadTransformer.transformMessage(mockMuleEvent, UTF_8);
assertThat(response, is(PLAIN_TEXT));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class StreamingUtils method updateTypedValueForStreaming.
/**
* Updates the value a given {@link TypedValue} instance by replacing it with a {@link CursorProvider}.
*
* @param value the typed value to update
* @param event the current event
* @param streamingManager the streaming manager
* @return updated {@link TypedValue instance}
*/
public static TypedValue updateTypedValueForStreaming(final TypedValue value, final CoreEvent event, final StreamingManager streamingManager) {
if (event == null) {
return value;
} else {
Object payload = value.getValue();
if (payload instanceof CursorProvider) {
CursorProvider cursorProvider = streamingManager.manage((CursorProvider) payload, event);
DataType dataType = DataType.builder(value.getDataType()).type(cursorProvider.getClass()).build();
return new TypedValue<>(cursorProvider, dataType, value.getByteLength());
}
return value;
}
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class StreamingUtils method updateTypedValueWithCursorProvider.
/**
* Updates the {@link Cursor} value a given {@link TypedValue} instance by replacing it with a {@link CursorProvider}.
*
* @param value the typed value to update
* @param event the current event
* @param streamingManager the streaming manager
* @return updated {@link TypedValue instance}
*/
public static TypedValue updateTypedValueWithCursorProvider(final TypedValue value, final CoreEvent event, final StreamingManager streamingManager) {
if (event == null) {
return value;
} else {
Object payload = value.getValue();
if (payload instanceof CursorStream) {
CursorProvider provider = ((CursorStream) value.getValue()).getProvider();
DataType dataType = DataType.builder(value.getDataType()).type(provider.getClass()).build();
return new TypedValue(provider, dataType, value.getByteLength());
} else {
return value;
}
}
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class MessageEnricher method enrich.
protected PrivilegedEvent enrich(PrivilegedEvent currentEvent, PrivilegedEvent enrichmentEvent, String sourceExpressionArg, String targetExpressionArg, ExtendedExpressionManager expressionManager) {
if (StringUtils.isEmpty(sourceExpressionArg)) {
sourceExpressionArg = "#[mel:payload:]";
}
TypedValue typedValue = expressionManager.evaluate(sourceExpressionArg, enrichmentEvent, getLocation());
if (typedValue.getValue() instanceof Message) {
Message muleMessage = (Message) typedValue.getValue();
typedValue = new TypedValue(muleMessage.getPayload().getValue(), muleMessage.getPayload().getDataType());
}
if (!StringUtils.isEmpty(targetExpressionArg)) {
PrivilegedEvent.Builder eventBuilder = PrivilegedEvent.builder(currentEvent);
expressionManager.enrich(targetExpressionArg, currentEvent, eventBuilder, getLocation(), typedValue);
return eventBuilder.build();
} else {
return PrivilegedEvent.builder(currentEvent).message(Message.builder(currentEvent.getMessage()).value(typedValue.getValue()).mediaType(typedValue.getDataType().getMediaType()).build()).build();
}
}
Aggregations