rest - 使用 SOAP 和 WSO2 ESB 代理 RESTful 服务

标签 rest wso2 wso2-esb

我们希望使用 SOAP 代理 RESTful Web 服务。

REST 服务使用 GET 方法并通过查询参数接受输入。它生成 application/csv 类型的资源。

WSO2 ESB/Synapse 是否支持这种场景,是否有可用的示例?

请求示例

SOAP 代理请求:

<request>
  <fromDate>2012-01-01</fromDate>
  <toDate>2012-12-31</toDate>
</request>

REST 端点请求:

http://localhost/person?fromDate=2012-01-01&toDate=2012-12-31

响应示例

REST 端点响应

"Name","Age","Sex"
"Geoff","22","Male"

SOAP 代理响应

<person>
  <name>Geoff</name>
  <age>22</age>
  <sex>Male</sex>
<person>

非常感谢。

最佳答案

如果我理解正确的话,您希望将 REST 服务公开为 SOAP 服务,以便 SOAP 客户端可以通过 ESB 访问您的 REST 服务?

如果是这种情况,则有可能:) 您应该从以下位置查看样本 152:http://docs.wso2.org/wiki/display/ESB451/Proxy+Service+Samples

它将解释如何获取 SOAP 请求并将其传递到 REST 后端,然后将 REST 响应转换为 SOAP 响应。

编辑:这是一个关于如何执行您在评论中提出的要求的示例配置,希望它能帮助您开始:)

<proxy xmlns="http://ws.apache.org/ns/synapse" name="RESTProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>

         <!-- We set the HTTP Method we want to use to make the REST request here -->
         <property name="HTTP_METHOD" value="GET" scope="axis2"/>

         <!-- This is where the magic happens, for what you want i.e. mapping SOAP "params" to REST query param's --> 
         <property name="messageType" value="application/x-www-form-urlencoded" scope="axis2"/>

         <send>
            <endpoint>
               <!-- This is the RESTful URL we are going to query, like the one in the ESB example 152 -->
               <address uri="http://localhost/person" />
            </endpoint>
         </send>

      </inSequence>

      <outSequence>
         <log level="full"/>
         <property name="messageType" value="text/xml" scope="axis2"/>
         <send/>
      </outSequence>
   </target>
   <description></description>
</proxy>

那么您向 ESB 发出的 SOAP 请求应该类似于:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
    <person>
        <fromDate>2012-01-01</fromDate>
        <toDate>2012-12-31</toDate>
    </person>
   </soapenv:Body>
</soapenv:Envelope>

希望有帮助:)

关于rest - 使用 SOAP 和 WSO2 ESB 代理 RESTful 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13987882/

相关文章:

WSO2 ESB - 配置 CORS

ios - 休息套件 RKMappingOperation 不起作用

PHP API 最佳实践 - 回显 json_encoded 对象 : bad or good?

wso2 - 如何使用丰富中介器通过 WSO2 ESB 将 SOAP 信封设置为 XML 主体

WSO2 ESB 5.0.0 - 如何获取属性调解器的注册表值

wso2 - 丰富中介添加有效负载 wso2

java - 仅当方法使用 xml/json 时才需要 JAXB 元素

javascript - 运行服务器时出现找不到模块 '../lib/cli' 错误

java - Java 程序的 wso2 权利

wso2 - 如何在wso2 esb脚本中介器中读取请求参数值