use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DataTypeBuilderTestCase method cglibClassProxy.
@Test
public void cglibClassProxy() {
final Message muleMessageProxy = mock(MessageTestImpl.class);
final DataType dataType = DataType.fromObject(muleMessageProxy);
assertThat(dataType.getType(), is(equalTo(MessageTestImpl.class)));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DataTypeBuilderTestCase method cacheClean.
@Test
public void cacheClean() throws InterruptedException, ClassNotFoundException {
ClassLoader custom = new ClassLoader(this.getClass().getClassLoader()) {
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (Message.class.getName().equals(name)) {
byte[] classBytes;
try {
classBytes = toByteArray(this.getClass().getResourceAsStream("/org/mule/runtime/api/message/Message.class"));
return this.defineClass(null, classBytes, 0, classBytes.length);
} catch (Exception e) {
return super.loadClass(name);
}
} else {
return super.loadClass(name);
}
}
};
PhantomReference<ClassLoader> clRef = new PhantomReference<>(custom, new ReferenceQueue<>());
DataType.builder().type(custom.loadClass(Message.class.getName())).build();
custom = null;
new PollingProber(GC_POLLING_TIMEOUT, DEFAULT_POLLING_INTERVAL).check(new JUnitLambdaProbe(() -> {
System.gc();
assertThat(clRef.isEnqueued(), is(true));
return true;
}, "A hard reference is being mantained to the type of the DataType."));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DataTypeBuilderTestCase method cglibInterfaceProxy.
@Test
public void cglibInterfaceProxy() {
final Message muleMessageProxy = mock(Message.class);
final DataType dataType = DataType.fromObject(muleMessageProxy);
assertThat(dataType.getType(), is(equalTo(Message.class)));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class AbstractTransformer method transform.
@Override
public Object transform(Object src, Charset enc) throws TransformerException {
Object payload = src;
DataType sourceType;
if (src instanceof Message) {
Message message = (Message) src;
if ((!isSourceDataTypeSupported(DataType.MULE_MESSAGE, true) && !(this instanceof AbstractMessageTransformer))) {
payload = message.getPayload().getValue();
sourceType = message.getPayload().getDataType();
} else {
sourceType = DataType.fromObject(payload);
}
} else {
sourceType = DataType.fromObject(payload);
}
if (!isSourceDataTypeSupported(sourceType)) {
I18nMessage msg = transformOnObjectUnsupportedTypeOfEndpoint(getName(), payload.getClass());
// / FIXME
throw new TransformerException(msg, this);
}
if (logger.isDebugEnabled()) {
logger.debug(format("Applying transformer %s (%s)", getName(), getClass().getName()));
logger.debug(format("Object before transform: %s", StringMessageUtils.toString(payload)));
}
Object result = doTransform(payload, enc);
if (logger.isDebugEnabled()) {
logger.debug(format("Object after transform: %s", StringMessageUtils.toString(result)));
}
checkTransformerReturnClass(this, result);
return result;
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class EventToMessageSequenceSplittingStrategy method split.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public MessageSequence<?> split(CoreEvent event) {
if (expressionSplitterStrategy.hasDefaultExpression()) {
Message msg = event.getMessage();
Object payload = msg.getPayload().getValue();
if (payload instanceof MessageSequence<?>) {
return ((MessageSequence<?>) payload);
}
if (payload instanceof Iterator<?>) {
return new IteratorMessageSequence(((Iterator<Object>) payload));
}
if (payload instanceof Collection) {
return new CollectionMessageSequence(copyCollection((Collection) payload));
} else if (payload instanceof CursorIteratorProvider) {
return new IteratorMessageSequence(((CursorIteratorProvider) payload).openCursor());
} else if (payload instanceof Iterable<?>) {
return new IteratorMessageSequence(((Iterable<Object>) payload).iterator());
} else if (payload instanceof Object[]) {
return new ArrayMessageSequence((Object[]) payload);
} else if (payload instanceof NodeList) {
return new NodeListMessageSequence((NodeList) payload);
} else if (payload instanceof Map<?, ?>) {
List<Object> list = new LinkedList<>();
Set<Map.Entry<?, ?>> set = ((Map) payload).entrySet();
for (Map.Entry<?, ?> entry : set) {
list.add(new ImmutableEntry<>(entry));
}
return new CollectionMessageSequence(list);
}
}
try {
Iterator<TypedValue<?>> valueIterator = expressionSplitterStrategy.split(event);
if (hasMelExpression(expressionSplitterStrategy.getExpression())) {
List<Object> iteratorCollection = new ArrayList<>();
valueIterator.forEachRemaining(iteratorCollection::add);
return new CollectionMessageSequence<>(iteratorCollection);
}
return new IteratorMessageSequence(valueIterator);
} catch (ExpressionRuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalArgumentException(format("Could not split result of expression %s. The provided value is not instance of %s java " + "type or it's not a collection in any other format", expressionSplitterStrategy.getExpression(), new Class[] { Iterable.class, Iterator.class, MessageSequence.class, Collection.class }), e);
}
}
Aggregations