2.24. CXF


Apache CXF を使用して SOAP WebServices を公開するか、CXF WS クライアントを使用して外部 WebServices に接続します。

2.24.1. 含まれるもの

使用方法と設定の詳細は、上記リンクを参照してください。

2.24.2. Maven コーディネート

code.quarkus.redhat.com でこのエクステンションを使用して新しいプロジェクトの作成

または、既存のプロジェクトに座標を追加します。

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-cxf-soap</artifactId>
</dependency>
Copy to Clipboard Toggle word wrap

2.24.3. 使用方法

2.24.3.1. 全般

camel-quarkus-cxf-soap は、CXF Extensions for Quarkus プロジェクト (quarkus-cxf) のエクステンションを使用します。

これは、サポートされるユースケースと WS 仕様のセットの大部分が quarkus-cxf によって提供されることを意味します。

重要

サポート対象のユースケースおよび WS 仕様の詳細は、Quarkus CXF の Reference を参照してください。

2.24.3.2. 依存関係の管理

Red Hat build of Apache Camel for Quarkus は、CXF および quarkus-cxf のバージョンを 管理 します。これらのプロジェクトと互換性があるバージョンを選択する必要はありません。

2.24.3.3. クライアント

camel-quarkus-cxf-soap (追加の依存関係は不要) を使用すると、CXF クライアントを Camel ルートでプロデューサーとして使用できます。

import org.apache.camel.builder.RouteBuilder;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;

@ApplicationScoped
public class CxfSoapClientRoutes extends RouteBuilder {

    @Override
    public void configure() {

        /* You can either configure the client inline */
        from("direct:cxfUriParamsClient")
                .to("cxf://http://localhost:8082/calculator-ws?wsdlURL=wsdl/CalculatorService.wsdl&dataFormat=POJO&serviceClass=org.foo.CalculatorService");

        /* Or you can use a named bean produced below by beanClient() method */
        from("direct:cxfBeanClient")
                .to("cxf:bean:beanClient?dataFormat=POJO");

    }

    @Produces
    @SessionScoped
    @Named
    CxfEndpoint beanClient() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(CalculatorService.class);
        result.setAddress("http://localhost:8082/calculator-ws");
        result.setWsdlURL("wsdl/CalculatorService.wsdl"); // a resource in the class path
        return result;
    }
}
Copy to Clipboard Toggle word wrap

CalculatorService は以下のようになります。

import jakarta.jws.WebMethod;
import jakarta.jws.WebService;

@WebService(targetNamespace = CalculatorService.TARGET_NS) 
1

public interface CalculatorService {

    public static final String TARGET_NS = "http://acme.org/wscalculator/Calculator";

    @WebMethod 
2

    public int add(int intA, int intB);

    @WebMethod 
3

    public int subtract(int intA, int intB);

    @WebMethod 
4

    public int divide(int intA, int intB);

    @WebMethod 
5

    public int multiply(int intA, int intB);
}
Copy to Clipboard Toggle word wrap
1 2 3 4 5
注記: JAX-WS アノテーションが必要です。Simple CXF フロントエンドはサポートされていません。ネイティブモードで適切に機能させるには、複雑なパラメータータイプに JAXB アノテーションが必要です。
ヒント

このサービスエンドポイントインターフェイスを実装する quay.io/l2x6/calculator-ws:1.2 コンテナーに対して、このクライアントアプリケーションをテストできます。

$ docker run -p 8082:8080 quay.io/l2x6/calculator-ws:1.2
Copy to Clipboard Toggle word wrap
注記

quarkus-cxf は、@io.quarkiverse.cxf.annotation.CXFClient アノテーションを使用する SOAP クライアントの注入 をサポートします。詳細は、quarkus-cxf ユーザーガイドの SOAP Clients の章を参照してください。

2.24.3.4. サーバー

camel-quarkus-cxf-soap を使用すると、SOAP エンドポイントを Camel ルートのコンシューマーとして公開できます。このユースケースには、追加の依存関係は必要ありません。

import org.apache.camel.builder.RouteBuilder;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;

@ApplicationScoped
public class CxfSoapRoutes extends RouteBuilder {

    @Override
    public void configure() {
        /* A CXF Service configured through a CDI bean */
        from("cxf:bean:helloBeanEndpoint")
                .setBody().simple("Hello ${body} from CXF service");

        /* A CXF Service configured through Camel URI parameters */
        from("cxf:///hello-inline?wsdlURL=wsdl/HelloService.wsdl&serviceClass=org.foo.HelloService")
                        .setBody().simple("Hello ${body} from CXF service");
    }

