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
method invocation proceeds only if the interceptor method returns InvocationContext.proceed()
.
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.
You can specify this method on the EJB 3.0 message-driven bean class (see "Using Annotations") or on an interceptor class that you associate with an EJB 3.0 message-driven bean (see "Configuring an Around Invoke Interceptor Method on an Interceptor Class of an EJB 3.0 MDB").
For more information, see "Understanding EJB 3.0 Interceptors".
Example 10-11 shows how to designate a method of a message-driven bean class as an interceptor method using the @AroundInvoke
annotation. 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-11 @AroundInvoke in an EJB 3.0 Message-Driven Bean
@MessageDriven public class MessageLogger implements MessageListene { @Resource javax.ejb.MessageDrivenContext mc; public void onMessage(Message message) { .... } @AroundInvoke public Object myInterceptor(InvocationContext ctx) throws Exception { if (!userIsValid(ctx. getEJBContext().getCallerPrincipal())) { throw new SecurityException( "Caller: '" + ctx.getEJBContext().getCallerPrincipal().getName() + "' does not have permissions for method " + ctx.getMethod() ); } return ctx.proceed(); } }