Using XPath functions in filter mediator

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 06:32:10

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/15000596/using-xpath-functions-in-filter-mediator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!