wso2 对过滤中介的响应 属性
wso2 response property to filter mediator
我正在尝试对我的响应使用过滤器中介来检查响应是否是一个集合。
所以我在这里做的是检查belongs_to_collection中的元素id是否是数字
<property expression="/soapenv:Envelope/soapenv:Body/root:movie/belongs_to_collection/id" name="collection" scope="default" type="STRING"/>
<filter description="" regex="[0-9]+" source="get-property('collection')">...</filter>
这是我的完整 api 配置
http://pastebin.com/QA3GCd1W
这是要过滤的响应
http://pastebin.com/0dxweJu3
如果您在表达式中使用名称空间前缀,则需要定义这些名称空间。例如:
<property expression="/root:movie/belongs_to_collection/id"
name="collection" scope="default" type="STRING" xmlns:root="www.wso2esb.com"/>
然而,我在使用您的 API 时看到的响应是
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<jsonObject>
<belongs_to_collection>
<id>8650</id>
...
您的根元素是 soapenv:Envelope 标记,因此您不必再将其放入表达式中。开头的 / 指的是根元素。之后的任何内容都指代根元素中的元素。
所以表达式应该如下:
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
name="collection" expression="/soapenv:Body/jsonObject/belongs_to_collection/id"
scope="default" type="STRING"/>
如果你不想处理命名空间,你可以这样使用local-name()
。
<property name="collection"
expression="//*[local-name()='belongs_to_collection']/*[local-name()='id']/text()"
scope="default"
type="STRING"/>
我正在尝试对我的响应使用过滤器中介来检查响应是否是一个集合。
所以我在这里做的是检查belongs_to_collection中的元素id是否是数字
<property expression="/soapenv:Envelope/soapenv:Body/root:movie/belongs_to_collection/id" name="collection" scope="default" type="STRING"/>
<filter description="" regex="[0-9]+" source="get-property('collection')">...</filter>
这是我的完整 api 配置 http://pastebin.com/QA3GCd1W
这是要过滤的响应 http://pastebin.com/0dxweJu3
如果您在表达式中使用名称空间前缀,则需要定义这些名称空间。例如:
<property expression="/root:movie/belongs_to_collection/id"
name="collection" scope="default" type="STRING" xmlns:root="www.wso2esb.com"/>
然而,我在使用您的 API 时看到的响应是
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<jsonObject>
<belongs_to_collection>
<id>8650</id>
...
您的根元素是 soapenv:Envelope 标记,因此您不必再将其放入表达式中。开头的 / 指的是根元素。之后的任何内容都指代根元素中的元素。
所以表达式应该如下:
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
name="collection" expression="/soapenv:Body/jsonObject/belongs_to_collection/id"
scope="default" type="STRING"/>
如果你不想处理命名空间,你可以这样使用local-name()
。
<property name="collection"
expression="//*[local-name()='belongs_to_collection']/*[local-name()='id']/text()"
scope="default"
type="STRING"/>