简体   繁体   中英

WSO2 ESB iterate mediator joining

i'm facing some problems with this process.. let me explain:

i want to call two services and join the responses in this order:

i have the first service's response:

<locations xmlns="http://ssocial.com/traceit/services/location">
        <location>
            <latitude>-33.45209980</latitude>
            <longitude>-70.66241990</longitude>
            <altitude>0.0</altitude>
            <creation>2016-09-04T14:59:48.000-03:00</creation>
            <updated>2016-09-04T14:59:48.000-03:00</updated>
            <deviceId>25</deviceId>
        </location>
        <location>
            <latitude>-33.45149521</latitude>
            <longitude>-70.66146224</longitude>
            <altitude>817.0</altitude>
            <creation>2016-09-04T13:18:43.000-03:00</creation>
            <updated>2016-09-04T13:18:43.000-03:00</updated>
            <deviceId>25</deviceId>
        </location>
    </locations>

then i have the secon service's response :

<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
    <id>1</id>
    <name>MOBILE</name>
</type>


And then, the final response that i would like to have is :

<locations xmlns="http://ssocial.com/traceit/services/location">
        <location>
            <latitude>-33.45209980</latitude>
            <longitude>-70.66241990</longitude>
            <altitude>0.0</altitude>
            <creation>2016-09-04T14:59:48.000-03:00</creation>
            <updated>2016-09-04T14:59:48.000-03:00</updated>
            <deviceId>25</deviceId>
            <device xmlns="http://ssocial.com/traceit/services/device">
                <id>25</id>
                <code>mobile_02</code>
                <type>
                    <id>1</id>
                    <name>MOBILE</name>
                </type>
            </device>
        </location>
        <location>
            <latitude>-33.45149521</latitude>
            <longitude>-70.66146224</longitude>
            <altitude>817.0</altitude>
            <creation>2016-09-04T13:18:43.000-03:00</creation>
            <updated>2016-09-04T13:18:43.000-03:00</updated>
            <deviceId>25</deviceId>
            <device xmlns="http://ssocial.com/traceit/services/device">
                <id>25</id>
                <code>mobile_02</code>
                <type>
                    <id>1</id>
                    <name>MOBILE</name>
                </type>
            </device>
        </location>
    </locations>

i'm really having lot of troubles trying to join both responses like that, and this is my sequence in wso2:

<sequence name="getDeviceInfoByLocationProcess" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="count(//ns1:locations/ns1:location)" name="LOCATIONS_COUNT" scope="default" type="STRING" xmlns:ns1="http://ssocial.com/traceit/services/location"/>
<iterate description="" expression="//ns1:locations/ns1:location/ns1:deviceId" id="LOCATIONS_ITERATOR" xmlns:ns1="http://ssocial.com/traceit/services/location">
    <target>
        <sequence>
            <property description="device_id" expression="//ns1:deviceId" name="device_id" scope="default" type="STRING"/>
            <sequence key="getDeviceInfoProcess"/>
        </sequence>
    </target>
</iterate>
<log level="custom">
    <property expression="//ns1:locations" name="LOCATIONS" xmlns:ns1="http://ssocial.com/traceit/services/location"/>
    <property expression="//ns2:device" name="DEVICE_INFO" xmlns:ns2="http://ssocial.com/traceit/services/device"/>
</log>
<property name="ECNCLOSING_ELEMENT" scope="default">
    <wrapper xmlns=""/>
</property>
<aggregate id="AGG_01">
    <completeCondition>
        <messageCount max="-1" min="{get-property('LOCATIONS_COUNT')}"/>
    </completeCondition>
    <onComplete expression="//ns2:device" xmlns:ns2="http://ssocial.com/traceit/services/device">
        <log level="full">
            <property expression="$ctx:LOCATIONS_COUNT" name="COUNTER"/>
            <property expression="$ctx:ECNCLOSING_ELEMENT" name="ENCLOSING"/>
        </log>
        <call/>
    </onComplete>
</aggregate>

and actually with this sequence, i'm just getting this:

<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
    <id>1</id>
    <name>MOBILE</name>
</type>


In advance , thank you very much for the help

I can't see the content of "getDeviceInfoProcess" sequence, but I guess your are using call mediator. So, as a result of those requests (multiple requests because of iterate mediator), you receive some responses and that what you have to deal with in the rest of the initial mediation : aggregate offers you a way to wait for all the responses, but the initial message is lost : you should save it in a property (type OM) and use something like payloadMediator inside aggregate/onComplete to compose the final message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM