如何使用WSO2 API管理器从SOAP后端创建Rest API

如何使用WSO2 API管理器从SOAP后端创建Rest API,rest,soap,wso2,wso2-am,Rest,Soap,Wso2,Wso2 Am,我是wso2 api管理器的新手,我需要暂停一个SOAP服务并将其带到REST api,我已经看过所有文档,但都没有响应我的问题,我已经创建了一个输入序列 getProdRequestInSequence.xml <?xml version="1.0" encoding="UTF-8"?> <sequence xmlns="http://ws.apache.org/ns/synapse" name="getP

我是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>
 <?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 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>
<?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>

$1
xml_to_json_out_message.xml
现在,根据文档,这些文件一旦创建,我就负责消息中介策略,应该可以完美地工作 但它给了我这个错误

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

提前谢谢你的帮助

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>
 <?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 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>
<?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>

$1
和输出序列

xml\u to\u json\u out\u message.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>
 <?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 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>
<?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>

现在,根据文档,这些文件一旦创建,我就负责消息中介策略,应该可以完美地工作 但它给了我这个错误

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


提前感谢您的帮助

提供的getProdRequestInSequence.xmlsynapse配置文件中存在语法不匹配

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

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>
 <?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 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>
<?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>

$1

上述问题的解决方案:

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


建议使用WSo2 API管理器的方法:

WSO2 API管理器能够将SOAP服务/API公开为REST API开箱即用,无需任何序列或synapse级配置

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


请参阅文档。

WSO2 API MANAGER的版本为2.6.0*此错误通常发生在序列中出现验证错误时。您是否可以尝试在任何在线XML验证器中按顺序验证您的XML,并检查它是否有效?