17.5. Spring で CXF エンドポイントを設定する
以下に示す Spring 設定ファイルを使用して CXF エンドポイントを設定できます。また、エンドポイントを camelContext タグに埋め込むこともできます。サービスエンドポイントを呼び出すときに、operationName ヘッダーと operationNamespace ヘッダーを設定して、呼び出す操作を明示的に指定できます。
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/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>
ルート Bean 要素で指定された JAX-WS schemaLocation 属性を必ず含めてください。これにより、CXF はファイルを検証できるようになります。これは必須です。<cxf:cxfEndpoint/> タグの末尾にある名前空間の宣言にも注意してください。結合された {namespace}localName 構文は現在、このタグの属性値に対してサポートされていないため、これらの宣言が必要です。
cxf:cxfEndpoint 要素は、多くの追加属性をサポートしています。
| Name | 値 |
|---|---|
|
|
このサービスが実装しているエンドポイント名で、 |
|
|
このサービスが実装しているサービス名で、 |
|
| WSDL の場所。クラスパス、ファイルシステム、またはリモートでホストできます。 |
|
|
使用するサービスモデルの |
|
| サービス公開アドレス。 |
|
| JAX-WS エンドポイントで使用されるバス名。 |
|
| JSR181 アノテーションを持つかどうかにかかわらず、SEI (Service Endpoint Interface) クラスのクラス名。 |
また、多くの子要素もサポートしています。
| Name | 値 |
|---|---|
|
|
このエンドポイントの着信インターセプター。 |
|
|
このエンドポイントの着信障害インターセプター。 |
|
|
このエンドポイントの発信インターセプター。 |
|
|
このエンドポイントの送信障害インターセプター。 |
|
| JAX-WS エンドポイントに提供する必要があるプロパティーマップ。以下を参照してください。 |
|
| JAX-WS エンドポイントに提供する必要がある JAX-WS ハンドラーリスト。以下を参照してください。 |
|
|
エンドポイントで使用する |
|
|
このエンドポイントが使用する |
|
| このエンドポイントのインターセプターを保持する機能。Bean または参照のリスト |
|
| エンドポイントが使用するスキーマの場所。schemaLocations のリスト |
|
|
このエンドポイントが使用するサービスファクトリー。これは、Spring |
CXF JAX-WS 設定ページ で、インターセプター、プロパティー、およびハンドラーを提供する方法を示すより高度な例を見つけることができます。
cxf:properties を使用して、Spring 設定ファイルから camel-cxf エンドポイントの dataFormat および setDefaultBus プロパティーを設定できます。
<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"
})
ただし、SpringBoot では、(他の例で示されているように) Java コードで設定された Bean を使用するのがベストプラクティスです。