简体   繁体   中英

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?

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>

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