<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~  Licensed to the Apache Software Foundation (ASF) under one
  ~  or more contributor license agreements.  See the NOTICE file
  ~  distributed with this work for additional information
  ~  regarding copyright ownership.  The ASF licenses this file
  ~  to you under the Apache License, Version 2.0 (the
  ~  "License"); you may not use this file except in compliance
  ~  with the License.  You may obtain a copy of the License at
  ~ 
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->
  
<!-- Invoking remote EJB Stateless Session Beans from Synapse. -->
<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()}"/>
		<respond/>
            </inSequence>
        </target>
    </proxy>

</definitions>
