4

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

我的简单 RESTful 服务可以像http://<<my system>>:8080/myapp/person/read 响应一样被调用,我获取JSONPerson 实体的数据。

问题:我无法将参数传递给 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>

我有另一个 RESTful 服务,其GET方法和 id 作为 URL 本身的一部分,并且工作正常。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>

感谢任何指示或帮助。

4

2 回答 2

2

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

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

看看这个实现类似场景的例子。

于 2013-07-11T12:06:59.437 回答
1

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

于 2013-07-11T16:59:51.330 回答