使用apache camel和CXF时,在Web服务中调用特定方法

时间:2013-09-12 11:56:56

标签: web-services cxf apache-camel

我正在使用Apache Camel和端点的CXF Spring配置如何调用特定方法。即如果wsdl已经定义了我需要的10种方法 将10 cxfEndpoint暴露给站点,或者可以通过调用对其进行参数化 不知何故?如何插入“方法名称”以便在该服务中调用?

 <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort"
        wsdlURL="testutils/hello_world.wsdl"
        serviceClass="org.apache.hello_world_soap_http.Greeter"
        endpointName="s:SoapPort"
        serviceName="s:SOAPService"
    xmlns:s="http://apache.org/hello_world_soap_http" />

1 个答案:

答案 0 :(得分:1)

因此,当您使用5个操作创建WSDL时,在CXF中运行WSDL2JAVA工具时将公开这5个操作。

让我们假设我有一个带有2个操作的WSDL,如下所示:

  1. GetClient
  2. ListClient
  3. 在camel中,当我将此路由公开为camel使用者时,我可以通过检查消息上的headers.operationName属性来查看执行了哪个操作。

    例如,当用户执行GetClient操作时,headers.operationName将等于字符串"GetClient"

    所以我可以创建一个如下的路由来处理不同的操作:

        <from uri="cxf:bean:AccountsService?dataFormat=POJO"/>
        <doTry>
            <choice>
                <when>
                    <simple>${headers.operationName} == 'GetClient'</simple>
                    <bean ref="GetClientBean"/>
                </when>
                <when>
                    <simple>${headers.operationName} == 'ListClient'</simple>
                    <bean ref="ListClientBean"/>
                </when>
                <when>
                    <simple>${headers.operationName} == 'SomeOtherOperation'</simple>
                    <bean ref="SomeOtherBean"/>
                </when>
            </choice>
    

    如果要限制暴露的操作,可以简单地抛出异常或在您不想公开的操作上构造错误消息。

    玩得开心!

相关问题