You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSO2 Call Template Mediator如何获取变量值?

在WSO2 Call Template Mediator中传递动态参数的正确方式

你遇到的核心问题是<with-param>不能同时指定value和expression属性——当需要传递动态值时,只需保留expression即可(部分IDE的语法校验可能误报,但WSO2运行时完全支持该写法)。以下是两种可行解决方案:

方案1:用fn:concat()直接拼接静态文本与动态值

通过XPath的fn:concat()函数,把静态字符串和属性值拼接后传入模板,无需保留value字段:

<property expression="$ctx:variable" name="test" type="STRING"/>
<call-template target="HelloWorld_Logger">
    <with-param name="message" expression="fn:concat('VARIABLE: ', $ctx:test)"/>
</call-template>

方案2:预先拼接参数值再传递

如果不想在expression中直接拼接,可以先把格式化后的结果存入新属性,再传递给模板:

<property expression="$ctx:variable" name="test" type="STRING"/>
<property expression="fn:concat('VARIABLE: ', $ctx:test)" name="formattedMessage" type="STRING"/>
<call-template target="HelloWorld_Logger">
    <with-param name="message" expression="$ctx:formattedMessage"/>
</call-template>

关键说明

  • <with-param>的value仅用于静态字符串,expression用于动态求值,两者不可同时使用。
  • 若IDE因仅使用expression报错,可忽略该提示——WSO2 ESB/APIM部署后能正常解析并获取属性值。

内容的提问来源于stack exchange,提问作者Marco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 19:55:19