如何从 RESTful API WSO2EI 6.2.0 中的 OnComplete AggregateMediator 获取 属性?

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

我尝试了几种方法从 OnComplete AggregateMediator 中获取 属性 并将其用于 ForEach Mediator 的 Expression prop,但是其中 none 成功了。 我也在 google 中搜索过,但一点运气都没有。

这是我的 RESTful API(短模式):

这是顺序部分

<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></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=""></result>
       </format>
       <args>
         <arg evaluator="xml" expression="get-property('operation','message')"/>
       </args>
     </payloadFactory>
     <send>
       <endpoint key="NamedEP"/>
     </send>
   </inSequence>

这是 OutSequence 部分:

   <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" : "" }]
      </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>

这是故障序列部分

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

我试过这个:

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

它不起作用。 DBReport 没有在 ForEach Mediator 中执行,Log Mediator 也是如此

我试过这个:

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

WSO2EI 显示错误

我尝试将 OutSequence 部分中的所有 Mediator(ForEach 和 DBReport)移动到 InSequence 部分,但它也没有用。

请帮帮我。 任何帮助将不胜感激。

提前致谢。

这是根据@Arunan 的评论的日志

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}

Alhamdulillah,我已尽力而为,效果非常好。

如何在 InSequence 和 OutSequence 之间共享消息传递(在我的例子中:从 inSequence 部分内的聚合中介到 OutSequence 部分内的 Expression ForEach 中介)。

您必须声明新的 属性,并从消息 属性 中获取值,例如:

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

并且,在 ForEach 表达式中,您提供以下代码

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

谢谢大家。 谢谢 whosebug.com