Search in sources :

Example 1 with MuleClientFlowConstruct

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;
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MuleClientFlowConstruct(org.mule.runtime.core.privileged.client.MuleClientFlowConstruct) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) I18nMessage(org.mule.runtime.api.i18n.I18nMessage)

Aggregations

ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)1 I18nMessage (org.mule.runtime.api.i18n.I18nMessage)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 Message (org.mule.runtime.api.message.Message)1 DataType (org.mule.runtime.api.metadata.DataType)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)1 MuleClientFlowConstruct (org.mule.runtime.core.privileged.client.MuleClientFlowConstruct)1