25.5. 端点选项


CXF 端点使用 URI 语法进行配置:

cxf:beanId:address
Copy to Clipboard Toggle word wrap

使用以下路径和查询参数:

25.5.1. 路径参数(2 参数)

Expand
Name描述默认值类型

beanId (common)

查找现有的已配置的 CxfEndpoint。必须使用 bean: 作为前缀。

 

字符串

地址 (service)

服务发布地址。

 

字符串

25.5.2. 查询参数(35 参数)

Expand
Name描述默认值类型

dataformat ( common)

CXF 端点支持的数据类型消息。

Enum 值:

  • PAYLOAD
  • RAW
  • MESSAGE
  • CXF_MESSAGE
  • POJO

POJO

DataFormat

wrapStyle (common)

WSDL 样式,用于描述在 SOAP 正文中如何表示参数。如果值为 false,则 CXF 将选择 document-literal unwrapped 风格,如果值为 true,则 CXF 将选择文档封装样式。

 

布尔值

bridgeErrorHandler (consumer)

允许将消费者桥接到 Camel 路由错误处理程序,这意味着当消费者试图选择传入消息或类似信息时发生异常,现在将作为消息处理并由路由 Error Handler 处理。默认情况下,使用者将使用 org.apache.camel.spi.ExceptionHandler 来处理例外情况,该处理程序将被记录在 WARN 或 ERROR 级别,并忽略。

false

布尔值

exceptionHandler (consumer (advanced))

要让使用者使用自定义例外处理程序:请注意,如果启用了 bridgeErrorHandler 选项,则此选项不使用。默认情况下,消费者将处理异常,其记录在 WARN 或 ERROR 级别中,并忽略。

 

ExceptionHandler

exchangePattern (consumer (advanced))

在消费者创建交换时设置交换模式。

Enum 值:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

cookieHandler (producer)

配置 Cookie 处理程序来维护 HTTP 会话。

 

CookieHandler

defaultOperationName (producer)

这个选项将设置默认 operationName,供调用远程服务的 CxfProducer 使用。

 

字符串

defaultOperationNamespace (producer)

这个选项将设置默认 operationNamespace,供调用远程服务的 CxfProducer 使用。

 

字符串

hostnameVerifier (producer)

要使用的主机名验证器。使用 # 表示法引用 registry 中的 HostnameVerifier。

 

HostnameVerifier

lazyStartProducer (producer)

生成者是否应懒惰启动 (在第一个消息中)。通过懒惰启动,您可以使用此选项来允许 CamelContext 和路由在生成者启动期间启动,并导致路由启动失败。通过懒惰启动,启动失败可以在路由信息时通过 Camel 的路由错误处理程序进行处理。请注意,在处理第一个消息时,创建并启动生成者可能需要稍等时间,并延长处理的总处理时间。

false

布尔值

sslContextParameters (producer)

Camel SSL 设置参考。使用 # 表示法引用 SSL 上下文。

 

SSLContextParameters

wrap (producer)

CXF 端点制作者将调用哪些操作。

false

布尔值

同步 (producer (advanced))

设置是否应严格使用同步处理。

false

布尔值

allowStreaming (advanced)

这个选项控制在 PAYLOAD 模式运行时 CXF 组件是否会将传入的消息解析为 DOM Elements,或将有效负载保留为 javax.xml.transform.Source 对象,在某些情况下允许流。

 

布尔值

Bus (advanced)

使用自定义配置的 CXF 总线。

 

bus

continuationTimeout (advanced)

这个选项用于设置 CXF 持续超时,在 CXF 服务器使用 Jetty 或 Servlet 传输时,默认可在 CxfConsumer 中使用。

30000

long

cxfBinding (advanced)

使用自定义 CxfBinding 控制 Camel 消息和 CXF 消息之间的绑定。

 

CxfBinding

cxfConfigurer (advanced)

