Enterprise Java Development@TOPIC@
Extends Java Interceptors specified in EJB Spec
Not specific to EJBs -- any POJO
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
Same implementation as EJB Interceptor
Annotated with @javax.interceptor.Interceptor
Annotated with @InterceptorBinding annotation
Not activate by default
import javax.interceptor.Interceptor;
@Validation
@Interceptor
public class ContactsNormalizerInterceptor {
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
Can be an EJB
Annotated with @InterceptorBinding annotation
@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>
Activates Interceptor classes
Controls order applied