    @Produces
    @ApplicationScoped
    @Named
    CxfEndpoint helloBeanEndpoint() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(HelloService.class);
        result.setAddress("/hello-bean");
        result.setWsdlURL("wsdl/HelloService.wsdl");
        return result;
    }
}
Copy to Clipboard Toggle word wrap

これら 2 つのサービスが提供されるパスは、たとえば application.properties で設定できる quarkus.cxf.path 設定プロパティー の値によって異なります。

application.properties

quarkus.cxf.path = /soap-services
Copy to Clipboard Toggle word wrap

この設定を適用すると、http://localhost:8080/soap-services/hello-bean および http://localhost:8080/soap-services/hello-inline で、2 つのサービスにそれぞれアクセスできます。

WSDL には、上記の URL に ?wsdl を追加することでアクセスできます。

重要

他のエクステンションが HTTP エンドポイントを公開しないと 100% 確信できない限り、アプリケーションで quarkus.cxf.path = / を使用しないでください。

quarkus-cxf 2.0.0 より前 (つまり、Red Hat build of Apache Camel for Quarkus 3.0.0 より前)、quarkus.cxf.path のデフォルト値は / でした。このデフォルト値は、他の Quarkus エクステンションがさらなる HTTP エンドポイントの公開を阻止していたため、変更されました。とりわけ、RESTEasy、Vert.x、SmallRye Health ( health エンドポイントは公開されていません) がこの影響を受けていました。

注記

quarkus-cxf は、SOAP エンドポイントを公開する代替方法をサポートします。詳細は、quarkus-cxf ユーザーガイドの SOAP Services の章を参照してください。

2.24.3.5. 要求および応答のロギング

org.apache.cxf.ext.logging.LoggingFeature を使用して、クライアントとサーバーの両方の SOAP メッセージの詳細ロギングを有効にできます。

import org.apache.camel.builder.RouteBuilder;
import org.apache.cxf.ext.logging.LoggingFeature;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;

@ApplicationScoped
public class MyBeans {

    @Produces
    @ApplicationScoped
    @Named("prettyLoggingFeature")
    public LoggingFeature prettyLoggingFeature() {
        final LoggingFeature result = new LoggingFeature();
        result.setPrettyLogging(true);
        return result;
    }

    @Inject
    @Named("prettyLoggingFeature")
    LoggingFeature prettyLoggingFeature;

    @Produces
    @SessionScoped
    @Named
    CxfEndpoint cxfBeanClient() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(CalculatorService.class);
        result.setAddress("https://acme.org/calculator");
        result.setWsdlURL("wsdl/CalculatorService.wsdl");
        result.getFeatures().add(prettyLoggingFeature);
        return result;
    }

    @Produces
    @ApplicationScoped
    @Named
    CxfEndpoint helloBeanEndpoint() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(HelloService.class);
        result.setAddress("/hello-bean");
        result.setWsdlURL("wsdl/HelloService.wsdl");
        result.getFeatures().add(prettyLoggingFeature);
        return result;
    }
}
Copy to Clipboard Toggle word wrap
注記

org.apache.cxf.ext.logging.LoggingFeature のサポートは、camel-quarkus-cxf-soap 依存関係として io.quarkiverse.cxf:quarkus-cxf-rt-features-logging によって提供されます。アプリケーションに明示的に追加する必要はありません。

2.24.3.6. WS 仕様

サポートされる WS 仕様の範囲は、Quarkus CXF プロジェクトによって提供されます。

camel-quarkus-cxf-soap は、io.quarkiverse.cxf:quarkus-cxf エクステンションを介して、以下の仕様のみをカバーします。

  • JAX-WS
  • JAXB
  • WS-Addressing
  • WS-Policy
  • MTOM

アプリケーションが WS-Security や WS-Trust などの他の WS 仕様を必要とする場合は、それをカバーする Quarkus CXF 依存関係を追加する必要があります。どの WS 仕様がどの Quarkus CXF エクステンションでカバーされているかを確認するには、Quarkus CXF の Reference ページを参照してください。

ヒント

Red Hat build of Apache Camel for Quarkus および Quarkus CXF には、さまざまな WS 仕様を実装したアプリケーションの実行可能なサンプルとして役立つ インテグレーション テスト が多数含まれています。

2.24.3.7. ツール

quarkus-cxf は、以下の 2 つの CXF ツールをラップします。

重要

wsdl2Java が適切に機能するためには、アプリケーションは io.quarkiverse.cxf:quarkus-cxf に直接依存する必要があります。

ヒント

wsdlvalidator はサポート対象外ですが、application.properties で以下の設定を指定し、wsdl2Java を使用して WSDL を検証できます。

application.properties

quarkus.cxf.codegen.wsdl2java.additional-params = -validate
Copy to Clipboard Toggle word wrap

トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat