Mule ESB-3.Build a webservice proxy

自從引入ESB後,系統之間再也不直接依賴。我負責的這塊,主要是解決Webservice的問題。使系統A再也不直接依賴系統B的Webservice。
咱們選擇的產品是Mule ESB。因此天然要使用Mule 建立一個Webservice代理,即系統A請求到ESB,ESB請求系統B。

準備工做:
經過個人博客 Mule ESB-Basic Studio Tutorial 瞭解Mule ESB的基本操做。並準備開發環境。

環境:
windows 8
jdk 1.6
mule-standalone-3.5.0-M4
MuleStudio-for-win-32bit-3.5.0-201312091746

主要步驟:
一、新建一個Mule Project
二、建立一個流程

這兩步很是easy,再也不贅述。操做結果:

三、編輯流程
    (1)新建一個flow
            打開gxpt_test_esb_1.0.mflow,拖一個flow scope 進去。命名爲HttpProxyService。

    (2)加入HTTP Endpoint
            加入HTTP Endpoint,並且右擊轉換爲outbound endpoint,打開屬性窗體,輸入address。即Webservice的endpoint。 http://192.168.24.46:8080/test_server_webservice/UserManagerBean

      (3)爲這個Webservice建立一個client
               加入一個SOAP Component到http endpoint的前面,編輯它的屬性,設置operation爲proxy client
     
     (4)建立一個真正的代理服務
             加入還有一個 SOAP Component到 proxy client SOAP的前面,設置operation爲proxy service。設置 Namespace 和 Service,必須和你要代理的Webservice的wsdl相符。在 WSDL Location中填上wsdl的地址, http://192.168.24.46:8080/test_server_webservice/UserManagerBean?wsdl
也可以將該文件放在項目的目錄中。如src/
    
      (5)加入一個 HTTP inbound endpoint,設置address。如 http://192.168.24.12:8888/UserManager    

最後,完整的flow應該是如下這個樣子:


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <flow name="HttpProxyService" doc:name="HttpProxyService">
        <http:inbound-endpoint exchange-pattern="request-response" address="http://192.168.24.12:8888/UserManager" doc:name="HTTP"/>
        <!-- wsdlLocation="service/UserManagerBean.wsdl" 也可以使用該屬性替換掉url-->
        <cxf:proxy-service namespace="http://ejb.jialin.com/" service="UserManagerBean" payload="body"  wsdlLocation="http://192.168.24.46:8080/test_server_webservice/UserManagerBean?wsdl" doc:name="SOAP"/>
        <cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="SOAP"/>
        <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://192.168.24.46:8080/test_server_webservice/UserManagerBean" doc:name="HTTP"/>
    </flow>
    <flow name="gxpt_test_esb_1.0Flow1" doc:name="gxpt_test_esb_1.0Flow1"/>
</mule>

OK,接下你可以run mule server,在瀏覽器中輸入wsdl地址。看一下結果啦。
假設輸入代理地址和直接輸入目標地址。顯示的wsdl同樣,說明配置正確。



小結:
在這篇文章中,我介紹了怎樣使用mule建立一個Webservice代理,不需要使用不論什麼轉換器。也不需要寫一行代碼。全然是配置完畢的。

在興許文章中將繼續聊Mule ESB,敬請關注。
相關文章
相關標籤/搜索