use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class SpringRegistryBootstrap method doRegisterTransformer.
@Override
protected void doRegisterTransformer(TransformerBootstrapProperty bootstrapProperty, Class<?> returnClass, Class<? extends Transformer> transformerClass) throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(transformerClass);
DataType returnType = null;
if (returnClass != null) {
DataTypeParamsBuilder dataTypeBuilder = DataType.builder().type(returnClass);
if (isNotEmpty(bootstrapProperty.getMimeType())) {
dataTypeBuilder = dataTypeBuilder.mediaType(bootstrapProperty.getMimeType());
}
builder.addPropertyValue("returnDataType", dataTypeBuilder.build());
}
String name = bootstrapProperty.getName();
if (name == null) {
// Prefixes the generated default name to ensure there is less chance of conflict if the user registers
// the transformer with the same name
name = "_" + TransformerUtils.generateTransformerName(transformerClass, returnType);
}
builder.addPropertyValue("name", name);
notifyIfOptional(name, bootstrapProperty.getOptional());
doRegisterObject(name, builder);
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class TestLegacyMessageUtils method getOutboundPropertyDataType.
/**
* Gets an outbound property data type from the message.
*
* @param message message used to obtain the data from. Must be a {@link InternalMessage}
* @param name the name or key of the property. This must be non-null.
* @return the property data type or null if the property does not exist in the specified scope
* @throws {@link IllegalStateException} if there is any problem accessing the legacy message API using reflection
*/
public static DataType getOutboundPropertyDataType(Message message, String name) {
try {
Method method = message.getClass().getMethod("getOutboundPropertyDataType", String.class);
method.setAccessible(true);
return (DataType) method.invoke(message, name);
} catch (Exception e) {
throw new IllegalStateException(LEGACY_MESSAGE_API_ERROR, e);
}
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DefaultMuleEventTestCase method setSessionVariableDefaultDataType.
@Test
public void setSessionVariableDefaultDataType() throws Exception {
muleEvent.getSession().setProperty(PROPERTY_NAME, PROPERTY_VALUE);
DataType dataType = muleEvent.getSession().getPropertyDataType(PROPERTY_NAME);
assertThat(dataType, like(String.class, MediaType.ANY, null));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DefaultMuleEventTestCase method setSessionVariableCustomDataType.
@Test
public void setSessionVariableCustomDataType() throws Exception {
DataType dataType = DataType.builder().type(String.class).mediaType(APPLICATION_XML).charset(CUSTOM_ENCODING).build();
muleEvent.getSession().setProperty(PROPERTY_NAME, PROPERTY_VALUE, dataType);
DataType actualDataType = muleEvent.getSession().getPropertyDataType(PROPERTY_NAME);
assertThat(actualDataType, like(String.class, APPLICATION_XML, CUSTOM_ENCODING));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method returnsDataType.
@Test
public void returnsDataType() throws Exception {
DataType dataType = DataType.builder().type(String.class).mediaType(JSON).charset(UTF_16.name()).build();
CoreEvent event = createEvent(TEST_MESSAGE, dataType);
TypedValue typedValue = evaluateTyped("payload", event);
assertThat((String) typedValue.getValue(), equalTo(TEST_MESSAGE));
assertThat(typedValue.getDataType(), like(String.class, JSON, UTF_16));
}
Aggregations