WSO2 EI 将传入的 Json 请求转换为 XML 并将其发送到 WSDL 端点

WSO2 EI converting Incoming Json request to XML and send it to WSDL Endpoint

当我将 json 发送到 wso2 代理服务时,它将传入请求转换为 xml 使用有效负载调解器。 它给了我以下错误:

{
    "Envelope": {
        "Body": {
            "Fault": {
                "faultcode": "S:Client",
                "faultstring": "Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {http://fcubs.ofss.com/service/FCUBSCcyService}RATESMASTERQUERY_IOFS_REQ"
            }
        }
    }
}

这是我的发送请求:

{
    "Parameter": {
        "brncode": "CHO",
        "ccy1": "USD",
        "ccy2": "MNT"
    }
}

这是我的代理服务代码: 接收 Json 并发送 XML 到端点

      <inSequence>
         <log category="DEBUG" level="full" separator="&#xA;">
            <property name="Request" value="=============Request============"/>
            <property expression="json-eval($)" name="Request"/>
         </log>

Payload Mediator 将 Json 转换为 XML 并将发送到端点

         <payloadFactory media-type="xml">
            <format>
               <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                                 xmlns="http://fcubs.ofss.com/service/FCUBSCcyService">
                  <soapenv:Body>
                     <RATESMASTERQUERY_IOFS_REQ>
                        <FCUBS_HEADER>
                           <SOURCE></SOURCE>
                           <UBSCOMP></UBSCOMP>
                           <USERID></USERID>
                           <BRANCH></BRANCH>
                           <SERVICE>FCUBSCcyService</SERVICE>
                           <OPERATION></OPERATION>
                        </FCUBS_HEADER>
                        <FCUBS_BODY>
                           <Rates-Master-IO>
                              <BRNCODE></BRNCODE>
                              <CCY1></CCY1>
                              <CCY2></CCY2>
                           </Rates-Master-IO>
                        </FCUBS_BODY>
                     </RATESMASTERQUERY_IOFS_REQ>
                  </soapenv:Body>
               </soapenv:Envelope>
            </format>
enter code here
            <args>
               <arg evaluator="xml" expression="$trp:Source"/>
               <arg value="FCUBS"/>
               <arg evaluator="xml" expression="$trp:userid"/>
               <arg evaluator="xml" expression="ctx:brncode"/>
               <arg evaluator="xml" expression="$trp:function"/>
               <arg evaluator="xml" expression="ctx:ccy1"/>
               <arg evaluator="xml" expression="ctx:ccy2"/>
            </args>
         </payloadFactory>
         <header name="Accept" scope="transport" value="text/xml"/>
         <property name="messageType" scope="axis2" value="text/xml"/>
      </inSequence>

输出序列:

 <outSequence>
             <log category="DEBUG" separator="&#xA;">
                <property name="Response" value="=============Response============"/>
                <property expression="json-eval($)" name="Response"/>
             </log>
             <property name="messageType" scope="axis2" value="application/json"/>
             <send/>
          </outSequence>

如何正确使用它? 谢谢

payloadFactorysoap:Body 进行操作,因此您不应在 payloadFactory 中创建 soap:Envelopesoap:Body。只需将 Content-TypemessageType 都设置为 'text/xml',使用 payloadFactory 创建请求并发送。

除了小错误,你的配置看起来还不错

错误 01:ctx 应该改为 $ctx

错误 02:如果您公开 REST API,您应该创建一个 REST API [1] 而不是代理。代理服务是为了在 WSO2 EI 中公开 SOAP 服务。

以下是满足您要求的工作示例:

<api xmlns="http://ws.apache.org/ns/synapse" name="API_Name" context="/APIBasePath" version="1.0.0" version-type="context">
   <resource methods="POST" url-mapping="/samplePath">
      <inSequence>
         <payloadFactory media-type="xml">
            <format>
               <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://fcubs.ofss.com/service/FCUBSCcyService">
                  <soapenv:Body>
                     <RATESMASTERQUERY_IOFS_REQ>
                        <FCUBS_HEADER>
                           <SOURCE></SOURCE>
                           <UBSCOMP></UBSCOMP>
                           <USERID></USERID>
                           <BRANCH></BRANCH>
                           <SERVICE>FCUBSCcyService</SERVICE>
                           <OPERATION></OPERATION>
                        </FCUBS_HEADER>
                        <FCUBS_BODY>
                           <Rates-Master-IO>
                              <BRNCODE></BRNCODE>
                              <CCY1></CCY1>
                              <CCY2></CCY2>
                           </Rates-Master-IO>
                        </FCUBS_BODY>
                     </RATESMASTERQUERY_IOFS_REQ>
                  </soapenv:Body>
               </soapenv:Envelope>
            </format>
            <args>
               <arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$trp:Source"/>
               <arg value="FCUBS"/>
               <arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$trp:userid"/>
               <arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$ctx:brncode"/>
               <arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$trp:function"/>
               <arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$ctx:ccy1"/>
               <arg xmlns:ns="http://org.apache.synapse/xsd" evaluator="xml" expression="$ctx:ccy2"/>
            </args>
         </payloadFactory>
         <property name="messageType" value="text/xml" scope="axis2"/>
         <log level="full"/>
         <send>
            <endpoint>
               <address uri="http://www.mocky.io/v2/5185415ba171ea3a00704eed" format="soap11"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <respond/>
      </outSequence>
   </resource>
</api>

[1] https://docs.wso2.com/display/EI650/Working+with+APIs