Question

In my inSequence of a proxy I'm filtering with a xpath query in the filter mediator. But I want to use XPath functions like exists() or count(). But this does not work and always creates an exception. Here my example:

<filter xpath="count($body/myElement)>2">
 <drop/>
</filter>

And the exception I always get:

ERROR - FilterMediator Error evaluating XPath expression : n:exists($body/avintis:Exception)
        org.jaxen.UnresolvableException: No Such Function exists

How can I make these functions work?

Was it helpful?

Solution

You can use xpath functions with filter mediator as modifying your synapse segment as shown below.

<filter xpath="fn:exists($body/myElement)">
 <drop/>
</filter>

You can refer for Sample 156: Service Integration with specifying the receiving sequence available at [1] for further sample.

 <filter xpath="fn:number(get-property('SIMPLE_SER_AMT')) > fn:number(get-property('SECURE_SER_AMT'))">

[1]. http://wso2.org/project/esb/java/4.0.3/docs/samples/proxy_samples.html

Thank You, Dharshana

OTHER TIPS

For those wondering how to use fn:count, you could try:

<property name="itemCount" expression="fn:count(//*[local-name()='item'])"/>
<filter xpath="fn:number(get-property('itemCount')) > fn:number(0)">

This works for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top