2015-10-26 98 views
0

我想要一個post API(wso2 APIm v1.9),要求是將動態應用程序/ xml有效載荷傳遞給後端服務url。json請求的payloadfactory配置

我從API控制檯和api突觸配置,然後使用PayloadFactory中介傳遞json有效載荷,我已創建動態有效載荷,這將傳遞到服務端點。

PayloadFactory配置附有和標籤:

<payloadFactory media-type="xml"> 
        <format> 
         <input> 
          <Param>$1</Param> 
         </input> 
        </format> 
        <args> 
         <arg evaluator="json" expression="$."/> //passing like this since the json payload is massive.  
        </args> 
     </payloadFactory> 

在測試API,讓下面的錯誤 API控制檯響應:

<am:fault xmlns:am="http://wso2.org/apimanager"> 
    <am:code>404</am:code> 
    <am:type>Status report</am:type> 
    <am:message>Runtime Error</am:message> 
    <am:description>Production key offered to the API with no production endpoint</am:description> 
</am:fault> 

能否請您檢查,並提出什麼是我的配置問題。

API配置:

<resource methods="POST" 
       uri-template="/sample/{id}/sub" 
       faultSequence="fault"> 
     <inSequence> 
      <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION"> 
       <then> 
        <property name="api.ut.backendRequestTime" 
          expression="get-property('SYSTEM_TIME')"/> 
        <property name="Authorization" 
          expression="fn:concat('Basic ', 'dXNlcjp1c2Vy')" 
          scope="transport"/> 
        <property name="messageType" value="application/xml" scope="axis2"/> 
        <payloadFactory media-type="xml"> 
        <format> 
         <input> 
          <newParam>$1</newParam> 
         </input> 
        </format> 
        <args> 
         <arg evaluator="json" expression="$."/> 
        </args> 
        </payloadFactory> 
        <property name="DISABLE_CHUNKING" value="true" scope="axis2"/> 
        <send> 
        <endpoint name="admin--Test_APIproductionEndpoint_0"> 
         <http uri-template="http://xxxx:8181/ValidateWAR/getValidate/validate"/> 
         <property name="Content-Type" value="application/xml" scope="transport"/> 
        </endpoint> 
        </send> 
       </then> 
       <else> 
        <sequence key="_sandbox_key_error_"/> 
       </else> 
      </filter> 
     </inSequence> 
     <outSequence> 
      <class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/> 
      <send/> 
     </outSequence> 
     </resource> 

感謝您對這個快速反應。

問候, 作爲

回答

0

我想你應該制定在WSO2 ESB定義的API內部的邏輯。處理應該在那裏進行,而API管理器在那裏'管理'您的後端API服務。這被稱爲API Facade模式(http://wso2.com/blogs/architecture/2013/05/a-pragmatic-approach-to-the-api-faade-pattern/)。

你不應該在API管理器中修改Synapse源代碼視圖,因爲它是由wso2人員自動生成和仔細開發的。

一旦你有你的esb api,然後從API管理器調用該api(通過指向它作爲生產端點,在發佈者)