<definitions xmlns="http://ws.apache.org/ns/synapse">
<proxy name="StoreLocatorProxy" transports="https http" startOnLoad="true" trace="disable">
<target>
<!-- First call StoreLocator#getClosestStore(), then call StoreRegistry#getStoreById() with the result. -->
<inSequence>
<bean action="CREATE" class="samples.bean.Location" var="loc"/>
<bean action="SET_PROPERTY" var="loc" property="latitude" value="{//m:latitude}" xmlns:m="http://services.samples"/>
<bean action="SET_PROPERTY" var="loc" property="longitude" value="{//m:longitude}" xmlns:m="http://services.samples"/>
<ejb class="samples.ejb.StoreLocator" beanstalk="demo" method="getClosestStore" target="store_id" jndiName="StoreLocatorBean/remote">
<args>
<arg value="{get-property('loc')}"/>
</args>
</ejb>
<ejb class="samples.ejb.StoreRegistry" beanstalk="demo" method="getStoreById" target="store" jndiName="StoreRegistryBean/remote">
<args>
<arg value="{get-property('store_id')}"/>
</args>
</ejb>
<!-- Prepare the response. -->
<enrich>
<source type="inline" clone="true">
<getClosestStoreResponse xmlns="">
<store>
<name>?</name>
<address>?</address>
<phone>?</phone>
</store>
</getClosestStoreResponse>
</source>
<target type="body"/>
</enrich>
<bean action="GET_PROPERTY" var="store" property="name" target="{//store/name/text()}"/>
<bean action="GET_PROPERTY" var="store" property="address" target="{//store/address/text()}"/>
<bean action="GET_PROPERTY" var="store" property="phoneNo" target="{//store/phone/text()}"/>
<!-- Send the response back to the client of the ESB. -->
<respond/>
</inSequence>
</target>
</proxy>
</definitions>
Executing the Client
Send the following request to http://localhost:8280/services/StoreLocatorProxy
using a tool such at TCPMon or curl.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<getClosestStore xmlns="http://services.samples">
<latitude>78</latitude>
<longitude>8</longitude>
</getClosestStore>
</soapenv:Body>
</soapenv:Envelope>
When the StoreLocatorProxy receives the request, it first creates an instance of
samples.bean.Location using the Bean mediator.
Then, it sets the properties of the newly created bean with the values
extracted from the incoming SOAP message, again using the Bean mediator.
The subsequent EJB mediator invokes the getClosestStore() method on the remote stateless
session bean, StoreLocator, with the previously populated
Location object as an argument and stores the result in the store_id message context
property. Another EJB mediator that follows calls the getStoreById() method
on a second stateless session bean,StoreRegistry, to obtain store details encapsulated in
a JavaBean (an instance of samples.bean.Store) and stores this resulting bean in a message context
property named store. The demo beanstalk provides all necessary configurations
needed for the two remote EJB invocations.
Finally, Enrich and Bean mediators are used to build the response message extracting properties from
the JavaBean stored in the store message context property.
A sample response is shown below.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<getClosestStoreResponse>
<store>
<name>Kadawatha</name>
<address>253, Kandy Road, Kadawatha</address>
<phone>0112990789</phone>
</store>
</getClosestStoreResponse>
</soapenv:Body>
</soapenv:Envelope>