wso2wso2-enterprise-integratorintegrator

How can I get the Property from OnComplete AggregateMediator in RESTful API WSO2EI 6.2.0?


I've tried several ways to get The Property from OnComplete AggregateMediator and used it in Expression prop of ForEach Mediator, but none of these is suceed. I've searched in google too, but no luck at all.

Here is my RESTful API (in short mode):

This is inSequence section

<api xmlns="http://ws.apache.org/ns/synapse" context="/path/to/context" name="NamedAPI">
  <resource methods="POST" protocol="http">
    <inSequence>
    <property expression="count(//parameter/objects)" name="count" scope="default" type="STRING"/>
    <iterate expression="//parameter/objects" id="iterate1" sequential="true">
       <target>
         <sequence>
           <property expression="//objects/text()" name="element1" scope="default" type="STRING"/>
           <sequence key="getIdOfElement1"/>
           <property expression="json-eval($.result.id)" name="el1id" scope="default" type="STRING"/>
           <payloadFactory media-type="xml">
             <format>
               <ids xmlns="">
                 <id>$1</id>
               </ids>
             </format>
             <args>
               <arg evaluator="xml" expression="get-property('el1id')"/>
             </args>
           </payloadFactory>
         </sequence>
       </target>
     </iterate>
     <aggregate id="iterate1">
       <completeCondition timeout="10">
         <messageCount max="-1" min="{get-property('count')}"/>
       </completeCondition>
       <onComplete expression="//ids">
         <property expression="$body" name="message" scope="operation" type="OM"/>
       </onComplete>
     </aggregate>
     <payloadFactory media-type="xml">
       <format>
         <result xmlns="">$1</result>
       </format>
       <args>
         <arg evaluator="xml" expression="get-property('operation','message')"/>
       </args>
     </payloadFactory>
     <send>
       <endpoint key="NamedEP"/>
     </send>
   </inSequence>

This is OutSequence section:

   <outSequence>
     <property expression="get-property('operation', 'message')" name="IDs"/>
     <log level="custom">
       <property expression="//ids" name="========== LIST IDs =========="/>
    </log>
    <foreach expression="//ids" id="foreach1">
      <sequence>
        <log level="custom">
          <property expression="//id" name="========== ID =========="/>
        </log>
        <log level="full"/>
        <dbreport>
          <connection>
            <pool>
              <dsName>A_DS</dsName>
            </pool>
          </connection>
          <statement>
            <sql>INSERT INTO "table" ("field1", "id") VALUES (?,?)</sql>
            <parameter expression="get-property('field1')" type="VARCHAR"/>
            <parameter expression="//id" type="INTEGER"/>
          </statement>
        </dbreport>
      </sequence>
    </foreach>
    <payloadFactory media-type="json">
      <format>
        [{ "field1" : "$1" }]
      </format>
      <args>
        <arg evaluator="xml" expression="get-property('field1')"/>
      </args>
    </payloadFactory>
    <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
    <property expression="json-eval($.)" name="response" scope="default" type="STRING"/>
  <send/>
</outSequence>

This is FaultSequence Section

    <faultSequence>
      <payloadFactory media-type="json">
        <format>
          [{ "fault" : { "responsecode" : "999", "responsedesc" : "General error", "errordetails" : "$1" } }]
        </format>
        <args>
          <arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
        </args>
      </payloadFactory>
      <respond/>
      <send/>
    </faultSequence>
  </resource>
</api>

I've Tried this:

<foreach expression="//ids" id="foreach1">

it does not work. The DBReport not executed in ForEach Mediator, so does the Log Mediator

I've Tried this:

<foreach expression="get-property('operation', 'message')" id="foreach1">

The WSO2EI showed me an error

I've tried to move all of the Mediator (ForEach and DBReport) in OutSequence Section to the InSequence Section but it's not worked too.

Please, help me. Any help will be appreciated.

Thanks in advance.

Here is the log as per @Arunan's Comment

TID: [-1234] [] [2019-08-21 10:00:06,176]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== START COUNTER ========== = 1 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,176]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== START ITERATE NO :  = 2.0 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,177]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== NIP FROM ITERATE :   = 198910202001020001 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,180]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== START ITERATE NO :  = 2.0 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,181]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== NIP FROM ITERATE :   = 199509142005010001 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,230]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== RPID FROM SEQUENCE IN ITERATE ========== = 3 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,230]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== RPID FROM SEQUENCE IN ITERATE ========== = 1 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,262]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== EXIST RICE DOCUMENT ========== = 0 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2019-08-21 10:00:06,348]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  ========== LIST RPIDs ========== =  {org.apache.synapse.mediators.builtin.LogMediator}

Solution

  • Alhamdulillah, I've tried my best, and It's worked Perfectly.

    How to share the messaging between InSequence and OutSequence (in my case: from Aggregate Mediator inside inSequence section to Expression ForEach Mediator inside OutSequence section).

    You must declare new property, and get the value from message property, like:

    <property expression="get-property('operation', 'message')" name="rpidList" scope="default" type="OM"/>
    

    And, in the ForEach Expression, you give a code below

    <foreach expression="$ctx:rpidList//rpids" id="foreach1">
    

    Thanks for all. And Thank you StackOverflow.com