我有一台安装了DSS功能的WSO2 ESB服务器。当我使用" accept:application / json"来调用REST服务时在请求标头中,我没有收到JSON响应,只接收XML。
Best,Ivan
答案 0 :(得分: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"
}
]
}
}