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

概要

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

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

  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 の特定のメソッドレベルでインターセプターをバインドします。

      注記

      これらの要素は、Java EE インターセプターの場合と同様に EJB 3.1 XSD を使用して設定されます。
  3. 上記の要素の例として以下の記述ファイルを参照してください。

    例16.2 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 は https://github.com/jbossas/jboss-as/blob/master/ejb3/src/main/resources/jboss-ejb-container-interceptors_1_0.xsd で入手できます。