Red Hat Training
A Red Hat training course is available for Red Hat Fuse
12.4. 配置 Undertow 运行时
概述
HTTP 服务供应商和 HTTP 使用者使用 Undertow 运行时,利用分离的端点。可以配置运行时的线程池,您也可以通过 Undertow 运行时为 HTTP 服务提供商设置许多安全设置。
Maven 依赖项
如果您将 Apache Maven 用作构建系统,您可以通过在项目的 pom.xml 文件中包括以下依赖项,将 Undertow 运行时添加到您的项目中:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-undertow</artifactId>
<version>${cxf-version}</version>
</dependency>命名空间
用于配置 Undertow 运行时的元素在命名空间 http://cxf.apache.org/transports/http-undertow/configuration 中定义。若要使用 Undertow 配置元素,您必须将 例 12.14 “Undertow 运行时配置命名空间” 中显示的行添加到端点配置文件的 Bean 元素中。在本例中,为命名空间分配 httpu 前缀。另外,您必须将配置元素的命名空间添加到 xsi:schemaLocation 属性中。
例 12.14. Undertow 运行时配置命名空间
<beans ...
xmlns:httpu="http://cxf.apache.org/transports/http-undertow/configuration"
...
xsi:schemaLocation="...
http://cxf.apache.org/transports/http-undertow/configuration
http://cxf.apache.org/schemas/configuration/http-undertow.xsd
...">engine-factory 元素
httpu:engine-factory 元素是用于配置应用使用的 Undertow 运行时的根元素。它具有单个必需属性 总线,其值是管理所配置的 Undertow 实例的 总线 名称。
该值通常是 cxf,这是默认 总线实例的名称。
http:engine-factory 元素有三个子项,其中包含用于配置由 Undertow 运行时工厂实例化的 HTTP 端口的信息。子项包括在 表 12.7 “配置 Undertow 运行时工厂元素” 中。
表 12.7. 配置 Undertow 运行时工厂元素
| element | 描述 |
|---|---|
|
| 指定特定 Undertow 运行时实例的配置。请参阅 “engine 元素”一节。 |
|
指定用于保护 HTTP 服务提供商的可重用属性集。它有一个属性 | |
|
指定用于控制 Undertow 实例的线程池的一组可重复使用的属性。它有一个属性 请参阅 “配置线程池”一节。 |
engine 元素
httpu:engine 元素用于配置 Undertow 运行时的特定实例。它有一个属性 port,用于指定由 Undertow 实例管理的端口数量。
您可以为 port 属性指定 0 值。httpu:engine 元素中指定的任何线程属性(其 port 属性设置为 0)都用作未明确配置的 Undertow 侦听器的配置。
每个 httpu:engine 元素都可以具有两个子项:一个用于配置安全属性,另一个用于配置 Undertow 实例的线程池。对于每种配置,您可以直接提供配置信息,也可以提供对父 httpu:engine-factory 元素中定义的一组配置属性的引用。
表 12.8 “配置 Undertow 运行时实例的元素” 描述用于提供配置属性的子元素。
表 12.8. 配置 Undertow 运行时实例的元素
| element | 描述 |
|---|---|
| 指定一组属性,以配置用于特定 Undertow 实例的安全性。 | |
|
指的是由 | |
| 指定特定 Undertow 实例使用的线程池的大小。请参阅 “配置线程池”一节。 | |
|
是指由 |
配置线程池
您可以通过以下任一方式配置 Undertow 实例的线程池的大小:
-
使用
engine-factory元素中的identifiedThreadingParameters元素指定线程池的大小。然后,您可以使用threadingParametersRef元素来引用这个元素。 -
使用
threadingParameters元素直接指定线程池的大小。
threadingParameters 有两个属性来指定线程池的大小。属性在 表 12.9 “配置 Undertow 线程池的属性” 中描述。
httpu:identifiedThreadingParameters 元素具有单个子 线程Parameters 元素。
示例
例 12.15 “配置 Undertow 实例” 显示配置片段,用于在端口号 9001 上配置 Undertow 实例。
例 12.15. 配置 Undertow 实例
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:httpu="http://cxf.apache.org/transports/http-undertow/configuration"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xsi:schemaLocation="http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/transports/http-undertow/configuration
http://cxf.apache.org/schemas/configuration/http-undertow.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
...
<httpu:engine-factory bus="cxf">
<httpu:identifiedTLSServerParameters id="secure">
<sec:keyManagers keyPassword="password">
<sec:keyStore type="JKS" password="password"
file="certs/cherry.jks"/>
</sec:keyManagers>
</httpu:identifiedTLSServerParameters>
<httpu:engine port="9001">
<httpu:tlsServerParametersRef id="secure" />
<httpu:threadingParameters minThreads="5"
maxThreads="15" />
</httpu:engine>
</httpu:engine-factory>
</beans>