Skip to Main Content
Enterprise JavaBeans 3.1, 6th Edition
book

Enterprise JavaBeans 3.1, 6th Edition

by Andrew Lee Rubinger, Bill Burke
September 2010
Intermediate to advanced content levelIntermediate to advanced
766 pages
18h 35m
English
O'Reilly Media, Inc.
Content preview from Enterprise JavaBeans 3.1, 6th Edition

Intercepting Lifecycle Events

Not only can you intercept EJB method invocations, but you can also intercept EJB lifecycle events. These callbacks can be used to initialize the state of your EJB bean classes, as well as the interceptor class itself. Lifecycle interception looks very similar to the @AroundInvoke style:

@callback-annotation> voidmethod-name(InvocationContext
 ctx);

To intercept an EJB callback, define a method within your interceptor class that is annotated with the callback in which you are interested. The return value of the method must be void because EJB callbacks have no return value. The method name can be anything and must not throw any checked exceptions (no throws clause). InvocationContext is the only parameter to this method. As with @AroundInvoke methods, callback interception is invoked in one big Java call stack. This means you must call InvocationContext.proceed() to complete the lifecycle event. When calling proceed(), the next interceptor class that has the same callback is invoked. If there are no other interceptors, then the callback method of the EJB’s bean class is invoked, if one exists. If the EJB has no callback method, then proceed() is a no-op. Because there may be no callback method, InvocationContext.getMethod() always returns null.

Custom Injection Annotations

Why would you want to intercept an EJB callback? One concrete example is when you want to create and define your own injection annotations. The EJB specification has a bunch of annotations ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
JavaServer Faces

JavaServer Faces

Hans Bergsten
EJB 3 Developer Guide

EJB 3 Developer Guide

Michael Sikora

Publisher Resources

ISBN: 9781449399139Errata Page