【发布时间】:2014-02-09 07:31:16
【问题描述】:
如何确定消息包含特定元素?如果消息不包含特定元素,我想丰富消息,但我不知道如何确定?
谢谢。
【问题讨论】:
如何确定消息包含特定元素?如果消息不包含特定元素,我想丰富消息,但我不知道如何确定?
谢谢。
【问题讨论】:
您可以使用filter mediator 执行基于内容的调解。以下示例显示了您的用例。 (1) 使用 xpath 匹配完成过滤。它搜索不出现 XPath //p:echoString/test,并基于此执行丰富的中介。以下皂体将匹配过滤器。 (2)
(1)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="messageFilter" transports="http https" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="full" separator=","/>
<filter xpath="not(//p:echoString/test)" xmlns:p="http://echo.services.core.carbon.wso2.org" >
<then>
<log separator=",">
<property name="XPath Matched" value="true"/>
</log>
<enrich>
<source clone="true" xpath="//p:echoString/in"/>
<target type="property" property="ORIGINAL_REQ"/>
</enrich>
<log separator=",">
<property name="ORIGINAL_REQ" expression="get-property('ORIGINAL_REQ')"/>
</log>
</then>
<else>
<log separator=",">
<property name="XPath Matched" value="false"/>
</log>
</else>
</filter>
<send>
<endpoint>
<address uri="http://localhost:9763/services/echo"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" separator=",">
<property name="OUT-SEQUENCE" value="property_value"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
(2)
<body>
<p:echoString xmlns:p="http://echo.services.core.carbon.wso2.org">
<in>123</in>
<test>testing-node</test>
</p:echoString>
</body>
【讨论】: