2012-12-21 87 views
5

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

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 Endpo INT响应

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

SOAP代理响应

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

非常感谢。

回答

5

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

然后SOAP请求您对ESB应该是这样的:

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

希望帮助:)

+0

非常感谢,这个例子非常有帮助。然而,我们仍然想知道 - 我们如何将SOAP XML参数转换为REST调用的查询参数?你能帮我吗? –

0

您可以使用类中介提取使用XPATH的SOAP参数。比构建REST URL并将其发送回IN顺序流。

0

1.你需要从SOAP代理,该值

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

3。你需要使用查询参数

传递价值的REST服务,你需要格式化从REST服务到SOAP格式

的SOAP请求将被响应,

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

可以存储从SOAP代理请求的值,

<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中介的格式返回响应,

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