2014-10-31 47 views
0

在WSO2 ESB中,我創建了一個rest API。此API需要連接到兩個不同的服務,併合並結果。使用wso2 esb api聚合響應:無回答

爲此,我使用了一個API,用一個克隆介質發送出適當的消息。這工作正常。

在這種情況下,我使用記錄器來查看傳入的消息。這兩個都是json,然後回來。然後我想使用一個聚合中介來組合這兩者。有了這個,我有兩個問題:

  • 使用rootElementProperty放置在一個父這兩個項目時,一個NPE發生,
  • 使用時,充實調解員或任何其他人做出正確的消息,並與結束髮送,所產生的消息永遠不會被髮回。

這可能是什麼原因造成的?

這是實際的API:

<?xml version="1.0" encoding="UTF-8"?> 
<api xmlns="http://ws.apache.org/ns/synapse" name="Cale-StreetsAPI" context="/Cale-StreetsAPI"> 
    <resource methods="GET" uri-template="/getStreets?lat={lat}&amp;lon={lon}&amp;radius={radius}"> 
     <inSequence> 
      <property name="aggRoot" scope="default"> 
       <red:jsonObject xmlns:red="redora"/> 
      </property> 
      <log description=""> 
       <property name="lat" expression="get-property('uri.var.lat')"/> 
       <property name="lon" expression="get-property('uri.var.lon')"/> 
       <property name="radius" expression="get-property('uri.var.radius')"/> 
      </log> 
      <clone continueParent="true" id="deCartaStreets"> 
       <target> 
        <sequence> 
         <sequence key="DeCartaDDS"/> 
        </sequence> 
       </target> 
       <target> 
        <sequence> 
         <sequence key="DeCartaReverseGeo"/> 
        </sequence> 
       </target> 
      </clone> 
     </inSequence> 
     <outSequence> 
      <property name="messageType" value="application/xml" scope="axis2" type="STRING" description="messageType"/> 
      <log level="full" description=""> 
       <property name="WSANSWER" value="true"/> 
      </log> 
      <aggregate> 
       <completeCondition> 
        <messageCount min="2" max="-1"/> 
       </completeCondition> 
       <onComplete expression="$body/jsonObject"> 
        <enrich> 
         <source clone="true" xpath="$body//jsonObject"/> 
         <target type="property" property="ResultItems"/> 
        </enrich> 
        <log level="custom"> 
         <property name="ResultItems" expression="get-property('ResultItems')"/> 
        </log> 
        <enrich> 
         <source type="inline" clone="true"> 
          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
           <soapenv:Header/> 
           <soapenv:Body> 
            <JsonResponse xmlns="dummy"/> 
           </soapenv:Body> 
          </soapenv:Envelope> 
         </source> 
         <target type="envelope"/> 
        </enrich> 
        <enrich> 
         <source type="property" clone="true" property="ResultItems"/> 
         <target xmlns:red="dummy" action="child" xpath="//red:JsonResponse"/> 
        </enrich> 
        <log level="full" description=""> 
         <property name="AGGREGATE_END" value="true"/> 
        </log> 
        <property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/> 
        <send/> 
       </onComplete> 
      </aggregate> 
     </outSequence> 
     <faultSequence> 
      <log level="full" category="WARN"/> 
     </faultSequence> 
    </resource> 
</api> 

回答

0

我面對你做了同樣的問題。根據互聯網API的帖子數量不支持聚合。

所以我的解決方案是引入聚合代理服務,它完成了API剛剛調用該代理服務的所有工作。

因此,如果您修改您的解決方案如下,你應該能夠達到你所期望的:

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AggregatingProxy" transports="local https http" startOnLoad="true" trace="disable"> 
<target> 
    <inSequence> 
     <log level="full"/> 
     <property name="enclosing_element"> 
      <result xmlns=""/> 
     </property> 
     <clone continueParent="true"> 
      <property name="aggRoot" scope="default"> 
       <red:jsonObject xmlns:red="redora"/> 
      </property> 
      <log description=""> 
       <property name="lat" expression="get-property('uri.var.lat')"/> 
       <property name="lon" expression="get-property('uri.var.lon')"/> 
       <property name="radius" expression="get-property('uri.var.radius')"/> 
      </log> 
      <clone continueParent="true" id="deCartaStreets"> 
       <target> 
        <sequence> 
         <sequence key="DeCartaDDS"/> 
        </sequence> 
       </target> 
       <target> 
        <sequence> 
         <sequence key="DeCartaReverseGeo"/> 
        </sequence> 
       </target> 
      </clone> 
     </clone> 
    </inSequence> 
    <outSequence> 
     <property name="messageType" value="application/xml" scope="axis2" type="STRING" description="messageType"/> 
     <log level="full" description=""> 
      <property name="WSANSWER" value="true"/> 
     </log> 
     <aggregate> 
      <completeCondition> 
       <messageCount min="2" max="-1"/> 
      </completeCondition> 
      <onComplete expression="$body/jsonObject"> 
       <enrich> 
        <source clone="true" xpath="$body//jsonObject"/> 
        <target type="property" property="ResultItems"/> 
       </enrich> 
       <log level="custom"> 
        <property name="ResultItems" expression="get-property('ResultItems')"/> 
       </log> 
       <enrich> 
        <source type="inline" clone="true"> 
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
          <soapenv:Header/> 
          <soapenv:Body> 
           <JsonResponse xmlns="dummy"/> 
          </soapenv:Body> 
         </soapenv:Envelope> 
        </source> 
        <target type="envelope"/> 
       </enrich> 
       <enrich> 
        <source type="property" clone="true" property="ResultItems"/> 
        <target xmlns:red="dummy" action="child" xpath="//red:JsonResponse"/> 
       </enrich> 
       <log level="full" description=""> 
        <property name="AGGREGATE_END" value="true"/> 
       </log> 
       <property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/> 
       <send/> 
      </onComplete> 
     </aggregate> 
    </outSequence> 
    <faultSequence> 
     <log level="full" category="WARN"/> 
    </faultSequence> 
</target> 
</proxy> 

API配置:

<api xmlns="http://ws.apache.org/ns/synapse" name="Cale-StreetsAPI" context="/Cale-StreetsAPI"> 
<resource methods="GET" uri-template="/getStreets?lat={lat}&amp;lon={lon}&amp;radius={radius}"> 
    <inSequence> 
     <call> 
      <endpoint> 
       <address uri="http://localhost:8280/services/AggregatingProxy" format="soap12"></address> 
      </endpoint> 
     </call> 
     <respond/> 
    </inSequence> 
</resource> 
</api> 

這實際上摸索出適合我,希望能幫助你太。

還要考慮使用:

<property name="enclosing_element"> 
      <result xmlns=""/> 
     </property> 
    ... 
    <onComplete expression="$body/jsonObject" enclosingElementProperty="enclosing_element"> 

如果你的服務返回不同類型的結果。

謝謝, 弗拉基米爾。