这个选项可以应用 org.apache.camel.component.cxf.CxfEndpointConfigurer 的实现,它支持以编程方式配置 CXF 端点。用户可以通过实施 CxfEndpointConfigurer 的 configure{ServerClient} 方法来配置 CXF 服务器和客户端。

 

CxfConfigurer

defaultBus (advanced)

当 CXF 端点本身创建总线时,将设置默认总线。

false

布尔值

headerFilterStrategy (advanced)

使用自定义 HeaderFilterStrategy 过滤标头到 Camel 消息。

 

HeaderFilterStrategy

mergeProtocolHeaders (advanced)

是否合并协议标头。如果启用,则在 Camel 和 CXF 之间传播标头变得更为一致且类似。如需了解更多详细信息,请参阅 CAMEL-6393。

false

布尔值

mtomEnabled (advanced)

启用 MTOM (attachments)。这需要使用 POJO 或 PAYLOAD 数据格式模式。

false

布尔值

properties (advanced)

使用 Map 中的键/值对设置额外的 CXF 选项。例如,若要在 SOAP 故障中打开 stacktrace,properties.faultStackTraceEnabled=true。

 

Map

skipPayloadMessagePartCheck (advanced)

设置是否应禁用 SOAP 消息验证。

false

布尔值

loggingFeatureEnabled (logging)

这个选项启用 CXF Logging 功能,将入站和出站 SOAP 消息写入日志。

false

布尔值

loggingSizeLimit (logging)

要限制在启用了日志记录功能时日志记录器将输出的字节数,并且 -1 代表没有限制。

49152

int

skipFaultLogging (logging)

这个选项控制 PhaseInterceptorChain 是否跳过记录它捕获的 Fault。

false

布尔值

password (security)

这个选项用于为 CXF 客户端设置密码的基本身份验证信息。

 

字符串

用户名 (安全性)

这个选项用于为 CXF 客户端设置 username 的基本身份验证信息。

 

字符串

bindingId (service)

要使用的服务模型的 bindingId。

 

字符串

portName (service)

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

 

字符串

publishedEndpointUrl (service)

此选项可以覆盖从 WSDL 发布的 endpointUrl,该Url可以通过服务地址 url 和 wsd 进行访问。

 

字符串

serviceClass (service)

SEI (Service Endpoint Interface)类的类名称,它们可能具有 JSR181 注释。

 

serviceName (service)

此服务正在实现的服务名称,它映射到 wsdl:servicename。

 

字符串

wsdlURL (service)

WSDL 的位置。可以位于类路径、文件系统上,也可以远程托管。

 

字符串

serviceNameportNameQNames,因此如果您提供它们,请确保它们带有其 {namespace} 前缀,如上例中所示。

25.5.3. dataformats 的描述

在 Apache Camel 中,Camel CXF 组件是将路由与 Web 服务集成的关键。您可以使用 Camel CXF 组件创建 CXF 端点,该端点可通过以下方法之一使用:

  • consumer - (路由开始时)代表 Web 服务实例,它与路由集成。注入路由的有效负载类型取决于端点的 dataFormat 选项的值。
  • 制作者 - (路由中的其他点)代表 WS 客户端代理,它将当前交换对象转换为远程 Web 服务的操作调用。当前交换的格式必须与端点的 dataFormat 设置匹配。
Expand
DataFormat描述

POJO

POJO (老的 Java 对象)是目标服务器上调用的方法的 Java 参数。支持 Protocol 和 Logical JAX-WS 处理程序。

PAYLOAD

PAYLOAD 是应用 CXF 端点的消息配置后的消息有效负载( soap:body的内容)。仅支持 Protocol JAX-WS 处理程序。不支持逻辑 JAX-WS 处理程序。

RAW

RAW 模式提供从传输层接收的原始消息流。如果您正在使用这种类型的 DataFormat,则无法处理或更改流,则一些 CXF 拦截器会被删除,因此您可以在 camel-cxf 消费者后看到任何 soap 标头。不支持 JAX-WS 处理程序。

