Sample 390: Introduction to the XQuery Mediator

<definitions xmlns=""> <!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --> <registry provider="org.apache.synapse.registry.url.SimpleURLRegistry"> <!-- the root property of the simple URL registry helps resolve a resource URL as root + key --> <parameter name="root">file:repository/conf/sample/resources/</parameter> <!-- all resources loaded from the URL registry would be cached for this number of milli seconds --> <parameter name="cachableDuration">15000</parameter> </registry> <localEntry key="xquery-key-req" src="file:repository/conf/sample/resources/xquery/xquery_req.xq"/> <proxy name="StockQuoteProxy"> <target> <inSequence> <property name="body" expression="$body/child::*[position()=1]"/> <xquery key="xquery-key-req"> <variable name="payload" type="ELEMENT"/> </xquery> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </inSequence> <outSequence> <out> <xquery key="xquery/xquery_res.xq"> <variable name="payload" type="ELEMENT"/> <variable xmlns:m0="http://services.samples" name="code" type="STRING" expression="self::node()//m0:return/m0:symbol/child::text()"/> <variable xmlns:m0="http://services.samples" name="price" type="DOUBLE" expression="self::node()//m0:return/m0:last/child::text()"/> </xquery> <send/> </out> </outSequence> </target> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions>


Demonstrate how to use the XQuery mediator for message content transformations


  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Start Synapse using the configuration numbered 390 (repository/conf/sample/synapse_sample_390.xml)
    Unix/Linux: sh -sample 390
    Windows: synapse.bat -sample 390

Executing the Client

This example uses the XQuery mediator to perform transformations. This sample behaves the same as sample 8 and the only difference is that this sample uses XQuery instead of XSLT for transformation.

Send a custom quote request to Synapse as follows.

ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=customquote

Request is transformed into a standard stock quote request by the XPery mediator. The XQuery definition is loaded through a local entry. The response from Axis2 is transformed back to a custom quote response. In this case the XQuery definition is loaded from the registry.

Back to Catalog