Forums Register Login

how many interceptor method in a Bean class ?

+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
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)?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 :
+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
 

anyways what should I answer for the exam ?


Only one method allowed in the same class.
+Pie Number of slices to send: Send
Thanks Christophe.
And inside of my fortune cookie was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2165 times.
Similar Threads
EJB3 mock questions available now! (Section 2)
EJB Spec violationg for session bean rules.
whats wrong with this client ?
Doubts regarding javabeat questions
Interceptor and Exceptions
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:56:16.