2016-07-19 55 views
0

我在Apache Camel和CXF中遇到了一個有趣的困境。如何明確定義Apache Camel CXF消費者和生產者

我嘗試建立以下路線。

from("servlet://proxy?matchOnUriPrefix=true") .to("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE");

`from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE").to("file:/META-INF/data/test.xml");` 

我的願望其實是接收與Servlet組件的要求,做一些與(處理器,轉換等,但我不包括在這裏爲簡單起見)重定向這對我的web服務的實現和文件組件會將文件的內容作爲結果返回給WebService。

問題是,如果我從端點'from("servlet://proxy?matchOnUriPrefix=true")'路由到端點'to("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")'駱駝認爲這應該是CXF Consumer,但我希望它是一個生產者。

所以我其實我喜歡從from("servlet://proxy?matchOnUriPrefix=true")到'from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")',但我找不到一個辦法。

如果我配置爲第一個配置,servlet組件接收到請求,路由到CXF:consumer然後它啓動到CXF的TCP調用:'from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")'中定義的生產者它有效,但它很奇怪,我不想要開始一個TCP通話,我只想讓這個消息去'from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE")'。

有沒有一種方法可以達到我想要什麼?我可以定義一個CXF消費者或提供者,然後使用'from','to'?

有趣地我與ServiceMix的/保險絲類似的東西。

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:osgiRouter="http://osgi.salgar.org/osgirouter" 
    xmlns:http="http://servicemix.apache.org/http/1.0" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
         http://servicemix.apache.org/http/1.0 http://servicemix.apache.org/http/1.0/servicemix-http.xsd"> 

    <http:consumer service="http:FindOrders" endpoint="httpEndpoint" locationURI="http://localhost:8088/MockB2BService" 
     defaultMep="http://www.w3.org/2004/08/wsdl/in-out" targetService="osgiRouter:mediation" /> 

    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" /> 
</beans> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:eip="http://servicemix.apache.org/eip/1.0" 
    xmlns:osgiRouter="http://osgi.salgar.org/osgirouter" 
    xmlns:orderProvider_v1="http://v1.salgar.org/B2BService" 
    xmlns:orderProvider_v2="http://v2.salgar.org/B2BService" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
         http://servicemix.apache.org/eip/1.0 http://servicemix.apache.org/eip/1.0/servicemix-eip.xsd"> 

    <eip:content-based-router endpoint="osgiRouterMediation" 
     service="osgiRouter:mediation"> 
     <eip:rules> 
      <eip:routing-rule> 
       <eip:predicate> 
        <eip:xpath-predicate id="wsdl_version_predicate_v1" 
         xpath="(//namespace::*[.='http://v1.salgar.org/B2BService']) = 'http://v1.salgar.org/B2BService'" /> 
       </eip:predicate> 
       <eip:target> 
        <eip:exchange-target service="orderProvider_v1:findOrders" /> 
       </eip:target> 
      </eip:routing-rule> 
      <eip:routing-rule> 
       <eip:predicate> 
        <eip:xpath-predicate id="wsdl_version_predicate_v2" 
         xpath="(//namespace::*[.='http://v2.salgar.org/B2BService']) = 'http://v2.salgar.org/B2BService'" /> 
       </eip:predicate> 
       <eip:target> 
        <eip:exchange-target service="orderProvider_v2:findOrders" /> 
       </eip:target> 
      </eip:routing-rule> 
     </eip:rules> 
    </eip:content-based-router> 

    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" /> 
</beans> 




<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0" 
    xmlns:orderProvider_v1="http://v1.salgar.org/B2BService" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
         http://servicemix.apache.org/cxfbc/1.0 http://servicemix.apache.org/cxfbc/1.0/servicemix-cxf-bc.xsd"> 
    <cxfbc:provider endpoint="findOrdersProviderEndpoint" 
     useJBIWrapper="false" wsdl="classpath:v1/B2BService.wsdl" service="orderProvider_v1:findOrders" 
     locationURI="http://localhost:8989/MockB2BService" /> 

    <bean class="org.apache.servicemix.common.osgi.EndpointExporter" /> 
</beans> 

預期其中一期工程但我可以明確地定義端點CXF提供者,做我這裏有同樣的可能性大嗎?

回答

0

如果我沒有理解你的問題所在,這將工作(和駱駝理想的解決方案)

路線A

from("servlet://proxy?matchOnUriPrefix=true") 
.to("direct:webservice-business-logic") 
.to("direct:process-to-file"); 

B線

from("direct:webservice-business-logic") 
.to("actual-processors-to-do-webservice-business-logic"); 

路線C

from("cxf:/incident?wsdlURL=wsdl/OrderInfoService.wsdl&dataFormat=MESSAGE") 
.to("direct:webservice-business-logic); 

基本上,Route C w生病只能由希望使用網絡服務的外部人士使用。

路線B將僅由路線A中使用,所以,路線B是指內部駱駝處理。因爲調用Web服務沒有意義,Web服務邏輯也位於駱駝路由中。

希望這會有所幫助!

+0

如果我使用「從( 「servlet的://代理matchOnUriPrefix =真正的」)。爲了 ( 「CXF:?/事件WSDLURL = WSDL/OrderInfoService.wsdl&DATAFORMAT =報」)。爲了 (「文件:/ META-INF/data/test.xml「);'和'to(」cxf:/ incident?wsdlURL = wsdl/OrderInfoService。wsdl&dataFormat = MESSAGE「)'嘗試使用web服務(進行TCP調用)不生成它(提供web服務的實現邏輯)至少它在我的測試平臺中以這種方式工作 – posthumecaver

+0

您的解釋不明確,但我已經更新了答案,希望它有幫助,讓我知道如果它仍然沒有幫助 – gnanagurus

+0

不幸的是,我的用例更奇怪,你做內部調用Web服務的假設沒有任何意義,但我想,當我從servlet端點接收到調用並且路由到web服務端點時,我仍然希望檢查wsdl符合性,另外我在調用時還有一些web服務器頭文件,他們也應該在Web服務端點進行解釋,因此我需要一個內部Web服務終點 – posthumecaver