Reputation: 567
I'm trying to use the Filter mediator for my response to check whether the response is a collection.
So what I did here is to check whether the element id in belongs_to_collection is a numeric
<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>
Here's my full api config http://pastebin.com/QA3GCd1W
and here's the response to be filter http://pastebin.com/0dxweJu3
Upvotes: 2
Views: 628
Reputation: 12513
If you don't want to deal with namespaces, you can use local-name()
like this.
<property name="collection"
expression="//*[local-name()='belongs_to_collection']/*[local-name()='id']/text()"
scope="default"
type="STRING"/>
Upvotes: 2
Reputation: 2653
If you use namespace prefixes in your expression you need to define those namespaces. For example:
<property expression="/root:movie/belongs_to_collection/id"
name="collection" scope="default" type="STRING" xmlns:root="www.wso2esb.com"/>
The response I see when using your API however is
<?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>
...
Your root element is the soapenv:Envelope tag, so you don't have to put that in your expression anymore. The / at the beginning refers to the root element. Anything after that refers to elements inside your root element.
So the expression should be as follows:
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
name="collection" expression="/soapenv:Body/jsonObject/belongs_to_collection/id"
scope="default" type="STRING"/>
Upvotes: 2