2012-04-24 94 views
2

我正在嘗試將Apache CXF與Apache Camel集成。 配置駱駝:通過Apache Camel調用CXF webservice

<cxf:cxfEndpoint id="authTest" 
     address="/cxfAuth" 
     serviceClass="com.test.AuthService" > 
     <cxf:properties> 
      <entry key="dataFormat" value="POJO" /> 
      <entry key="setDefaultBus" value="true" /> 
     </cxf:properties> 
    </cxf:cxfEndpoint> 

    <camel:camelContext trace="true"> 
     <camel:route> 
      <camel:from uri="cxf:bean:authTest" /> 
      <camel:to uri="bean:routeExitResponseProcessor"/> 
     </camel:route> 
    </camel:camelContext> 

我們調用Web服務的具體操作我用這:

<camel:route> 
      <camel:from uri="direct:startAuthTest"/> 
      <camel:setHeader headerName="getEmployee"> 
       <camel:constant>gid</camel:constant> 
      </camel:setHeader> 
      <camel:to uri="cxf:bean:authTest" /> 
      <camel:log message=">>> data is : ${body}"/> 
      <camel:to uri="bean:routeExitResponseProcessor"/> 
     </camel:route> 

但包括上述的配置,我在服務器控制檯上獲得WARN ServletController:149 - Can't find the the request for http://localhost:8080/CXFService/services/cxfAuth's Observer後我的web服務不在瀏覽器中找到。

請幫忙。

回答

2

您可以撥打以下,以獲得CXF操作名稱被稱爲...看到http://camel.apache.org/cxf.html更多細節

String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME); 

也,見例如使用這個單元測試...

http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java

+0

然後根據操作的名字我已經把中如果有很多...別人。有沒有乾淨的方法來做到這一點? – 2012-04-24 19:06:41

+1

請參閱我包含的單元測試示例,但基本上choice()stmts可以用在beans/processors等的路由或條件中...... – 2012-04-24 20:38:27

+0

有沒有什麼辦法在camel配置文件中配置它? – 2012-04-25 19:12:47

0

在CXF端點

<cxf:cxfEndpoint id="yourServiceCall" 
    address="http://localhost:8181/yourservice/services/yourserviceport" 
    wsdlURL="wsdl/yourwsdl.wsdl" xmlns:ns="http://service.your.com" 
    endpointName="ns:YourServicePort" serviceName="ns:yourService" 
    serviceClass="com.service.YourServicePortType"> 

和駱駝端點

camelContext id="camelId" xmlns="http://camel.apache.org/schema/spring"> 
    <camel:dataFormats> 
     <camel:jaxb contextPath="com.your.service" id="jaxb" /> 
    </camel:dataFormats> 

    <route id="route1"> 
     <from uri="cxf:bean:yourServiceCall?dataFormat=PAYLOAD" /> 
     <camel:unmarshal ref="jaxb" /> 
     <log message="log: Called from cxf endpoint" /> 
     <!-- Your Logic --> 
     <camel:process ref="ExitResponseProcessor"/> 
     <camel:marshal ref="jaxb" /> 
    </camel:route> 

基於人士Himanshu亞達夫評論:更新

<camel:choice> 
<camel:when> 
<camel:simple>${body} is com.your.service.YourRequest</camel:simple> 
<!-- Your Logic or call any bean method with <camel:bean ref="YourBean " method="YourMethod"/ /> --> 
</camel:when> 
<camel:when> </camel:when> 
<camel:otherwise> </camel:otherwise> 
</camel:choice