Enterprise Java Development@TOPIC@

Chapter 119. CDI Interceptors

119.1. @InterceptorBinding Annotation
119.2. Interceptor Class
119.3. CDI Bean Class
119.4. CDI Descriptor (beans.xml) Activation
119.5. Summary

Annotation to identify type of interceptor required (e.g., @Transactional)

package info.ejava.examples.ejb.interceptor.interceptors;


import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.interceptor.InterceptorBinding;
@Inherited
@InterceptorBinding
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Validation {
}

The above @InterceptorBinding annotation will be used to designate the type of interceptor required/offered by/to a bean

import javax.interceptor.Interceptor;


@Validation
@Interceptor
public class ContactsNormalizerInterceptor {
    @AroundInvoke
    public Object invoke(InvocationContext ctx) throws Exception {
@Stateless

@Validation
public class ContactsEJB implements ContactsRemote {
    @Override
    public Contact createContact(Contact contact) throws InvalidParam {

<?xml version="1.0" encoding="UTF-8"?>
<beans ...
     
     <interceptors>
        <class>info.ejava.examples.ejb.interceptor.interceptors.PreNormizedInterceptor</class>
        <class>info.ejava.examples.ejb.interceptor.interceptors.ContactsNormalizerInterceptor</class>
        <class>info.ejava.examples.ejb.interceptor.interceptors.PostNormizedInterceptor</class>
     </interceptors>
</beans>