2012-02-13 106 views
1

我有一個客戶端,它連接到Web服務以獲取一些信息。我有一個要求,我必須將相同的信息發送到使用不同端口的多個服務。爲了解決這個問題而不修改客戶端代碼,我發現了MULE ESB,它應該完全符合我的需求。MULE ESB:將多個Web服務綁定到一個客戶端

我發現了一個指導,我可以使用MULE ESB和一個端口將一個客戶端連接到一個服務,但我無法找到一種鏈接服務的方法,以便他們都監聽一個端口,但它們本身不同。

這是它是如何應該看起來像: Conceptual Diagram

UPDATE:

這裏是我現在的騾子應用程序配置:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.2.1" 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-3.0.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> 
    <flow name="flows1Flow1" doc:name="flows1Flow1"> 
     <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:4433/miniwebservice" mimeType="text/xml" doc:name="HTTP"/> 
     <http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:4434/miniwebservice?wsdl" mimeType="text/xml" doc:name="HTTP"/> 
    </flow> 
</mule> 

這裏是WebService的:

客戶:

package miniwebservice; 

import java.net.URL; 
import javax.xml.namespace.QName; 
import javax.xml.ws.Service; 

public class TestWsClient 
{ 
    public static void main(final String[] args) throws Throwable 
    { 
     String url = (args.length > 0) ? args[0] : "http://localhost:4434/miniwebservice"; 
     Service service = Service.create(
      new URL(url + "?wsdl"), 
      new QName("http://miniwebservice/", "HalloWeltImplService")); 
     HalloWelt halloWelt = service.getPort(HalloWelt.class); 
     System.out.println("\n" + halloWelt.hallo(args.length > 1 ? args[1] : "")); 
    } 
} 

服務器:

package miniwebservice; 

import javax.xml.ws.Endpoint; 

public class TestWsServer 
{ 
    public static void main(final String[] args) 
    { 
     String url = (args.length > 0) ? args[0] : "http://localhost:4434/miniwebservice"; 
     Endpoint.publish(url, new HalloWeltImpl()); 
    } 
} 

InterfaceImpl:

package miniwebservice; 

import javax.jws.WebService; 

@WebService(endpointInterface="miniwebservice.HalloWelt") 
public class HalloWeltImpl implements HalloWelt 
{ 
    public String hallo(String wer) 
    { 
     return "Hallo " + wer; 
    } 
} 

接口:

package miniwebservice; 

import javax.jws.*; 

@WebService 
public interface HalloWelt 
{ 
    public String hallo(@WebParam(name = "wer") String wer); 
} 

如果我啓動服務器和騾子aplication併力爭達到http://localhost:4434/miniwebservice?wsdl奧爾http://localhost:4433/miniwebservice我在下面的例外我的瀏覽器(Firefox 8.0):

無法由於異常創建的SOAP消息:XML讀取器錯誤:javax.xml.stream.XMLStreamException:ParseError在[行,列]:[1,1] 消息:內容在序言中是不允許的。

我剛開始和Mule一起工作,所以我認爲這樣做將會得到重定向騾的服務來獲得wsdl,但它看起來像它有點複雜。

+0

這些Web服務的性質是什麼? SOAP風格?另外:如果Mule將3次調用的結果聚合在一起,或者選擇一個或使用不同的遠程服務作爲後備(call 1st,如果1st失敗,則回退到2nd)。 – 2012-02-13 17:24:59

+0

@David Dossot我編輯的問題增加了一些新的信息。 – Kiesa 2012-02-14 07:56:35

+0

從目標服務URL中除去?wsdl,否則將所有請求管理到WSDL生成器。 – 2012-02-14 16:21:34

回答

1

免責聲明:

  • 這不是最終解決整個問題,其中包括指派到若干服務和聚集的結果,但在正確方向邁出的一步。
  • 這不代表如何在Mule中完成Web服務代理(它是way simpler),而是一種用於HTTP請求路由的準系統方法,因此可以添加聚合。 ?

既然你要轉發HTTP GET請求到WSDL處理器和HTTP POST SOAP請求發送到Web服務,你需要處理目標的HTTP方法和請求URI傳播自己:

<flow name="flows1Flow1"> 
    <http:inbound-endpoint exchange-pattern="request-response" 
     address="http://localhost:4433/miniwebservice" /> 
    <message-properties-transformer scope="outbound"> 
     <add-message-property key="http.method" value="#[header:INBOUND:http.method]" /> 
    </message-properties-transformer> 
    <logger level="INFO" category="ddo" /> 
    <http:outbound-endpoint exchange-pattern="request-response" 
     address="http://localhost:4434#[header:INBOUND:http.request]" /> 
</flow> 

(使用TestWsClient和TestWsServer進行測試和驗證)