wso2 - WSO2 EI 新的 xml 标签使用 Enrich 调解器和当 xml 标签动态获取时
问题描述
是否可以使用丰富的中介将新的 xml 标记添加到 xml 有效负载。
我的样本有效载荷 -
<courses>
<id>181</id>
<formatted_name>Learning</formatted_name>
<score>0</score>
<status>in_progress</status>
<issued_certificate />
<from_timestamp>1626083705</from_timestamp>
<to_timestamp />
</courses>
新标签将是
<link> www.google.com </link>
我不能使用内联作为源,因为链接是动态获取的。所以我将新标签添加到有效负载,然后是属性。
<payloadFactory media-type="xml">
<format>
<link xmlns="">$1</link>
</format>
<args>
<arg evaluator="xml" expression="get-property('login_link')"/>
</args>
</payloadFactory>
<property description="Get login link payload" expression="//root/*" name="login_link_xml" scope="default" type="STRING"/>
// get original payload back
<enrich description="Restore original payload">
<source clone="false" property="course_payload" type="property"/>
<target type="body"/>
</enrich>
// assign property as a new node inside the courses
<enrich>
<source clone="true" property="login_link_xml" type="property"/>
<target action="child" type ="custom" xpath="//courses"/>
</enrich>
这在丰富后给出了相同的有效载荷
解决方案
你可以用一些不同的方式来做。使用 xpath 表达式和函数创建您的“标签”作为属性类型 OM: concat,带编码字符
<property name="my_link" value="devintegra.com" scope="default" type="STRING"/>
<property name="linkNode"
type="OM"
expression="concat('<link>',get-property('my_link'),'</link>')"
scope="default" />
有了这个属性,你可以丰富你的身体:
<enrich>
<source type="property" clone="true" property="linkNode"/>
<target action="child" xpath="//courses"/>
</enrich>
这应该可以按您的预期工作。
推荐阅读
- apache - 如何在我的 htaccess 重写中使参数可选?
- java - 批处理循环执行java - 如何取消引用变量作为命令的一部分
- sql-server - Azure SQL 的 SUSER_SID 支持
- r - R在特定位置将元素添加到Dataframe
- assembly - 68000汇编语言怎么定义一个枚举?
- go - 在 Go 中返回带参数的函数的函数?
- java - 选项卡在 Java 中是如何工作的?
- data-modeling - 如何在hybris灵活搜索中排除子类型
- php - 正则表达式不包含结尾和开头不同的字符串
- nginx - 如何在安装了 Plesk 的服务器上为 Flask 应用程序设置 nginx