关于web服务:通过Apache Camel调用CXF webservice

Calling CXF webservice through Apache Camel

我正在尝试将 Apache CXF 与 Apache Camel 集成。
骆驼的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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 服务上的特定操作,我正在使用这个:

1
2
3
4
5
6
7
8
9
<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 服务。

请帮忙。


您可以调用以下命令来获取被调用的 CXF 操作名称...有关详细信息,请参阅 http://camel.apache.org/cxf.html

1
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


在 CXF 端点

1
2
3
4
5
    <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">

在骆驼端点

1
2
3
4
5
6
7
8
9
10
11
12
13
   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 Yadav 评论:更新

1
2
3
4
5
6
7
8
 <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