use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class SoapOperationExecutor method getRequest.
/**
* Builds a Soap Request with the execution context to be sent using the {@link SoapClient}.
*/
private SoapRequest getRequest(ExecutionContext<OperationModel> context, Map<String, String> fixedHeaders) throws MessageTransformerException, TransformerException {
SoapRequestBuilder builder = SoapRequest.builder().operation(getOperation(context));
builder.soapHeaders(fixedHeaders);
Optional<Object> optionalMessageGroup = getParam(context, MESSAGE_GROUP);
if (optionalMessageGroup.isPresent()) {
Map<String, Object> message = (Map<String, Object>) optionalMessageGroup.get();
InputStream body = (InputStream) message.get(BODY_PARAM);
if (body != null) {
builder.content(body);
}
InputStream headers = (InputStream) message.get(HEADERS_PARAM);
if (headers != null) {
builder.soapHeaders((Map<String, String>) evaluateHeaders(headers));
}
Map<String, TypedValue<?>> attachments = (Map<String, TypedValue<?>>) message.get(ATTACHMENTS_PARAM);
if (attachments != null) {
toSoapAttachments(attachments).forEach(builder::attachment);
}
}
getParam(context, TRANSPORT_HEADERS_PARAM).ifPresent(th -> builder.transportHeaders((Map<String, String>) th));
return builder.build();
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class ReflectiveExpressionFunctionExecutor method getWrapper.
private Function<Object, Object> getWrapper(Parameter parameter) {
Type[] generics = parameter.getType().getGenericInterfaces();
Class<?> type;
if (generics.length == 0) {
type = Object.class;
} else {
type = model.getAllParameterModels().stream().filter(p -> p.getModelProperty(ImplementingParameterModelProperty.class).map(mp -> mp.getParameter().getName().equals(parameter.getName())).orElse(false)).map(p -> getType(p.getType()).orElse(Object.class)).findFirst().orElseThrow(() -> new IllegalStateException(format("Missing parameter with name [%s]", parameter.getName())));
}
DataType expected = DataType.fromType(type);
return value -> {
if (value == null) {
return null;
}
if (value instanceof TypedValue) {
if (((TypedValue) value).getDataType().equals(DataType.TYPED_VALUE)) {
// DW will wrap anything of type TypedValue in a new TypedValue with DataType.TYPED_VALUE
value = ((TypedValue) value).getValue();
}
TypedValue typedValue = (TypedValue) value;
// We have to check for transformations of the value because weave won't be able to validate types
return type.isInstance(typedValue.getValue()) ? value : new TypedValue<>(transformationService.transform(typedValue.getValue(), typedValue.getDataType(), expected), typedValue.getDataType());
} else {
return new TypedValue<>(value, fromObject(value));
}
};
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class ExpressionTypedValueValueResolver method resolve.
@Override
public TypedValue<T> resolve(ValueResolvingContext context) throws MuleException {
initEvaluator();
TypedValue typedValue = evaluator.resolveTypedValue(context.getEvent());
if (!isInstance(expectedClass, typedValue.getValue())) {
DataType expectedDataType = DataType.builder().type(expectedClass).mediaType(typedValue.getDataType().getMediaType()).build();
return new TypedValue<>(typeSafeTransformer.<T>transform(typedValue.getValue(), typedValue.getDataType(), expectedDataType), expectedDataType);
}
return typedValue;
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class ModuleJsonCustomTypeTestCase method testExtractingJsonResponseAndFeedingSimpleType.
@Test
public void testExtractingJsonResponseAndFeedingSimpleType() throws Exception {
final CoreEvent muleEvent = flowRunner("testExtractingJsonResponseAndFeedingSimpleType").run();
final Map<String, TypedValue<?>> variables = muleEvent.getVariables();
assertThat(variables.get("checkingNotAvenue").getValue(), is(false));
assertThat(variables.get("checkingFromExpression").getValue(), is(true));
assertThat(variables.get("checkingFromHardcodedType1").getValue(), is(true));
assertThat(variables.get("checkingFromHardcodedType1WithVariables").getValue(), is(true));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class TestEventBuilder method build.
/**
* Produces an event with the specified configuration.
*
* @param flow the recipient for the event to be built.
* @return an event with the specified configuration.
*/
public CoreEvent build(FlowConstruct flow) {
final Message.Builder messageBuilder;
messageBuilder = Message.builder().value(payload).mediaType(mediaType);
setInboundProperties(messageBuilder, inboundProperties);
setOutboundProperties(messageBuilder, outboundProperties);
if (attributes != null) {
messageBuilder.attributesValue(attributes);
}
final Message muleMessage = messageBuilder.build();
EventContext eventContext;
if (externalCompletionCallback != null) {
eventContext = create(flow, TEST_CONNECTOR_LOCATION, sourceCorrelationId, of(externalCompletionCallback));
} else {
eventContext = create(flow, TEST_CONNECTOR_LOCATION, sourceCorrelationId);
}
CoreEvent.Builder builder = InternalEvent.builder(eventContext).message(spyMessage.apply(muleMessage)).replyToHandler(replyToHandler).itemSequenceInfo(ofNullable(itemSequenceInfo));
for (Entry<String, TypedValue> variableEntry : variables.entrySet()) {
builder.addVariable(variableEntry.getKey(), variableEntry.getValue().getValue(), variableEntry.getValue().getDataType());
}
CoreEvent event = builder.build();
for (Entry<String, Attachment> outboundAttachmentEntry : outboundAttachments.entrySet()) {
event = outboundAttachmentEntry.getValue().addOutboundTo(event, outboundAttachmentEntry.getKey());
}
for (Entry<String, Object> sessionPropertyEntry : sessionProperties.entrySet()) {
((PrivilegedEvent) event).getSession().setProperty(sessionPropertyEntry.getKey(), sessionPropertyEntry.getValue());
}
return spyEvent.apply(event);
}
Aggregations