0

I'm new to WSO2 Enterprise Integrator.
I'm having hardtime combining this two messages using aggrerate mediator.
I have put my 1st message in property so I can access individual values (Is there any other way doing it?)
Required output is in json format. (I have tried for each but it's only looping in message 2 loop messages.)

Input message 1:

{
  "customerId": "ABC123",
  "channelNo": "1",
  "codename": "code123"
}

Input Message 2:

{
  "lnsAcctInfo": [
    {
      "acctno": "101991100000012",
      "custid": "2018111400000002",
      "acctype": null,
      "ccy": null,
      "name": null,
      "prdcode": "300"
    },
    {
      "acctno": "101991100000022",
      "custid": "2018111400000052",
      "acctype": 1,
      "ccy": 1,
      "name": 1,
      "prdcode": "300"
    }
  ]
}

Output required:

{
  "customerId": "ABC123",
  "codename": "code123",
  "lnsAcctInfo": [
    {
      "acctno": "101991100000012",
      "custid": "2018111400000002",
      "acctype": null
    },
    {
      "acctno": "101991100000022",
      "custid": "2018111400000052",
      "acctype": 1
    }
  ]
}

Here's the synapse code:

<resource methods="POST" uri-template="/foreach">
  <inSequence>
    <log>
      <property expression="json-eval($)" name="RecievedPostMessage" />
    </log>
    <property name="customid" scope="default" type="STRING" value="sampleuserid" />
    <payloadFactory description="payload-xml" media-type="xml">
      <format>
        <lnsAcctInfo xmlns="">$1</lnsAcctInfo>
      </format>
      <args>
        <arg evaluator="json" expression="$.lnsAcctInfo[*]" />
      </args>
    </payloadFactory>
    <log>
      <property expression="." name="payload1" />
    </log>
    <iterate expression="//lnsAcctInfo/jsonElement" id="1">
      <target>
        <sequence>
          <log>
            <property expression="." name="Iterate" />
          </log>
          <aggregate>
            <completeCondition>
              <messageCount max="-1" min="-1" />
            </completeCondition>
            <onComplete expression="//jsonElement">
              <log>
                <property expression="." name="aggre" />
              </log>
            </onComplete>
          </aggregate>
        </sequence>
      </target>
    </iterate>
    <log>
      <property expression="." name="overall" />
    </log>
    <respond />
  </inSequence>
  <outSequence>
    <send />
  </outSequence>
  <faultSequence />
</resource>
barbsan
  • 3,418
  • 11
  • 21
  • 28
  • How will you know which two messages are supposed to go together? Is your API supposed to receive both? Because that is not really an option, each incoming message on the API will be in a separate thread. Or will the API look one up based on the other maybe? – ophychius Dec 11 '18 at 06:33
  • [edit] your question and add your attempt with `foreach` – barbsan Dec 11 '18 at 07:57
  • the two messages will be coming from 2 different apis. I have used foreach but dont know how to get the accumulated results after the looping. – Clint Palanca Dec 12 '18 at 09:12

0 Answers0