【问题标题】:How to create a Rest API from SOAP Backend with WSO2 API Manager如何使用 WSO2 API Manager 从 SOAP 后端创建 Rest API
【发布时间】:2019-10-02 18:47:59
【问题描述】:

我是使用 wso2 api 管理器的新手,我需要暂停 SOAP 服务并将其带到 REST API,我已经查看了所有文档,但没有一个响应我的问题,我已经创建了一个输入序列

getProdRequestInSequence.xml

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" ><!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator --><header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/><!-- We are storing the input values which the end users input for these values into these two properties --><property name="uri.var.categoria" expression="$url:categoria"/>
<!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it --><property name="REST_URL_POSTFIX" scope="axis2" action="remove"/><!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator --><payloadFactory description="transform" media-type="xml">
  <format>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://localhost:81/soap/products.php/query/">
  <soapenv:Header/>
  <soapenv:Body>
  <quer:getProd>
    <quer:categoria>$1</quer:categoria>
  </quer:getProd></soapenv:Body>
  </soapenv:Envelope>
  </format>
  <args>
    <arg expression="get-property(‘uri.var.categoria’)"/>
  </args>
</payloadFactory><!-- Here we are setting the content type which the web service expects --><property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>

xml_to_json_out_message.xml

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="xml_to_json_out_message" >
<!-- Transforms the response to a JSON -->
    <property description="message" name="messageType" scope="axis2" type="STRING" value="application/json"/>
</sequence>

现在,根据文档,这些文件一旦创建,我就会在 Message Mediation Policies 中收费,并且应该可以正常工作 但它给了我这个错误

网关故障

未能发布环境 生产和沙盒 将序列部署到网关时出错###

提前感谢您的帮助

getProdRequestInSequence.xml

 <?xml version="1.0" encoding="UTF-8"?>
    <sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" ><!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator --><header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/><!-- We are storing the input values which the end users input for these values into these two properties --><property name="uri.var.categoria" expression="$url:categoria"/>
    <!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it --><property name="REST_URL_POSTFIX" scope="axis2" action="remove"/><!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator --><payloadFactory description="transform" media-type="xml">
      <format>
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://localhost:81/soap/products.php/query/">
      <soapenv:Header/>
      <soapenv:Body>
      <quer:getProd>
        <quer:categoria>$1</quer:categoria>
      </quer:getProd></soapenv:Body>
      </soapenv:Envelope>
      </format>
      <args>
        <arg expression="get-property(‘uri.var.categoria’)"/>
      </args>
    </payloadFactory><!-- Here we are setting the content type which the web service expects --><property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
    </sequence>

和输出序列

xml_to_json_out_message.xml

 <?xml version="1.0" encoding="UTF-8"?>
    <sequence xmlns="http://ws.apache.org/ns/synapse" name="xml_to_json_out_message" >
    <!-- Transforms the response to a JSON -->
        <property description="message" name="messageType" scope="axis2" type="STRING" value="application/json"/>
    </sequence>

现在,根据文档,这些文件一旦创建,我就会在 Message Mediation Policies 中收费,并且应该可以正常工作 但它给了我这个错误

网关故障

未能发布环境 生产和沙盒 将序列部署到网关时出错

提前感谢您的帮助

【问题讨论】:

  • WSO2 API MANAGER的版本是2.6.0*
  • 这个错误一般发生在你的序列有验证错误的时候。您可以尝试在任何在线 XML 验证器中验证您的 in-sequence 并检查它是否有效?

标签: rest soap wso2 wso2-am


【解决方案1】:

在提供的 getProdRequestInSequence.xml 突触配置文件中存在语法不匹配。

uri.var.categoria 已在 get-property() 方法中用特殊字符 (') 括起来,它不是单引号 (')。请在下面找到更新的突触配置文件

getProdRequestInSequence.xml

<?xml version="1.0" encoding="UTF-8"?>
    <sequence xmlns="http://ws.apache.org/ns/synapse" name="getProdRequestInSequence" >
    <!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator -->
    <header description="SOAPAction" name="SOAPAction" scope="transport" value="http://localhost:81/soap/products.php/query/getProd"/>
    <!-- We are storing the input values which the end users input for these values into these two properties -->
    <property name="uri.var.categoria" expression="$url:categoria"/>
    <!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it -->
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
    <!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator -->
    <payloadFactory description="transform" media-type="xml">
        <format>
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://localhost:81/soap/products.php/query/">
                <soapenv:Header/>
                <soapenv:Body>
                    <quer:getProd>
                        <quer:categoria>$1</quer:categoria>
                    </quer:getProd>
                </soapenv:Body>
            </soapenv:Envelope>
        </format>
        <args>
            <arg expression="get-property('uri.var.categoria')"/>
        </args>
    </payloadFactory>
    <!-- Here we are setting the content type which the web service expects -->
    <property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>

【讨论】:

    【解决方案2】:

    上述问题的解决方法:

    目前,您的方法有一个特殊字符“‘”,即 如果您使用 mac book 进行开发,则很常见。更换 具有正确字符的单引号将解决您当前的 问题。


    使用 WSo2 API 管理器的推荐方法:

    WSO2 API Manager 能够将 SOAP 服务/API 公开为 REST API 开箱即用,无需任何序列或突触级别配置。

    要使用 WSO2 API Manager 公开 REST 服务,您只需提供具有此功能的后端 URL 和 WDSL 文件。

    请参考文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多