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.

Image for post
Image for post
  1. Download WSO2 EI 7 from here.
  2. Go to <PRODUCT-HOME>/conf/deployment.toml file and add the following.
  1. Download WSO2 EI 6 from here.
  2. Go to <PRODUCT-HOME>/conf/ file uncomment the following.

Assume we get the following request payload from the user.

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=""/>

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

Written by

Senior Software Engineer — QA at WSO2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store