use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class TransformerUtils method transformToAny.
public static <T> Object transformToAny(T input, MuleContext muleContext, DataType... supportedTypes) {
final DataType sourceType = DataType.fromType(input.getClass());
Object transformedData = null;
for (DataType supportedType : supportedTypes) {
transformedData = attemptTransformation(sourceType, input, supportedType, muleContext);
if (transformedData != null) {
break;
}
}
return transformedData;
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class ContentTypeHandlingTestCase method setsContentTypeOnXml.
@Test
public void setsContentTypeOnXml() throws Exception {
CoreEvent response = runFlow("setsContentTypeOnXml");
DataType dataType = response.getMessage().getPayload().getDataType();
assertCustomEncoding(dataType);
assertThat(dataType.getMediaType().getPrimaryType(), is(MediaType.TEXT.getPrimaryType()));
assertThat(dataType.getMediaType().getSubType(), is(MediaType.TEXT.getSubType()));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class ContentTypeHandlingTestCase method maintainsContentType.
@Test
public void maintainsContentType() throws Exception {
CoreEvent response = flowRunner("defaultContentType").withPayload("").run();
final DataType responseDataType = response.getMessage().getPayload().getDataType();
assertDefaultEncoding(responseDataType);
assertDefaultMimeType(responseDataType);
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class ContentTypeHandlingTestCase method onlySetMimeTypeOnXml.
@Test
public void onlySetMimeTypeOnXml() throws Exception {
CoreEvent response = runFlow("onlySetMimeTypeOnXml");
DataType dataType = response.getMessage().getPayload().getDataType();
assertDefaultEncoding(dataType);
assertCustomMimeType(dataType);
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class ReflectiveFunctionExecutorFactory method createExecutor.
@Override
public FunctionExecutor createExecutor(FunctionModel functionModel, FunctionParameterDefaultValueResolverFactory defaultResolverFactory) {
DataType returnType = fromType(getType(functionModel.getOutput().getType()).orElseThrow(() -> new MuleRuntimeException(createStaticMessage(format("Failed to obtain the return type for function [%s]", functionModel.getName())))));
List<FunctionParameter> functionParameters = functionModel.getAllParameterModels().stream().map(p -> {
MetadataType paramType = p.getType();
DataType type = isTypedValue(paramType) ? fromType(TypedValue.class) : toDataType(paramType);
if (p.isRequired()) {
return new FunctionParameter(p.getName(), type);
}
Object defaultValue = p.getDefaultValue();
if (defaultValue == null) {
return new FunctionParameter(p.getName(), type, context -> Defaults.defaultValue(type.getType()));
}
return new FunctionParameter(p.getName(), type, defaultResolverFactory.create(defaultValue, type));
}).collect(toList());
return new ReflectiveExpressionFunctionExecutor(functionModel, returnType, functionParameters, method, getDelegateInstance());
}
Aggregations