This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Interceptors - more than 1 @AroundInvoke - Multiple @Interceptors declared for a class/method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Interceptors - more than 1 @AroundInvoke - Multiple @Interceptors declared for a class/method?" Watch "Interceptors - more than 1 @AroundInvoke - Multiple @Interceptors declared for a class/method?" New topic
Author

Interceptors - more than 1 @AroundInvoke - Multiple @Interceptors declared for a class/method?

Anirudh Gupta
Ranch Hand

Joined: Dec 08, 2010
Posts: 43

What happens when there are more than one @AroundInvoke methods present in an Interceptor class?
Which one gets executed first?

What happens on invocation of the proceed() method?

Can there be 2 @Interceptors declared for a class or method?


Regards,
Anirudh
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
In section 6.10 of my (free) electronic book, the following can be found on interceptor ordering:

The following specifies the order in which interceptors are invoked. This applies to all the different interceptor types with the corresponding interceptor methods:
• Business methods interceptors – around-invoke methods.
• Timeout method interceptors – around-timeout methods.
• Lifecycle event interceptors – PostConstruct, PreDestroy, PrePassivate, PostActivate methods.

The order in which interceptors are invoked is as follows:
• Default interceptors. Any default interceptors are invoked first in the order in which they are declared in the ejb- jar.xml deployment descriptor.
• Interceptors defined in @Interceptor annotated interceptor classes listed in an @Interceptors annotation on the target EJB class. Such interceptor methods are invoked in the order they are declared in the @Interceptors annotation. Interceptor methods of superclasses to the interceptor classes are invoked first, starting with the most general superclass and traversing down the inheritance hierarchy.
• Interceptors defined in @Interceptor annotated interceptor classes listed in an @Interceptors annotation on the target method in an EJB. Such interceptor methods are invoked in the order they are declared in the @Interceptors annotation annotating the EJB method to be invoked.
Interceptor methods of superclasses to the method-level interceptor classes are invoked first, starting with the most general superclass and traversing down the inheritance hierarchy.
• Interceptor methods defined in the target EJB class. Such interceptor methods are invoked, starting with those defined in the most general superclass and traversing down the inheritance hierarchy until finally invoking the interceptor methods in the target EJB class itself.

Best regards!


My free books and tutorials: http://www.slideshare.net/krizsan
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

1. You can specify just one @AroundInvoke in a class.

2. This method executes intercepted method and returns the type that method returns. If intercepted method return void - it gives you null.

3. They are executed in the order in which they appear.


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Anirudh Gupta
Ranch Hand

Joined: Dec 08, 2010
Posts: 43

Thank you Lucas and Ivan.
That was helpful.

I even tried it. 2 @AroundInvoke fails at deployment.
However, I have formed this impression that Weblogic 12C and Glassfish 3.1.1 implementation of Interceptors is not complete,
and what is full of errors. Will shortly post the Error Description and Stack Trace here.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Anirudh Gupta wrote:
However, I have formed this impression that Weblogic 12C and Glassfish 3.1.1 implementation of Interceptors is not complete,
and what is full of errors. Will shortly post the Error Description and Stack Trace here.

I recommend also creating a bug-ticket for the relevant product. I do not know about Weblogic, but GlassFish, being open source, has a JIRA bugtracking system here: http://java.net/jira/browse/GLASSFISH
I have had only good experiences from reporting bugs back to the community.
Best wishes!
 
 
subject: Interceptors - more than 1 @AroundInvoke - Multiple @Interceptors declared for a class/method?
 
Similar Threads
Doubt in interceptor methods
can a variable with same name present in more than one scope?
Invocation Order of Interceptors
Inheritance and method overloading
Invocation order of Lifecycle Callback Methods