The interceptor design pattern allows logic to be "inserted" before, during or after the execution of a piece of code, such as a method.
Interceptors are used to implement cross-cutting concerns, such as logging, auditing, and security, from the business logic.
As the name suggests, when messages are being passed , say- from one object to another, interceptors are used to catch that message and do some operations on it before it reaches the destination object.
In Java EE 5, Interceptors were allowed only on EJBs. In Java EE 6, Interceptors became a new specification of its own, abstracted at a higher level so that it can be more generically applied to a broader set of specifications in the platform.
They intercept invocations and life-cycle events on an associated target class. Basically, an interceptor is a class whose methods are invoked when business methods on a target class are invoked, life-cycle events such as methods that create/destroy the bean occur, or an EJB timeout method occurs. The CDI specification defines a type-safe mechanism for associating interceptors to beans using interceptor bindings.
Look for a working code sample at:
https://github.com/arun-gupta/javaee7-samples/tree/master/cdi/interceptors
Java EE 7 also introduced a new @Transactional annotation in Java Transaction API. This allows you to have container-managed transactions outside an EJB. This annotation is defined as an interceptor binding and implemented by the Java EE runtime. A working sample of @Transactional is at:
https://github.com/arun-gupta/javaee7-samples/tree/master/jta/transaction-scope