2017-01-27 52 views
0

我有安裝了DSS功能的WSO2 ESB服務器。當我在請求頭中使用「accept:application/json」調用REST服務時,我沒有收到JSON響應,只收到XML。帶DSS集成的WSO2 ESB不響應JSON

最佳,伊萬

+0

嗨Iva你能分享你的代理服務的代碼嗎? – Eric

回答

2

在此API由JSON響應我用這兩個屬性

<property name="Accept" value="application/json" scope="transport" type="STRING"/> 
<property name="messageType" value="application/json" scope="axis2"/> 

您可以在這裏看到的實施

<api xmlns="http://ws.apache.org/ns/synapse" name="showById" context="/getById"> 
    <resource methods="POST GET" uri-template="/getEmployeeXML/{Id}"> 
     <inSequence> 
     <property name="getId" expression="get-property('uri.var.Id')" scope="default" type="STRING"/> 
     <log> 
      <property name="ID" expression="get-property('getId')"/> 
     </log> 
     <property name="Accept" value="application/json" scope="transport" type="STRING"/> 
     <property name="messageType" value="application/json" scope="axis2"/> 
     <payloadFactory media-type="xml"> 
      <format> 
       <p:getEmployeeXML xmlns:p="arce.farmacy"> 
        <xs:Id xmlns:xs="arce.farmacy">$1</xs:Id> 
       </p:getEmployeeXML> 
      </format> 
      <args> 
       <arg evaluator="xml" expression="get-property('getId')"/> 
      </args> 
     </payloadFactory> 
     <property name="Action" value="urn:getEmployeeXML" scope="transport" type="STRING"/> 
     <property name="SOAPAction" value="urn:getEmployeeXML" scope="transport" type="STRING"/> 
     <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/> 
      <send> 
      <endpoint> 
       <address uri="http://169.254.193.10:9763/services/StoreProcedureFarmacy" format="soap11"/> 
      </endpoint> 
     </send> 
     </inSequence> 
     <outSequence> 
     <log level="full"/> 
     <send/> 
     </outSequence> 
     <faultSequence> 
     <sequence key="{faultSEQ}"/> 
     </faultSequence> 
    </resource> 
</api> 

這是響應

{ 
    "Employees": { 
    "Employe": [ 
     { 
     "Id": 5, 
     "Description": "Office 2" 
     } 
    ] 
    } 
}