Mule - Pass Parameters to datamapper and access th

2019-03-05 12:09发布

问题:

How to pass parameters to datamapper in mule and access them. (In XSLT, I pass them as context parameters, receive them in param and access using $ symbol). I need to do the same thing in datamapper. Any suggestions/links/example are appreciated.

Approach1: We are using invokeTransformer method in datamapper

output.abc= invokeTransformer("MyTransformer",input.abcdef);

This MyTransformer is a java component which has this default method overridden.

@Override
public String transformMessage(MuleMessage message, String outputEncoding)
        throws TransformerException {
System.out.println("Inside transformer" +message.getProperty    ("sessionVariable1",PropertyScope.SESSION));
    return message.getProperty("sessionVariable1",PropertyScope.SESSION);

But, the problem is I am not calling this transformer from mule flow. But, invoking it from datamapper. Hence the argument 'message' does not get passed. So, Unable to retrive that session variable to return to datamapper. Is there a way to send this argument(MuleMessage from datamapper)?

回答1:

You can use input arguments with DataMapper and then refer to them in the output:

<set-variable variableName="testvar" value="value of testvar"/>
<data-mapper:transform config-ref="new_mapping_grf"">
    <data-mapper:input-arguments>
        <data-mapper:input-argument key="testvar">#[flowVars['testvar']]</data-mapper:input-argument>
    </data-mapper:input-arguments>
</data-mapper:transform>

and

output.myField = invokeTransformer("MyTransformer",inputArguments.testvar);

or

output.myField = inputArguments.testvar;

Adding input arguments available in the DataMapper GUI through the input side green plus icon.