Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

8.6.3. コンテナーインターセプターの設定

概要

コンテナーインターセプタは、標準の Java EE インターセプタライブラリーを使用します。つまり、3.1 バージョンの ejb-jar デプロイメント記述子の ejb-jar.xml ファイルで許可されているものと同じ XSD 要素を使用します。それらは標準の Java EE インターセプターライブラリーをベースとしているため、コンテナーインターセプターはデプロイメント記述子を使用してのみ設定できます。これは設計によって行われたため、アプリケーションは JBoss 固有のアノテーションやその他のライブラリー依存関係を必要としません。コンテナーインターセプターの詳細については、以下を参照してください。「コンテナーインターセプターについて」

手順8.11 記述子ファイルを作成して、コンテナーインターセプターを設定します

  1. EJB デプロイメントの META-INF ディレクトリーに jboss-ejb3.xml ファイルを作成します。
  2. 記述子ファイルにコンテナーインターセプター要素を設定します。
    1. urn:container-interceptors:1.0 ネームスペースを使用して、コンテナーインターセプター要素の設定を指定します。
    2. <container-interceptors> 要素を使用してコンテナーインターセプターを指定します。
    3. >interceptor-binding> 要素を使用してコンテナーインターセプターを EJB にバインドします。インターセプターは、次のいずれかの方法でバインドできます。
      • ワイルドカード * を使用して、インターセプターをデプロイメントのすべての EJB にバインドします。
      • 特定の EJB 名を使用して、個々の Bean レベルでインターセプターをバインドします。
      • EJB の特定のメソッドレベルでインターセプターをバインドします。
      注記
      これらの要素は、JavaEE インターセプターの場合と同じ方法で EJB3.1XSD を使用して設定されます。
  3. 上記の要素の例については、次の記述子ファイルを確認してください。

    例8.3 jboss-ejb3.xml

    <jboss xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:jee="http://java.sun.com/xml/ns/javaee"
           xmlns:ci ="urn:container-interceptors:1.0">
     
        <jee:assembly-descriptor>
            <ci:container-interceptors>
                <!-- Default interceptor -->
                <jee:interceptor-binding>
                    <ejb-name>*</ejb-name>
                    <interceptor-class>org.jboss.as.test.integration.ejb.container.interceptor.ContainerInterceptorOne</interceptor-class>
                </jee:interceptor-binding>
                <!-- Class level container-interceptor -->
                <jee:interceptor-binding>
                    <ejb-name>AnotherFlowTrackingBean</ejb-name>
                    <interceptor-class>org.jboss.as.test.integration.ejb.container.interceptor.ClassLevelContainerInterceptor</interceptor-class>
                </jee:interceptor-binding>
                <!-- Method specific container-interceptor -->
                <jee:interceptor-binding>
                    <ejb-name>AnotherFlowTrackingBean</ejb-name>
                    <interceptor-class>org.jboss.as.test.integration.ejb.container.interceptor.MethodSpecificContainerInterceptor</interceptor-class>
                    <method>
                        <method-name>echoWithMethodSpecificContainerInterceptor</method-name>
                    </method>
                </jee:interceptor-binding>
                <!-- container interceptors in a specific order -->
                <jee:interceptor-binding>
                    <ejb-name>AnotherFlowTrackingBean</ejb-name>
                    <interceptor-order>
                        <interceptor-class>org.jboss.as.test.integration.ejb.container.interceptor.ClassLevelContainerInterceptor</interceptor-class>
                        <interceptor-class>org.jboss.as.test.integration.ejb.container.interceptor.MethodSpecificContainerInterceptor</interceptor-class>
                        <interceptor-class>org.jboss.as.test.integration.ejb.container.interceptor.ContainerInterceptorOne</interceptor-class>
                    </interceptor-order>
                    <method>
                        <method-name>echoInSpecificOrderOfContainerInterceptors</method-name>
                    </method>
                </jee:interceptor-binding>
            </ci:container-interceptors>
        </jee:assembly-descriptor>
    </jboss>
    
    
    urn:container-interceptors:1.0 名前空間の XSD は、EAP_HOME/docs/schema/jboss-ejb -container-interceptors_1_0.xsd で入手できます。