Java Reference
In-Depth Information
Finally, if more than one method‐level interceptor is present, again, the interceptors follow the order
they are listed in the @Interceptors annotation:
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class SomeBusinessService {
@Interceptors(SecurityInterceptor.class, AnotherInterceptor.class )
public void startService(){
// ...
If you need to tweak the default ordering, you can do so by custom coni guration within the EJB‐
JAR XML. The following overrides the interceptor order and provides a custom ordering:
<ejb-jar...>
<interceptors>
<interceptor>
<interceptor-class>
com.devchronicles.SecurityInterceptor
</interceptor-class>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb-name>OrderBean</ejb-name>
<interceptor-order>
<interceptor-class>
com.devchronicles.SecurityInterceptor
</interceptor-class>
</interceptor-order>
<interceptor-class>
com.devchronicles.AnotherInterceptor
</interceptor-class>
<method>
<method‐name>startService</method‐name>
</method>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
There might be exceptional cases in which the interceptors need to be disabled. You can disable
interceptors with annotations as seen in Listing 8‐9. Java EE offers two different annotations to
disable default and class‐level interceptors separately.
LISTING 8‐9: Disabling the interceptors
package com.devchronicles.interceptor;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.enterprise.event.Event;
import javax.inject.Inject;
Search WWH ::




Custom Search