| Author |
how many interceptor method in a Bean class ?
|
Sanju Thomas
Ranch Hand
Joined: Dec 29, 2004
Posts: 243
|
|
Section 12.3 of the EJB core specs says that we can have only one @AroundInvoket method in a class.
AroundInvoke methods may be defined on superclasses of the bean class or interceptor classes.
However, only one AroundInvoke method may be present on a given class. An AroundInvoke
method cannot be a business method of the bean.
But I could write two AroundInvoke methods in the Bean class, and JBoss 5.0 did not complain anything about it!.
Code is gien below.
Remote interface
Bean Class
Client code
JBoss console output
------------------------
13:01:16,381 INFO [STDOUT] interceptorMethod is called
13:01:16,381 INFO [STDOUT] interceptorMethodOne is called
13:01:16,381 INFO [STDOUT] Business Method
13:01:16,427 INFO [STDOUT] interceptorMethod is called
13:01:16,427 INFO [STDOUT] interceptorMethodOne is called
13:01:16,427 INFO [STDOUT] Business method one
Whats happening here ?? Am I doing something wrong ? or JBoss is not following spec ? Both interceptor methods are permitted and both are getting executed. Please help.
|
 |
Deepika Joshi
Ranch Hand
Joined: Feb 24, 2009
Posts: 268
|
|
Consider the following code from EJB 3 In Action
When you use @Interceptors you mention class name (e.g. ActionBazaarLogger.class) (and not method name),
If you have more than one @AroundInvoke in a class then how would you use them (or either of them)?
|
 |
Omar Al Kababji
Ranch Hand
Joined: Jan 13, 2009
Posts: 357
|
|
|
Well the specifications provided by SUN says that you must have only one method in an interceptor taged with the @AroundInvoke annotation, however it seems that JBoss didn't follow this specification. many times Applicatin Servers modifiy a bit some of the specifications.
|
Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
The spec says "However, only one AroundInvoke method may be present on a given class. ", not "must be", which also means : "You're responsible for your mistakes"
Here is what Glassfish gave me :
You can see that only one interceptor method is called. I also tried to put the interceptor method in a separate class :
This time, it gave me :
|
[My Blog]
All roads lead to JavaRanch
|
 |
Sanju Thomas
Ranch Hand
Joined: Dec 29, 2004
Posts: 243
|
|
Test result from Glasfish is also strange. When we had @AroundInvoke interceptor methods inside the bean the "interceptorMethodOne" got invoked, when we moved to a seperate interceptor class the "interceptorMethod" got invoked.
anyways what should I answer for the exam ?
According to spec we can have only one @AroundInvoke method in a class. Whether its in bean class or in sperate interceptor class. is that correct ?
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
anyways what should I answer for the exam ?
Only one method allowed in the same class.
|
 |
Sanju Thomas
Ranch Hand
Joined: Dec 29, 2004
Posts: 243
|
|
|
Thanks Christophe.
|
 |
 |
|
|
subject: how many interceptor method in a Bean class ?
|
|
|