12.4. Undertow ランタイムの設定
概要
Undertow ランタイムは、分離されたエンドポイントを使用する HTTP サービスプロバイダーと HTTP コンシューマーによって使用されます。ランタイムのスレッドプールを設定できます。また、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>Namespace
Undertow ランタイムの設定に使用される要素は、名前空間 http://cxf.apache.org/transports/http-undertow/configuration で定義されています。Undertow 設定要素を使用するには、例12.14「Undertow ランタイム設定名前空間」 にある行をエンドポイント設定ファイルの beans 要素に追加する必要があります。この例では、名前空間に接頭辞 httpu が割り当てられています。また、設定要素の namespace を 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 ランタイムの設定に使用されるルート要素です。この属性には単一の必須属性 bus があり、その値は、設定されている Undertow インスタンスを管理する Bus の名前です。
値は通常、デフォルトの Bus インスタンスの名前である cxf です。
http:engine-factory 要素には、Undertow ランタイムファクトリーによってインスタンス化された HTTP ポートの設定に使用される情報が含まれる 3 つの子があります。子は、表12.7「Undertow ランタイムファクトリーを設定するための要素」 で説明されています。
表12.7 Undertow ランタイムファクトリーを設定するための要素
| 要素 | 説明 |
|---|---|
|
| 特定の Undertow ランタイムインスタンスの設定を指定します。「engine 要素」を参照してください。 |
|
HTTP サービスプロバイダーを保護するための再利用可能なプロパティーのセットを指定します。これには、プロパティーセットを参照できる一意の識別子を指定する単一の属性 | |
|
Undertow インスタンスのスレッドプールを制御するための再利用可能なプロパティーセットを指定します。これには、プロパティーセットを参照できる一意の識別子を指定する単一の属性 「スレッドプールの設定」を参照してください。 |
engine 要素
httpu:engine 要素は、Undertow ランタイムの特定のインスタンスを設定するために使用されます。これには、Undertow インスタンスによって管理される port の数を指定する、組み込み undertow とポートを持つグローバル IP アドレスを指定する host の 2 つの属性があります。
port 属性に 0 の値を指定することができます。port 属性が 0 に設定された httpu:engine 要素に指定されたスレッドプロパティーは、明示的に設定されていないすべての Undertow リスナーの設定として使用されます。
各 httpu:engine 要素には、セキュリティープロパティーを設定する子と Undertow インスタンスのスレッドプールを設定する子の 2 つの子があります。設定の各タイプに対して、設定情報を直接提供するか、親 httpu:engine-factory 要素で定義された設定プロパティーのセットへの参照を指定することもできます。
設定プロパティーの提供に使用される子要素は 表12.8「Undertow ランタイムインスタンスを設定するための要素」 で説明されています。
表12.8 Undertow ランタイムインスタンスを設定するための要素
| 要素 | 説明 |
|---|---|
| 特定の Undertow インスタンスに使用されるセキュリティーを設定するためのプロパティーのセットを指定します。 | |
|
| |
| 特定の Undertow インスタンスによって使用されるスレッドプールのサイズを指定します。「スレッドプールの設定」を参照してください。 | |
|
|
スレッドプールの設定
Undertow インスタンスのスレッドプールのサイズは、以下のいずれかによって設定できます。
-
engine-factory要素のidentifiedThreadingParameters要素を使用して、スレッドプールのサイズを指定します。次に、tthreadingParametersRef要素を使用して要素を参照します。 -
threadingParameters要素を使用して、スレッドプールのサイズを直接指定します。
threadingParameters には、スレッドプールのサイズを指定する属性が 2 つあります。属性については、表12.9「Undertow スレッドプールを設定するための属性」 で説明されています。
httpu:identifiedThreadingParameters 要素には、単一の子 threadingParameters 要素があります。
例
例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>同時要求およびキューサイズの制限
Request Limiting Handler を設定して、同時接続リクエストの最大数と、Undertow サーバーインスタンスによって処理できるキューサイズに制限を設定できます。この設定の例を以下に示します。例12.16「接続要求およびキューサイズの制限」
表12.10 Request Limiting ハンドラーを設定するための属性
例12.16 接続要求およびキューサイズの制限
<httpu:engine-factory>
<httpu:engine port="8282">
<httpu:handlers>
<bean class="org.jboss.fuse.quickstarts.cxf.soap.CxfRequestLimitingHandler">
<property name="maximumConcurrentRequests" value="1" />
<property name="queueSize" value="1"/>
</bean>
</httpu:handlers>
</httpu:engine>
</httpu:engine-factory>