Defining and using interceptors

In this recipe, we will examine the process of creating and using a simple interceptor. An interceptor method will be invoked before a target method is executed. When the target method returns, additional code within the interceptor can be executed. This approach is useful for performing orthogonal tasks and for manipulating the parameters sent to a method and/or returned from a method.

Getting ready

There are two major steps in the creation and use of an interceptor:

  1. Creating a class containing an @AroundInvoke annotated method
  2. Specifying the target method using the @Interceptors annotation

    To use an interceptor, we must first create it and then specify where it will be used. The @AroundInvoke annotation designates ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.