wso2 ei 6.5 SOAP客户端和REST服务接收到的参数是XML Rest需要json

问题描述

  <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="ctc"
           startOnLoad="true"
           statistics="enable"
           trace="disable"
           transports="http,https">
       <target>
          <inSequence>
             <log>
                <property name="******" value="---ctc---"/>
             </log>
             <property xmlns:saop="http://j2ee.netbeans.org/wsdl/EsbJyBpel/src/saopWSDL"
                       expression="$body//saop:upload/xml"
                       name="request_msg"/>
    
             <log>
                <property expression="json-eval($)" name="request_msg"/>
             </log>
             <property name="messageType"     
                       scope="axis2"
                       type="STRING"
                       value="application/json"/>
             <script language="js">mc.setPayloadJSON(
                            {
                                    "Code" : "10","Price" : "11"
                     });</script>
             <property name="HTTP_METHOD" scope="axis2" value="POST"/>
                      <property name="messageType"
                       scope="axis2"
                       type="STRING"
                       value="application/json"/>
                        <property name="Content-Type"
                          value="application/json"
                          scope="transport"
                          type="STRING"/>
             <send>
                <endpoint>
                   <address format="pox" uri="http://192.16.110.142:8081/dqcsweb/ES/test"/>
                </endpoint>
             </send> 
    
          </inSequence>
          <outSequence>
             <log>
                <property expression="json-eval($)" name="res_msg"/>
             </log>
             <send/>
          </outSequence>
       </target>
    
    </proxy>

restful服务日志打印的XML结构; 您如何将XML结构转换为JSON?

我使用了脚本和payloadFactory,在ESB中输出了JSON字符串,并且被调用服务中的打印日志仍然是XML

输入: enter image description here

服务收到的消息(http://192.16.110.142:8081/dqcsweb/ES/test):

 <jsonObject><Code>10</Code><Price>11</Price></jsonObject>

期望:

{
   "code":"10","Price":"11"
}

解决方法

您可以更改调用rest的端点的格式吗?请参考以下示例配置。

        <send>
            <endpoint>
               <address format="rest" uri="http://192.16.110.142:8081/dqcsweb/ES/test"/>
            </endpoint>
         </send>

使用的pox格式导致消息转换为普通的旧XML格式。请参考文档[1]进一步阐明。

[1] -https://docs.wso2.com/display/EI611/Address+Endpoint

更新 您可以通过取消注释log4j.properties文件中的以下[2]来启用有线日志。您需要执行服务器重新启动才能启用此功能。这使您可以查看从EI服务器发出的请求。请检查从EI发送的请求是否包含必要的有效负载。

log4j.logger.org.apache.synapse.transport.http.wire=DEBUG

[2] -https://docs.wso2.com/display/ESB500/Debugging+Mediation#DebuggingMediation-Viewingwirelogs