use of org.mule.runtime.core.privileged.client.MuleClientFlowConstruct in project mule by mulesoft.
the class AbstractMessageTransformer method transform.
@Override
public final Object transform(Object src, Charset enc, CoreEvent event) throws MessageTransformerException {
DataType sourceType = DataType.fromType(src.getClass());
if (!isSourceDataTypeSupported(sourceType)) {
if (isIgnoreBadInput()) {
logger.debug("Source type is incompatible with this transformer and property 'ignoreBadInput' is set to true, so the transformer chain will continue.");
return src;
} else {
I18nMessage msg = CoreMessages.transformOnObjectUnsupportedTypeOfEndpoint(getName(), src.getClass());
throw new MessageTransformerException(msg, this, event.getMessage());
}
}
if (logger.isDebugEnabled()) {
logger.debug(format("Applying transformer %s (%s)", getName(), getClass().getName()));
logger.debug(format("Object before transform: %s", StringMessageUtils.toString(src)));
}
Message message;
if (src instanceof Message) {
message = (Message) src;
} else // TODO MULE-9342 Clean up transformer vs message transformer confusion
if (src instanceof CoreEvent) {
event = (CoreEvent) src;
message = event.getMessage();
} else if (muleContext.getConfiguration().isAutoWrapMessageAwareTransform()) {
message = of(src);
} else {
if (event == null) {
throw new MessageTransformerException(CoreMessages.noCurrentEventForTransformer(), this, null);
}
message = event.getMessage();
}
Object result;
// TODO MULE-9342 Clean up transformer vs message transformer confusion
if (event == null) {
MuleClientFlowConstruct flowConstruct = new MuleClientFlowConstruct(muleContext);
ComponentLocation location = getLocation() != null ? getLocation() : fromSingleComponent("AbstractMessageTransformer");
event = InternalEvent.builder(create(flowConstruct, location)).message(message).build();
}
result = transformMessage(event, enc);
if (logger.isDebugEnabled()) {
logger.debug(format("Object after transform: %s", StringMessageUtils.toString(result)));
}
result = checkReturnClass(result, event);
return result;
}
Aggregations