Using XPath 2.0 functions in WSO2 EI

By default XPath 2.0 functions are disabled in WSO2 EI. In this post, we will look at how can we use them in EI 6 and EI7.

Enable XPath 2.0 in WSO2 EI 7

  1. Go to <PRODUCT-HOME>/conf/deployment.toml file and add the following.
[mediation]
synapse.enable_xpath_dom_failover="true"

Enable XPath 2.0 in WSO2 EI 6

  1. Go to <PRODUCT-HOME>/conf/synapse.properties file uncomment the following.
synapse.xpath.dom.failover.enabled=true

Example

The QueueURL contains QueueId and the QueueName. Assume we need to extract only the QueueId which is ‘728847610545’.

We can simply substring the URL by using XPath 2.0 functions. You can further read about it by referring to this document.

We can first use a Property Mediator to copy the URL value to a property extracting from the URL.

<property expression="json-eval($.queueURL)" name="queueURL" scope="default" type="STRING"/>

Then we can use the substring method to extract the QueueID only.

<property expression="fn:substring($ctx:queueURL,39,12)" name="queueId" scope="default" type="STRING" xmlns:fn="http://www.w3.org/2005/xpath-functions"/>

First, we need to provide the string value, then the starting position which we need to start it extracted, and finally the length of the word.

The complete API is as below.

In the WSO2 Carbon log, you can see the following log is printed.

[2020-04-10 00:04:28,094]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - QueueID = 728847610545

Senior Software Engineer — QA at WSO2