Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
You can specify one nonbusiness method as the interceptor method for an EJB 3.0 message-driven bean. Each time the onMessage
method is invoked, OC4J intercepts the invocation and invokes the interceptor method. The onMessage
invocation proceeds only if the interceptor method returns InvocationContext.proceed()
.
You can specify this method on an interceptor class that you associate with an EJB 3.0 MDB or on the EJB 3.0 MDB class itself (see "Configuring an Around Invoke Interceptor Method on an EJB 3.0 MDB").
To configure an interceptor method on an interceptor class, you must do the following:
Create an interceptor class.
This can be any POJO class.
Implement the interceptor method.
An interceptor method has the following signature:
Object <METHOD>(InvocationContext) throws Exception
An interceptor method may have public, private, protected, or package level access, but must not be declared as final or static.
Designate the method as the interceptor method (see "Using Annotations").
Associate the interceptor class with your EJB 3.0 MDB (see "Configuring an Interceptor Class for an EJB 3.0 MDB").
For more information, see "Understanding EJB 3.0 Interceptors".
Example 10-12 shows how to specify interceptor class method myInterceptor
as the interceptor method of an EJB 3.0 MDB using the @AroundInvoke
annotation. After you associate this interceptor class with an MDB ("Configuring an Interceptor Class for an EJB 3.0 MDB"), each time the onMessage
method is invoked, OC4J intercepts the invocation and invokes the interceptor method myInterceptor
. The onMessage
method invocation proceeds only if the interceptor method returns InvocationContext.proceed()
.
Example 10-12 Interceptor Class
public class MyInterceptor { ... @AroundInvoke protected Object myInterceptor(InvocationContext ctx) throws Exception { Principal p = ctx.getEJBContext().getCallerPrincipal; if (!userIsValid(p)) { throw new SecurityException( "Caller: '" + p.getName() + "' does not have permissions for method " + ctx.getMethod() ); } return ctx.proceed(); } @PreDestroy public void myPreDestroyMethod (InvocationContext ctx) { ... ctx.proceed(); ... } }