Mule - Pass Parameters to datamapper and access them in xpath conditions

随声附和 提交于 2019-12-04 06:55:31

问题


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.



来源:https://stackoverflow.com/questions/22242329/mule-pass-parameters-to-datamapper-and-access-them-in-xpath-conditions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!