首页 文章

使用带有WSO2 ESB的SOAP代理RESTful服务

提问于
浏览
5

我们想用SOAP代理RESTful Web服务 .

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

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

Example Request

SOAP代理请求:

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

REST endpoints 请求:

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

Example Response

REST endpoints 响应

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

SOAP代理响应

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

非常感谢 .

4 回答

  • 0

    如果我理解正确,您希望将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>
    

    希望有帮助:)

  • 5
  • 1

    您可以使用类介体使用XPATH提取SOAP参数 . 然后构建REST URL并将其发送回IN序列流 .

  • 0

    1. 您需要从SOAP PROXY获取值

    2. 您需要将其存储在本地变量中

    3. 您需要使用查询参数将值传递给REST SERVICE

    4. 您需要将REST服务的响应格式化为SOAP格式

    SOAP请求将是,

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

    您可以将SOAP PROXY Request的值存储为,

    <proxy xmlns="http://ws.apache.org/ns/synapse" name="RESTProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true><target>
      <inSequence>
          <property name="fromDate" expression="//fromDate" scope="default" type="STRING"/>
          <property name="toDate" expression="//toDate" scope="default" type="STRING"/>
    

    然后,您可以将值传递给REST服务,

    <send>
         <endpoint>  
               <http method="GET" uri-template="http://localhost/person?fromDate=={get-property('fromDate')}&amp;toDate={get-property('toDate')}"/>  
        </endpoint>
    </send>  
    </inSequence>
    

    然后您可以使用 PayloadFactory mediator格式化响应,

    <outSequence>  
    <payloadFactory media-type="xml">     
          <format>
                   <person>
                          <Name>$1</Name>
                          <Age>$2</Age>
                          <Sex>$3</Sex>
                    </person>
            </format>
                    <args>
                        <arg evaluator="json" expression="$.Name"/>
                        <arg evaluator="json" expression="$.Age"/>
                        <arg evaluator="json" expression="$.Sex"/>
                    </args>
     </payloadFactory>
         <send/>
      </outSequence>
       </target>
       <description/>
      </proxy>
    

    所以代理的响应将是,

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

相关问题