O'Reilly logo

Enterprise JavaBeans 3.1, 6th Edition by Bill Burke, Andrew Lee Rubinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix I. Interceptors: TV Channel Service Example

Description

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 requests. The @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.

Source Listing

Following is a full listing of all source ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required