Search code examples
wso2esbwso2-enterprise-integratoreiwso2-esb

WSO2 EI/ESB: Append payload from Payload Factory to Path Parameter in backend call


I have a payload factory like below:

<payloadFactory media-type="json">
    <format>[{"value" : 1},{"value" : 2},{"value" : 3}]</format>
    <args/>
</payloadFactory>

<iterate expression="json-eval($)" id="iterate-over-nameAddress">
    <call>
        <endpoint>
            <http method="get" uri-template="https://backend.com/names/value+{uri.var.value}/address"/>
        </endpoint>
    </call>
</iterate>

In the above code, in backend call, I want the path-parameter "value+{uri.var.value}" to change dynamically according to the iterate expression. The path param should change like value1, value2, value3... for every iteration.

How do I implement this?


Solution

  • Since you are iterating with a dummy payload, you can try the following. Instead of having the values as 1, 2, 3 have the entire value thing in the dummy payload itself.

    <payloadFactory media-type="json">
            <format>[{"value" : "value1"},{"value" : "value2"},{"value" : "value3"}]</format>
            <args/>
         </payloadFactory>
         <iterate expression="json-eval($)">
            <target>
               <sequence>
                  <property name="uri.var.value" expression="json-eval($.value)"/>
                  <call>
                     <endpoint>
                         <http method="get" uri-template="http://www.mocky.io/v2/5185415ba171ea3a00704eed/{uri.var.value}/address"/>
                     </endpoint>
                 </call>
               </sequence>
            </target>
         </iterate>