Search code examples
wso2integrationwso2-data-services-serverwso2-esb

How exactly works this enrich mediator chained after a callou mediator in this ESB API flow?


I am very new in WSO2 and I am working on a EI project that involves ESB and DSS components.

I have the following doubt about the correct meaning of this section of an API flow:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="cropNamesSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">

    <payloadFactory media-type="xml">
        <format>
            <ds:FindCropNames xmlns:ds="http://ws.wso2.org/dataservice">
                <ds:sampleId>$1</ds:sampleId>
            </ds:FindCropNames>
        </format>

        <args>
            <arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:sample_id/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
        </args>
    </payloadFactory>

    <header name="Action" scope="default" value="urn:FindCropNames"/>

    <callout endpointKey="prgfasEndpoint">
        <source xmlns:ns="http://org.apache.synapse/xsd" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>

        <target xmlns:ns="http://org.apache.synapse/xsd" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
    </callout>

    <enrich>
        <source clone="true" type="envelope"/>
        <target property="cropNames" type="property"/>
    </enrich>

    <log level="custom">
        <property expression="$ctx:cropNames" name="crop names"/>
    </log>

    ........................................................................
    ........................................................................
    DO SOMETHING ELSE
    ........................................................................
    ........................................................................

In this code I am performing the following operation:

  • The first payloadFactory mediator is used to create a message containing the <ds_sampleId>...</ds_sampleId> parameter that is retrieved by the related XPATH expression into the <args>...</args>. This message represents a request that I wil send to a DSS service.

  • Then I am specifying an header with name="Action" that specify the name of the DSS service used to obtain some data from the DB (the service name is urn:FindCropNames.

  • Then I am using the callout mediator to perform the request toward the previous web service.

My doubts are related to the following enrich mediator, this one:

<enrich>
    <source clone="true" type="envelope"/>
    <target property="cropNames" type="property"/>
</enrich>

In many example I often see that after calling a web service using a callout mediator is chaned an enrich mediator.

From what I am understandint the meaning of this specific mediator (in the posted case) is that I am tacking the envelope of the web service response and I am copying it into a new property name cropNames that then I can use in my flows, for example I can log the content of this property chaining:

<log level="custom">
    <property expression="$ctx:cropNames" name="crop names"/>
</log>

Is it this interpretation correct or am I missing something?


Solution

  • This is correct, a property of type "OM" (xml) is created, it's name is "cropNames" and it belongs to the default scope (synapse scope) and you can access it with thoses xpath : get-property('cropNames') or $ctx:cropNames