29.5. 端点选项
CXF 端点使用 URI 语法进行配置:
cxf:beanId:address
使用以下路径和查询参数:
29.5.1. 路径参数(2 参数) 复制链接链接已复制到粘贴板!
| Name | 描述 | 默认值 | 类型 |
|---|---|---|---|
| beanId (common) | 要查找现有的配置的 CxfEndpoint。必须使用 bean: 作为前缀。 | 字符串 | |
| 地址 (服务) | 服务发布地址。 | 字符串 |
29.5.2. 查询参数(35 参数) 复制链接链接已复制到粘贴板!
| Name | 描述 | 默认值 | 类型 |
|---|---|---|---|
| dataformat ( common) | CXF 端点支持的数据类型消息。 Enum 值:
| POJO | DataFormat |
| wrapStyle (common) | WSDL 风格,用于描述 SOAP 正文中如何表示参数。如果值为 false,则 CXF 将选择 document-literal unwrapped 风格,如果值为 true,则 CXF 将选择 document-literal 包装风格。 | 布尔值 | |
| bridgeErrorHandler (consumer) | 允许将消费者桥接到 Camel 路由错误处理程序,这意味着当消费者试图选择传入消息或类似信息时发生异常,现在将作为消息处理并由路由 Error Handler 处理。默认情况下,使用者将使用 org.apache.camel.spi.ExceptionHandler 来处理例外情况,该处理程序将被记录在 WARN 或 ERROR 级别,并忽略。 | false | 布尔值 |
| exceptionHandler (consumer (advanced)) | 要让使用者使用自定义例外处理程序:请注意,如果启用了 bridgeErrorHandler 选项,则此选项不使用。默认情况下,消费者将处理异常,其记录在 WARN 或 ERROR 级别中,并忽略。 | ExceptionHandler | |
| exchangePattern (consumer (advanced)) | 在消费者创建交换时设置交换模式。 Enum 值:
| 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) | 这个选项控制 CXF 组件在 PAYLOAD 模式下运行时,将 DOM 解析传入的消息到 DOM Elements 中,或者将有效负载保留为 javax.xml.transform.Source 对象,允许在某些情况下流。 | 布尔值 | |
| 总线 (advanced) | 使用自定义配置的 CXF 总线。 | Bus | |
| continuationTimeout (advanced) | 这个选项用于设置 CXF continuation 超时,当 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 | 布尔值 |
| 属性 (advanced) | 使用映射中的键/值对设置额外的 CXF 选项。例如,要在 SOAP 错误中打开 stacktrace,即 properties.faultStackTraceEnabled=true。 | Map | |
| skipPayloadMessagePartCheck (advanced) | 设置是否应禁用 SOAP 消息验证。 | false | 布尔值 |
| loggingFeatureEnabled (logging) | 这个选项启用了 CXF 日志记录功能,将入站和出站 SOAP 消息写入日志。 | false | 布尔值 |
| loggingSizeLimit (logging) | 为限制启用日志记录功能时,日志记录器将输出的字节数,以及 -1 代表没有限制。 | 49152 | int |
| skipFaultLogging (logging) | 这个选项控制 PhaseInterceptorChain 是否跳过记录它捕获的 Fault。 | false | 布尔值 |
| 密码 (security) | 这个选项用于为 CXF 客户端设置密码的基本身份验证信息。 | 字符串 | |
| 用户名 (security) | 这个选项用于为 CXF 客户端设置用户名的基本身份验证信息。 | 字符串 | |
| bindingId (service) | 要使用的服务模型的 bindingId。 | 字符串 | |
| portName (service) | 此服务实施的端点名称,它映射到 wsdl:portname。在 ns:PORT_NAME 格式中,其中 ns 是在此范围内有效的命名空间前缀。 | 字符串 | |
| publishedEndpointUrl (service) | 此选项可覆盖从 WSDL 发布的 endpointUrl,该端点可通过服务地址 url 和 wsd 进行访问。 | 字符串 | |
| serviceClass (service) | 可以具有 JSR181 注解或没有该类的 SEI (服务端点接口)类的名称。 | 类 | |
| serviceName (service) | 此服务实施的服务名称,它映射到 wsdl:servicename。 | 字符串 | |
| wsdlURL (service) | WSDL 的位置。可以在 classpath、文件系统上,也可以远程托管。 | 字符串 |
serviceName 和 portName 是 QNames,因此如果您为它们提供,请务必为其添加 {namespace} 前缀,如上例中所示。
29.5.3. dataformats 的描述 复制链接链接已复制到粘贴板!
在 Apache Camel 中,Camel CXF 组件是与 Web 服务集成路由的关键。您可以使用 Camel CXF 组件创建 CXF 端点,该端点可采用以下任一方式使用:
- consumer - (在路由的开头)代表一个与路由集成的 Web 服务实例。注入到路由的有效负载类型取决于端点的 dataFormat 选项的值。
- producer -(路由中的其他点)代表 WS 客户端代理,它将当前的交换对象转换为远程 Web 服务的操作调用。当前交换的格式必须与端点的 dataFormat 设置匹配。
| DataFormat | 描述 |
|---|---|
|
| POJO (旧 Java 对象)是目标服务器上调用的方法的 Java 参数。支持协议和逻辑 JAX-WS 处理程序。 |
|
|
|
|
|
|
|
|
|
您可以通过检索交换属性 CamelCXFDataFormat 来确定交换的数据格式模式。Exchange key 常量在 org.apache.camel.component.cxf.common.message.CxfConstants.DATA_FORMAT_PROPERTY 中定义。
29.5.4. 如何在 RAW 模式中启用 CXF 的 LoggingOutInterceptor 复制链接链接已复制到粘贴板!
CXF 的 LoggingOutInterceptor 输出位于有线到日志记录系统(Java Util Logging)的出站消息。由于 LoggingOutInterceptor 处于 PRE_STREAM 阶段(但 PRE_STREAM 阶段被删除为 RAW 模式),因此您必须在 WRITE 阶段运行 LoggingOutInterceptor。以下是一个示例。
@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;
}
29.5.5. relayHeaders 选项的描述 复制链接链接已复制到粘贴板!
有来自一个 JAXWS WSDL-first 开发者的 in-band 和 out-of-band on-the-wire 标头。
in-band 标头是标头,作为端点(如 SOAP 标头)的 WSDL 绑定合同的一部分。
带外 标头是通过线线序列化的标头,但不明确成为 WSDL 绑定合同的一部分。
标头中继/过滤是双向的。
当路由具有 CXF 端点并且开发人员需要有在线标头(如 SOAP 标头)时,将在另一个 JAXWS 端点消耗的路由中转发,然后 relayHeaders 应该被设置为 true,这是默认值。
29.5.6. 仅在 POJO 模式中提供 复制链接链接已复制到粘贴板!
relayHeaders=true 表示转发标头的意图。是否将给定标头中继的实际决定被委派给实现 MessageHeadersRelay 接口的可插拔实例。将查询 MessageHeadersRelay 的 concrete 实现,以决定是否需要转发标头。已有一个 SoapMessageHeadersRelay 的一个实现,它将自身绑定到已知的 SOAP 命名空间。目前只有带外标头会被过滤,当 relayHeaders=true 时,带外标头总是会被转发。如果线上有一个标头,即命名空间在运行时未知,则使用 fall back DefaultMessageHeadersRelay,它只是允许转发所有标头。
relayHeaders=false 设置指定所有带外和带外的标头都应丢弃。
您可以对自己的 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"/>
查看显示您如何转发/过滤标头的测试:
-
支持
POJO和PAYLOAD模式。在POJO模式中,只有带外的消息标头可用于过滤,因为 CXF 从标头列表中删除。in-band 标头被合并到 POJO 模式的MessageContentList中。camel-cxf组件会尝试从MessageContentList中删除带外标头。如果需要过滤 in-band 标头,请使用PAYLOAD模式 或插入(pretty directly) CXF 拦截器/ JAXWS Handler 到 CXF 端点。 -
Message Header Relay 机制已合并到
CxfHeaderFilterStrategy中。relayHeaders选项、其语义和默认值保持不变,但它是CxfHeaderFilterStrategy的属性。以下是配置它的示例:
@Bean
public HeaderFilterStrategy dropAllMessageHeadersStrategy() {
CxfHeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
headerFilterStrategy.setRelayHeaders(false);
return headerFilterStrategy;
}
然后,您的端点可以引用 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;
}
然后按如下方式配置路由:
rom("cxf:bean:routerNoRelayEndpoint")
.to("cxf:bean:serviceNoRelayEndpoint");
-
MessageHeadersRelay接口稍有变化,并重命名为MessageHeaderFilter。它是CxfHeaderFilterStrategy的属性。以下是配置用户定义的 Message Header Filters 的示例:
@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;
}
-
除了
relayHeaders外,也可以在CxfHeaderFilterStrategy中配置以下属性。
| Name | 必填 | 描述 |
|---|---|---|
|
| 否 |
所有消息标头都由 Message Header Filters Type: |
|
| 否 |
所有消息标头都会被传播(不包括消息过滤器处理) 类型: |
|
| 否 |
如果激活命名空间中的两个过滤器重叠,则属性控制应如何处理它。如果值为 |