Sample 391: Using External XML Documents in the XQuery Mediator

<definitions xmlns="http://ws.apache.org/ns/synapse"> <!-- 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> <proxy name="StockQuoteProxy"> <target> <inSequence> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </inSequence> <outSequence> <out> <xquery key="xquery/xquery_commisson.xq"> <variable name="payload" type="ELEMENT"/> <variable name="commission" type="ELEMENT" key="misc/commission.xml"/> </xquery> <send/> </out> </outSequence> </target> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions>

Objective

Demonstrate how to import external XML documents into the XQuery engine using the XQuery mediator

Pre-requisites

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

Executing the Client

In this sample, data from commission.xml file is used inside XQuery. The stock quote price from the response and commission from the commission.xml document will be added and given as a new price value.

Try out this sample by invoking the proxy service as follows.

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

Back to Catalog