搜索

18.5. 使用 Spring 配置 CXF 端点

download PDF

您可以使用下面显示的 Spring 配置文件配置 CXF 端点,您还可以将端点嵌入到 camelContext 标签中。在调用服务端点时,您可以将 operationNameoperationNamespace 标头设置为显式状态您要调用的操作。

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:cxf="http://camel.apache.org/schema/cxf/jaxws"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/cxf/jaxws http://camel.apache.org/schema/cxf/jaxws/camel-cxf.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
     <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort"
            serviceClass="org.apache.hello_world_soap_http.GreeterImpl"/>
     <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" />
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
       <route>
         <from uri="cxf:bean:routerEndpoint" />
         <to uri="cxf:bean:serviceEndpoint" />
       </route>
    </camelContext>
  </beans>

务必包含 root Bean 元素上指定的 JAX-WS 模式Location 属性。这允许 CXF 验证文件,且是必需的。另请注意 < cxf:cxfEndpoint/& gt; 标签末尾的命名空间声明。这些声明是必需的,因为此标签的属性值当前不支持组合 {namespace}localName 语法。

cxf:cxfEndpoint 元素支持许多附加属性:

Name

portName

此服务的端点名称,它映射到 wsdl:port@name。以 ns:PORT_NAME 格式,其中 ns 是在这个范围内有效的命名空间前缀。

serviceName

此服务正在实现的服务名称,它映射到 wsdl:service@name。以 ns:SERVICE_NAME 格式,其中 ns 是在这个范围内有效的命名空间前缀。

wsdlURL

WSDL 的位置。可以位于 classpath、文件系统或远程托管。

bindingId

要使用的服务模型的 bindingId

address

服务发布地址。

总线

JAX-WS 端点中使用的总线名称。

serviceClass

SEI (Service Endpoint Interface)类的类名称,该类可以具有 JSR181 注解或不。

它还支持多个子元素:

Name

cxf:inInterceptors

此端点的传入拦截器。< bean> 或 &lt; ref> 列表。

cxf:inFaultInterceptors

此端点的传入错误拦截器。< bean> 或 &lt; ref> 列表。

cxf:outInterceptors

此端点传出的拦截器。< bean> 或 &lt; ref> 列表。

cxf:outFaultInterceptors

此端点传出的故障拦截器。< bean> 或 &lt; ref> 列表。

cxf:properties

应该向 JAX-WS 端点提供的属性映射。请参阅以下。

cxf:handlers

应该向 JAX-WS 端点提供 JAX-WS 处理程序列表。请参阅以下。

cxf:dataBinding

您可以指定在端点中使用的 DataBinding。这可以通过 Spring < bean class="MyDataBinding"/> 语法来提供。

cxf:binding

您可以为这个端点指定 BindingFactory。这可以通过 Spring < bean class="MyBindingFactory"/> 语法来提供。

cxf:features

保存此端点拦截器的功能。Bean 或 refs 列表

cxf:schemaLocations

要使用的端点的模式位置。schemaLocations 列表

cxf:serviceFactory

此端点要使用的服务工厂。这可以通过 Spring < bean class="MyServiceFactory"/> 语法提供

您可以找到更高级的示例,其中显示了如何在 CXF JAX-WS Configuration 页面上 提供拦截器、属性和处理程序。

注意

您可以使用 cxf:properties 设置 camel-cxf 端点的 dataFormat,并从 spring 配置文件中设置DefaultBus 属性。

<cxf:cxfEndpoint id="testEndpoint" address="http://localhost:9000/router"
     serviceClass="org.apache.camel.component.cxf.HelloService"
     endpointName="s:PortName"
     serviceName="s:ServiceName"
     xmlns:s="http://www.example.com/test">
     <cxf:properties>
       <entry key="dataFormat" value="RAW"/>
       <entry key="setDefaultBus" value="true"/>
     </cxf:properties>
   </cxf:cxfEndpoint>
注意

在 SpringBoot 中,您可以使用 Spring XML 文件来配置 camel-cxf,并使用类似以下示例的代码来创建 XML 配置的 Bean:

@ImportResource({
		"classpath:spring-configuration.xml"
})

但是,使用配置了 Bean 的 Java 代码(如其他示例所示)是在 SpringBoot 中最佳实践。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.