Java Reference
In-Depth Information
Chapter 23. Using Java EE Interceptors
This chapter discusses how to create interceptor classes and methods that interpose on
method invocations or lifecycle events on a target class.
The following topics are addressed here:
• “ Overview of Interceptors on page 453
• “ Using Interceptors on page 455
• “ The interceptor Example Application ” on page 460
Overview of Interceptors
Interceptors are used in conjunction with Java EE managed classes to allow developers to
invoke interceptor methods on an associated target class , in conjunction with method in-
vocations or lifecycle events. Common uses of interceptors are logging, auditing, and pro-
filing.
The Interceptors 1.1 specification is part of the final release of JSR 318, Enterprise
JavaBeans 3.1, available from http://jcp.org/en/jsr/detail?id=318 .
An interceptor can be defined within a target class as an interceptor method , or in an associ-
ated class called an interceptor class . Interceptor classes contain methods that are invoked
in conjunction with the methods or lifecycle events of the target class.
Interceptor classes and methods are defined using metadata annotations, or in the deploy-
ment descriptor of the application containing the interceptors and target classes.
Note
Applications that use the deployment descriptor to define interceptors
are not portable across Java EE servers.
Interceptor methods within the target class or in an interceptor class are annotated with one
of the metadata annotations defined in Table 23-1 .
Search WWH ::




Custom Search