Using an interceptor for logging and exception handling

Interceptors are good for removing extraneous code from a method. In the format method developed in the Using logging within an EJB recipe, most of the code was concerned with handling exceptions. This recipe shows how an interceptor can be used to greatly simplify the format method.

Getting ready

The general process of using an interceptor for logging includes:

  1. Accessing the parameters of the target method
  2. Using the validation methods to validate the parameters
  3. Catching and logging any thrown exceptions

    We will also need to modify the target class to accommodate the use of an interceptor.

    The process of creating and using an interceptor class is detailed in Chapter 8, Interceptors. Here, we will ...

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.