我使用wso2 esb 4.8.1版本的SOAP来作为API进行休息转换。我有一个带有xsi值的soap请求。在我使用脚本调解器生成正确的soap请求后,我得到了预期的响应。但是我的回答有问题。因为我需要将肥皂反应转换成json。当我尝试跟随序列时,um没有得到与axis2的正确的json响应。如何将这个soap响应正确转换为json?
这是肥皂的回应。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:easyDownloadResponse xmlns:ns1="http://usermanage.ivas.huawei.com" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<easyDownloadReturn href="#id0"/>
</ns1:easyDownloadResponse>
<multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://response.usermanage.ivas.huawei.com" id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:EasyDownloadResp">
<eventClassName xsi:type="xsd:string" xsi:nil="true"/>
<failedResources xsi:type="soapenc:Array" xsi:nil="true"/>
<operationID xsi:type="xsd:long">0</operationID>
<resultCode xsi:type="xsd:int">0</resultCode>
<resultInfo xsi:type="xsd:string" xsi:nil="true"/>
<returnCode xsi:type="xsd:string">000000</returnCode>
<toneTransactionID xsi:type="soapenc:Array" xsi:nil="true"/>
<transactionID xsi:type="xsd:string" xsi:nil="true"/>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
这是我得到的回复
{"easyDownloadResponse":{"@encodingStyle":"http://schemas.xmlsoap.org/soap/encoding/","easyDownloadReturn":{"@href":"#id0"}}}
这是我的序列
<outSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="messageType" value="application/json" scope="axis2" type="STRING"></property>
<send></send>
</outSequence>
非常欢迎您的所有答案。
答案 0 :(得分:0)
您可以尝试payload mediator获取准确的json格式1。但是你仍然需要取消注释
中的以下几行$ ESB_HOME / repository / conf / axis2 / axis2.xml
<!--messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONStreamFormatter"/-->
<!--messageBuilder contentType="application/json"
class="org.apache.axis2.json.JSONStreamBuilder"/-->
默认情况下,当PayloadFactor介体收到JSON消息时,它们会转换为XML。但是,如果启用JSON流格式化程序和构建器,则传入的JSON消息将保留为JSON格式。
并且您还可以再次使用脚本调解器(在outsequence中)来修改您的json响应。请参阅this sample
答案 1 :(得分:0)
最后,我找到了问题的解决方案。在正常情况下,我们使用
<property name="messageType" value="application/json" scope="axis2" type="STRING"></property>
但是这个axis2属性不能将复杂的soap响应转换为json,例如xsi。 为此需要使用以下axis2属性。然后它按照我们的预期将整个肥皂反应转换成Json。
<property name="messageType" value="application/json/badgerfish" scope="axis2" type="STRING"></property>
这是我完全的后果。
<outSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="messageType" value="application/json/badgerfish" scope="axis2" type="STRING"></property>
<send></send>
</outSequence>