As we’ve seen with security and transactions, often we have business logic that is not a part of our core concerns. Quite the opposite; applications are likely to have rules that need to be universal across modules or EJBs, and baking this logic into our implementation mixes concerns and makes for an unmaintainable system over time.
Much like Servlet Filters or AOP aspects, the EJB Interceptor model
provides a mechanism for application developers to apply logic to incoming
@Interceptors annotation quickly acts as a
mapping marker for the EJB container to know to apply a particular
interceptor for a given invocation.
Our example represents a television server which is capable of returning channel streams when a channel number is requested by the client. We apply a custom security policy whereby Channel 2 may be closed by an administrator; if a client requests Channel 2 while access is disallowed, the invocation will return a “Channel2ClosedException”. All of this logic is separated from the core code to return the channel requested, and therefore may be applied to other modules or unplugged from the system without need to alter the existing application in any way.
Wiki article: http://community.jboss.org/docs/DOC-15574
Following is a full listing of all source ...