2012-04-07 36 views
3

我開始與騾流,並已看到我見過這個頁面http://www.mulesoft.org/documentation/display/MULE3CONCEPTS/Using+Mule+with+Web+Serviceshttp://www.mulesoft.org/documentation/display/MULEWS/Consuming+SOAP+Web+Services+in+Mule這個OE了。他們沒有太大的幫助。目前,我有一個簡單的騾子流量,如下所示。如何在Mule流中使用SOAP Web服務?

流定義

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" 
    xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" 
    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.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.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="EchoFlow" doc:name="EchoFlow"> 
     <http:inbound-endpoint exchange-pattern="request-response" 
      host="localhost" port="8081" path="service/echoflow" doc:name="HTTP" /> 
     <cxf:jaxws-client operation="" serviceClass="com.myapp.demo.ServiceAImplService" 
      doc:name="SOAP"/> 
     <outbound-endpoint address="http://localhost:8080/ServiceA/services/" doc:name="Generic"/> 
    </flow> 
</mule> 

我使用的騾子工作室。有一個HTTP入站端點需要響應。我嘗試配置一個將調用實際Web服務的jax-ws客戶端。該服務的WSDL是:

wsdl文件

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="ServiceAImplService" targetNamespace="http://service.demo.myapp.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.demo.myapp.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <wsdl:types> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.demo.myapp.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<import namespace="http://service.demo.myapp.com/" schemaLocation="http://localhost:8080/ServiceA/services/ServiceAImplPort?xsd=serviceaimpl_schema1.xsd"/> 
</schema> 
    </wsdl:types> 
    <wsdl:message name="helloResponse"> 
    <wsdl:part element="tns:helloResponse" name="parameters"> 
    </wsdl:part> 
    </wsdl:message> 
    <wsdl:message name="hello"> 
    <wsdl:part element="tns:hello" name="parameters"> 
    </wsdl:part> 
    </wsdl:message> 
    <wsdl:portType name="IServiceA"> 
    <wsdl:operation name="hello"> 
     <wsdl:input message="tns:hello" name="hello"> 
    </wsdl:input> 
     <wsdl:output message="tns:helloResponse" name="helloResponse"> 
    </wsdl:output> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="ServiceAImplServiceSoapBinding" type="tns:IServiceA"> 
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="hello"> 
     <soap:operation soapAction="urn:Hello" style="document"/> 
     <wsdl:input name="hello"> 
     <soap:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output name="helloResponse"> 
     <soap:body use="literal"/> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="ServiceAImplService"> 
    <wsdl:port binding="tns:ServiceAImplServiceSoapBinding" name="ServiceAImplPort"> 
     <soap:address location="http://localhost:8080/ServiceA/services/ServiceAImplPort"/> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

我也不太清楚有關配置JAX-WS客戶端,你可以看到。那麼,我該如何在這個流程中使用SOAP Web服務。


我的第二個問題:我如何轉換有效負載以從一個Web服務調用另一個Web服務(都是SOAP)。流量是什麼?


最後,如何合併有效載荷?比方說,我有三個並行調用的Web服務,它們的響應都一起返回。如何合併有效載荷,以便我可以在另一個服務中讀取它(在並行調用多個服務的響應之後)?



什麼是利用CXF代理服務/客戶端的

 <pattern:web-service-proxy name="ex-proxy" 
     inboundAddress="http://localhost:8081/xxx" 
     outboundAddress="http://xx.xx.com/XXX_WS/xxxWService.asmx" /> 

相當於實施?這就讓我想到另一個問題:何時使用CXF服務以及何時使用CXF客戶端?最後,是否有Mule Flow Orchestration的詳細文檔或示例/教程?

+0

@Petter的回答給你提供了很好的線索。你的問題中有一點是不清楚的:你是否想要公開整體服務?作爲另一個Web服務或僅僅是一個普通的HTTP資源(如您的示例中所示)? – 2012-04-10 14:14:19

+0

我知道這些組件。但是,我不能正確配置它們,因爲沒有適當的文檔/示例!一個簡單的CXF代理示例將對幫助我有很大的幫助。我從不去尋求代碼,但我堅持了一個星期沒有任何進展! – r3st0r3 2012-04-10 21:47:03

+0

我看到jaxws-client的操作屬性是「」,這是不對的。您是否嘗試過使用「hello」?你會得到什麼錯誤? – 2012-04-10 21:59:00

回答

2

嘗試使用CXF代理(服務和客戶端)。在這種情況下,您會將原始XML導入流中。當然,如果需要,可以將它反序列化爲java,例如通過XML-To-Object轉換器(XStream)。

http://www.mulesoft.org/documentation/display/MULE3USER/Proxying+Web+Services+with+CXF

從那裏,有幾種方法可以做到在中間變換的有效載荷。或者通過Java(如上所述)並轉換java層對象或編寫一個XSLT表來進行轉換。或者使用Java和/或Mule提供的其他工具(腳本,xpath等)來轉換XML。

您可能想再次詳細解釋聚合情況。你想合併未來使用的響應或者有一個Web服務調用 - >扇出 - >聚合 - >響應?

+0

如果您想提供初始確認並繼續處理從請求中收到的數據,該怎麼辦? – 2017-03-02 23:39:11

+0

也許這是另一個問題。但通常在返回響應之前調用一些異步進程,如vm-endpoint,queue,async scope等。在異步/獨立線程中進一步處理。 – 2017-03-06 06:43:50

1

1)通常,您應該使用「代理服務」而不是「JAX-WS」來使用遠程Web服務。

2)使用鏈路由器在多個端點之間傳遞響應。

1

如果你有訪問網絡服務的服務端點接口,你可以輕鬆地使用web服務在這樣一個簡單的Java的組件:

public class CityServiceComponent { 

    public String process(String input) { 

     // list of cities 
     StringBuilder output = new StringBuilder(); 

     // create service factory 
     JaxWsProxyFactoryBean serviceFactory = new JaxWsProxyFactoryBean(); 
     // set service endpoint interface 
     serviceFactory.setServiceClass(CityService.class); 
     // set wsdl location 
     serviceFactory.setAddress("http://localhost:8080/city-service-provider/CityService?wsdl"); 
     // init city service 
     CityService cityService = (CityService) serviceFactory.create(); 

     // call city service and get all available cities 
     List<City> cities = cityService.findAll(); 

     // build list of cities 
     for (City city : cities) { 

      output.append(city.toString()); 
      output.append("\n"); 
     } 

     // forward output message 
     return output.toString(); 

    } 

} 

希望這有助於..