如何将 text/xml 响应转换为 application/json wso2 EI

How to convert text/xml response into application/json wso2 EI

我有一个 soap 服务,我需要在 Wso2 EI 中将此服务公开为休息 api,内容类型为 text/xml,我尝试使用

<property name="messageType" value="application/json" scope="axis2"/>

在后序中,但它不会将我的回复转换为 json。你能帮我看看怎么做吗?

我试过了,

    <resource methods="POST">
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2"/>
         <send/>
      </outSequence>
   </resource>

它应该可以完美运行。下面给出了一个示例 REST API 配置。

<api xmlns="http://ws.apache.org/ns/synapse" name="CheckREST" context="/samplerest">
   <resource methods="GET">
      <inSequence>
         <send>
            <endpoint>
               <http uri-template="http://localhost:8280/services/sampleSOAPproxy"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
         <send/>
      </outSequence>
   </resource>
</api>

如果不工作,请说明您使用的 EI 版本。

原因是 WSO2 EI 或 ESB 的开发方式是默认使用 SOAP 响应来响应 SOAP 请求。当您使用 SOAPAction 和 Content-Type 调用 PROXY 或 API 时:text/xml,EI 将此理解为 SOAP 请求,并将以 SOAP 响应进行响应。

因此,如果客户端请求在 SOAP-1.1 中,EI 会以 SOAP-1.1 响应进行响应,或者如果客户端请求在 SOAP-1.2 中,则 EI 会在 SOAP-1.2 中进行响应。

为了绕过这种行为,他们提供了一个额外的 属性,如下所示。

<property name="IsClientDoingREST" scope="default" type="BOOLEAN" value="true"/>

因此,在响应客户端之前,应按以下方式设置属性以获得响应 JSON 的预期行为。

<property name="IsClientDoingREST" scope="default" type="BOOLEAN" value="true"/>
<property name="messageType" scope="axis2" value="application/json"/>

此方法将帮助您从 SOAP 请求中获取 JSON 响应。