O'Reilly logo

Java EE 6 Cookbook for Securing, Tuning, and Extending Enterprise Applications by Mick Knutson

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

Adding advice with CDI Interceptors

Interceptors are similar to Aspects that allow developers to invoke interceptor methods in conjunction with method invocations or lifecycle events on an associated target class.

Interceptors help eliminate code cluttering and allow implementing of cross-cutting concerns. Interceptors are not as powerful as full AspectJ, but they still provide a great solution for these problem spaces.

Getting ready

To begin we need to assume this code will be run in a CDI-compliant container such as GlassFish. Tomcat does not come with native CDI support.

Before we begin implementing our first interceptor, we first want to cover the various elements and how they interact with one another.

Target class

We first start with an object ...

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