CXF_MESSAGE

CXF_MESSAGE 通过将消息从传输层转换为原始 SOAP 消息来调用 CXF 拦截器的完整功能

您可以通过检索交换属性 CamelCXFDataFormat 来确定交换的数据格式模式。Exchange key 常量在 org.apache.camel.component.cxf.common.message.CxfConstants.DATA_FORMAT_PROPERTY 中定义。

CXF 的 LoggingOutInterceptor 输出在有线路到日志记录系统(Java Util Logging)的出站消息。由于 LoggingOutInterceptor 位于 PRE_STREAM 阶段(但 PRE_STREAM 阶段在 RAW 模式中被删除),因此您必须配置 LoggingOutInterceptor 以便在 WRITE 阶段运行。以下是一个示例。

@Bean
public CxfEndpoint serviceEndpoint(LoggingOutInterceptor loggingOutInterceptor) {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setAddress("http://localhost:" + port
                            + "/services" + SERVICE_ADDRESS);
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.HelloService.class);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("dataFormat", "RAW");
    cxfEndpoint.setProperties(properties);
    cxfEndpoint.getOutInterceptors().add(loggingOutInterceptor);
    return cxfEndpoint;
}


@Bean
public LoggingOutInterceptor loggingOutInterceptor() {
    LoggingOutInterceptor logger = new LoggingOutInterceptor("write");
    return logger;
}
Copy to Clipboard Toggle word wrap

25.5.5. relayHeaders 选项的描述

有来自一个 JAXWS WSDL-first 开发者的 in-bandout-of-band on-the-wire 标头。

in-band 标头是标头,作为端点的 WSDL 绑定合同的一部分(如 SOAP 标头)明确定义。

带外 标头是通过线上序列化但不是 WSDL 绑定合同的一部分的标头。

标头转发/过滤是双向的。

当路由具有 CXF 端点且开发人员需要具有 on-the-wire 标头(如 SOAP 标头)时,将路由转发给另一个 JAXWS 端点,然后应将 relayHeaders 设置为 true,这是默认值。

25.5.6. 仅适用于 POJO 模式

relayHeaders=true 表示转发标头的意图。关于给定标头是否被中继到实施 MessageHeadersRelay 接口的可插拔实例的实际决定。将参考 MessageHeadersRelay 的具体实施,以确定是否需要转发标头。已有 SoapMessageHeadersRelay 的实现,它将自身绑定到众所周知的 SOAP 命名空间。目前,仅过滤带外标头,当 relayHeaders=true 时,in-band 标头始终会被转发。如果线上有一个标头,其命名空间对运行时未知,则将使用 fall back DefaultMessageHeadersRelay,这只是允许所有标头进行转发。

relayHeaders=false 设置指定所有标头 in-band 和 out-of-band 应该被丢弃。

您可以插件自己的 MessageHeadersRelay 实现覆盖,或向中继列表添加额外的消息。为了覆盖预加载的中继实例,请确保您的 MessageHeadersRelay 实现服务与您要覆盖的命名空间相同。另请注意,覆盖中继必须为您要覆盖的所有命名空间提供服务,否则路由启动时的运行时异常将会抛出,因为这会在命名空间中引入一个模糊性来转发实例映射。

<cxf:cxfEndpoint ...>
   <cxf:properties>
     <entry key="org.apache.camel.cxf.message.headers.relays">
       <list>
         <ref bean="customHeadersRelay"/>
       </list>
     </entry>
   </cxf:properties>
 </cxf:cxfEndpoint>
 <bean id="customHeadersRelay" class="org.apache.camel.component.cxf.soap.headers.CustomHeadersRelay"/>
Copy to Clipboard Toggle word wrap

查看显示如何在这里转发/过滤标头的测试:

