Mule-将参数传递给datamapper并在xpath条件下访问它们 [英] Mule - Pass Parameters to datamapper and access them in xpath conditions

查看:166
本文介绍了Mule-将参数传递给datamapper并在xpath条件下访问它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将参数传递到m子中的datamapper并访问它们. (在XSLT中,我将它们作为上下文参数传递,在param中接收它们并使用$符号进行访问).我需要在datamapper中做同样的事情.任何建议/链接/示例,不胜感激.

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.

方法1: 我们在datamapper中使用invokeTransformer方法

Approach1: We are using invokeTransformer method in datamapper

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

此MyTransformer是一个Java组件,该默认方法已被覆盖.

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);

但是,问题是我不是从m子流中调用此变压器.但是,从datamapper调用它.因此,消息"自变量没有被传递.因此,无法检索该会话变量以返回到数据映射器.有没有办法发送此参数(来自datamapper的MuleMessage)?

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)?

推荐答案

您可以在DataMapper中使用输入参数,然后在输出中引用它们:

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>

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

output.myField = inputArguments.testvar;

通过输入端的绿色加号图标添加DataMapper GUI中可用的输入参数.

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

这篇关于Mule-将参数传递给datamapper并在xpath条件下访问它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