简体   繁体   中英

WSO2 ESB Iterate over DSS response (json array)

I have a problem to iterate over call response of a dss. I have 2 servers

WSO2 ESB server (4.9.0) WSO2 Application Server (5.3.0) with Data Service (4.3.4) feature installed

i make a payload

  <payloadFactory media-type="xml">
    <format>
      <p:valoresReport xmlns:p="ReportsDataService">
        <xs:uuid xmlns:xs="ReportsDataService">$1</xs:uuid>
      </p:valoresReport>
    </format>
    <args>
      <arg value="123456789"/>
    </args>
  </payloadFactory>

and do a call through an endpoint

  <call blocking="true">
    <endpoint key="ReportsDataServiceEndPoint"/>
  </call>

The response is:

<ReportRowSet xmlns="ReportsDataService">
   <reportRow>
      <column1>1</column1>
      <column2>2</column2>
      <column3>3</column3>
   </reportRow>
   <reportRow>
      <column1>columna 1</column1>
      <column2>olumna 2</column2>
      <column3>columna 3</column3>
   </reportRow>
</ReportRowSet>

To read the response, i change de messageType to json

  <property name="messageType" scope="axis2" type="STRING" value="application/json"/>

and get the value with json-eval.

  <property expression="json-eval($.ReportRowSet.reportRow)" name="rows"
    scope="default" type="STRING"/>

I can log the property

  <log level="custom">
    <property expression="$ctx:rows" name="ROWS"/>
  </log>

output:

[2016-05-31 16:21:38,489]  INFO - LogMediator ROWS = [{"column1":1,"column3":3,"column2":2},{"column1":"columna 1","column3":"columna 3","column2":"olumna 2"}]

But when i try to iterate the rows, i dont know how to do this (this way does not work)

 <iterate continueParent="true" expression="$ctx:rows"
    id="MyIterator" sequential="true">
    <target>
      <sequence>
      ...

also i tried with no success (without changing the messagetype):

  <iterate continueParent="true" expression="//ReportRowSet/reportRow"
    id="MyIterator" sequential="true">

whats the correct form to do this integration and iteration.

I let you my dss and sequence:

ReportsDataService.dbs: [ https://drive.google.com/open?id=0B44t8SdKZz79ellKVmpkM0t6Rmc ]

GenerarReporteSequence.xml: [ https://drive.google.com/open?id=0B44t8SdKZz79YlkxMnNnNm8weGs ]

Try with proper namespace in your iterator mediator, sample below,

     <iterate xmlns:ns1="ReportsDataService" id="MyIterator" expression="//ns1:ReportRowSet/ns1:reportRow" sequential="true">
        <target>
           <sequence>
              <log level="custom">
                 <property name="col" expression="//ns1:column1"/>
              </log>
              <call>
                 <endpoint>
                    <http uri-template="http://endpoint.url"/>
                 </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