https://github.com/apache/camel/blob/main/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest.java

  • 支持 POJOPAYLOAD 模式。在 POJO 模式中,只有带外消息标头可用于过滤,因为已由 CXF 处理并从标头列表中删除。in-band 标头会合并到 POJO 模式的 MessageContentList 中。camel-cxf 组件会有任何尝试从 MessageContentList 中删除带内标头。如果需要过滤带内标头,请使用 PAYLOAD 模式或插入 CXF 端点中的 CXF 拦截器/JAXWS 处理程序。
  • Message Header Relay 机制已合并到 CxfHeaderFilterStrategy 中。relayHeaders 选项、其语义和默认值保持不变,但它是 CxfHeaderFilterStrategy 的属性。下面是一个配置它的示例:
@Bean
public HeaderFilterStrategy dropAllMessageHeadersStrategy() {
    CxfHeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
    headerFilterStrategy.setRelayHeaders(false);
    return headerFilterStrategy;
}
Copy to Clipboard Toggle word wrap

然后,您的端点可以引用 CxfHeaderFilterStrategy

@Bean
public CxfEndpoint routerNoRelayEndpoint(HeaderFilterStrategy dropAllMessageHeadersStrategy) {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
    cxfEndpoint.setAddress("/CxfMessageHeadersRelayTest/HeaderService/routerNoRelayEndpoint");
    cxfEndpoint.setWsdlURL("soap_header.wsdl");
    cxfEndpoint.setEndpointNameAsQName(
        QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortNoRelay"));
    cxfEndpoint.setServiceNameAsQName(SERVICENAME);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("dataFormat", "PAYLOAD");
    cxfEndpoint.setProperties(properties);
    cxfEndpoint.setHeaderFilterStrategy(dropAllMessageHeadersStrategy);
    return cxfEndpoint;
}

@Bean
public CxfEndpoint serviceNoRelayEndpoint(HeaderFilterStrategy dropAllMessageHeadersStrategy) {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
    cxfEndpoint.setAddress("http://localhost:" + port + "/services/CxfMessageHeadersRelayTest/HeaderService/routerNoRelayEndpointBackend");
    cxfEndpoint.setWsdlURL("soap_header.wsdl");
    cxfEndpoint.setEndpointNameAsQName(
        QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortNoRelay"));
    cxfEndpoint.setServiceNameAsQName(SERVICENAME);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("dataFormat", "PAYLOAD");
    cxfEndpoint.setProperties(properties);
    cxfEndpoint.setHeaderFilterStrategy(dropAllMessageHeadersStrategy);
    return cxfEndpoint;
}
Copy to Clipboard Toggle word wrap

然后,按如下所示配置路由:

rom("cxf:bean:routerNoRelayEndpoint")
    .to("cxf:bean:serviceNoRelayEndpoint");
Copy to Clipboard Toggle word wrap
  • MessageHeadersRelay 接口稍微改变,并被重命名为 MessageHeaderFilter。它是 CxfHeaderFilterStrategy 的一个属性。以下是配置用户定义的消息标头过滤器的示例:
@Bean
public HeaderFilterStrategy customMessageFilterStrategy() {
    CxfHeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
    List<MessageHeaderFilter> headerFilterList = new ArrayList<MessageHeaderFilter>();
    headerFilterList.add(new SoapMessageHeaderFilter());
    headerFilterList.add(new CustomHeaderFilter());
    headerFilterStrategy.setMessageHeaderFilters(headerFilterList);
    return headerFilterStrategy;
}
Copy to Clipboard Toggle word wrap
  • 除了 relayHeaders 外,还可以在 CxfHeaderFilterStrategy 中配置以下属性。
Expand
Name必填描述

relayHeaders

所有消息标头都将由 Message Header Filters Type:boolean Default:true处理

relayAllMessageHeaders

所有消息标头都会被传播(不由消息标头过滤器处理) Type:booleanDefault:false

allowFilterNamespaceClash

如果激活命名空间中的两个过滤器重叠,则属性控制应如何处理它。如果值为 true,则最后一个优先。如果值为 false,它将抛出异常 类型布尔值 默认值:false

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat