【问题标题】:Invoking RESTful service from WSO2 ESB using method POST使用方法 POST 从 WSO2 ESB 调用 RESTful 服务
【发布时间】:2013-06-19 11:43:07
【问题描述】:

我有一个简单的 RESTful 服务,我想使用 WSO2 ESB 将其公开为基于 SOAP 的 Web 服务。

我的简单 RESTful 服务可以像 http://<<my system>>:8080/myapp/person/read 这样调用 作为回应,我得到了 Person 实体的 JSON 数据。

问题:我无法将参数传递给 RESTful 服务。我要从 SOAP 输入中去除参数值,但不知道如何将它传递给我的 RESTful;使用 ESB 提供服务。

我在WSO2 ESB

中配置了以下
<proxy xmlns="http://ws.apache.org/ns/synapse" name="PersonProxy" transports="https,http" statistics="enable" trace="enable" startOnLoad="true">
   <target>
      <inSequence>
         <property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" name="PERSON_ID" expression="//soapenv:Body/person/id"/>
         <log level="full">
            <property name="PERSON_ID" expression="get-property('PERSON_ID')"/>
         </log>
         <filter xpath="//person">
            <then>
               <property name="REST_URL_POSTFIX" value="read" scope="axis2" type="STRING"/>
               <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
               <property name="id" expression="get-property('PERSON_ID')" scope="axis2" type="STRING"/>
               <property name="ContentType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"/>
            </then>
            <else/>
         </filter>
         <send>
            <endpoint>
               <address uri="http://<<my system>>:8080/myapp/person" format="rest"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description></description>
</proxy>

我的 SOAP 请求如下所示

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
    <person>
      <id>3</id>
    </person>
   </soapenv:Body>
</soapenv:Envelope>

我有另一个带有GET 方法和 id 作为 URL 本身的一部分的 RESTful 服务,并且工作正常。 ESB 配置看起来像

<property name="REST_URL_POSTFIX" expression="get-property('PERSON_ID')" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>

<endpoint>
    <address uri="http://<<my system>>:8080/cfs/person" format="rest"/>
</endpoint>

感谢任何指点或帮助。

【问题讨论】:

    标签: wso2 wso2esb


    【解决方案1】:

    如果您的服务可以作为http://&lt;&lt;my system&gt;&gt;:8080/myapp/person/id 调用,您可以从 SOAP 请求中读取 id 并使用“REST_URL_POSTFIX”属性发送它,如下所示。

    <property name="REST_URL_POSTFIX" expression="//person/id" scope="axis2" type="STRING"/>
    

    看看this example,它实现了类似的场景。

    【讨论】:

      【解决方案2】:

      您也可以尝试使用 ESB 4.7.0 中新增的 HTTP Endpoint。您可以像在 REST API 中一样定义 URI 模板。填充模板变量是通过属性中介完成的 - 因此您可以对属性中介执行的任何操作都可以用于在中介运行时定义端点 URL。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-09-05
        • 1970-01-01
        • 2012-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多