aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Life-Cycle Event Interceptor Method Skipped Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Life-Cycle Event Interceptor Method Skipped" Watch "Life-Cycle Event Interceptor Method Skipped" New topic
Author

Life-Cycle Event Interceptor Method Skipped

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
In my experiments I have noticed that a @PostConstruct method in my EJB class ceases to be invoked when I define a @PostConstruct method in a default interceptor class in the same web application.
I have studied the EJB 3.1 specifications in detail but haven't found anything that indicates that this is the behaviour I should expect.
On the contrary, I get the feeling that the default interceptor's @PostConstruct method should be invoked first and the @PostConstruct method in the EJB class be invoked later.
I am using GlassFish v3.0.1 for my experiments.
Anyone have any comments or insight on the above?
Thanks in advance!


My free books and tutorials: http://www.slideshare.net/krizsan
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10048
    
163

Ivan Krizsan wrote:

On the contrary, I get the feeling that the default interceptor's @PostConstruct method should be invoked first and the @PostConstruct method in the EJB class be invoked later.


Assuming the bean and interceptor methods are correct, you are right - that's how it's supposed to work. The exact details are in the "Interceptors 1.1 spec" section "Multiple Callback Interceptor Methods for a Life Cycle Callback Event"



[My Blog] [JavaRanch Journal]
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Ivan

The interceptor life-cycle methods are called before the bean one.
Take a look in the specification on the 12.2 Interceptor Life Cycle

Both the interceptor instance and the bean instance are created or activated before any of the respective PostConstruct or PostActivate callbacks are invoked. Any PreDestroy and PrePassivate
callbacks are invoked before the respective destruction or passivation of either the bean instance or interceptor instance.



This is from 3.0 specs, but I bet that in 3.1 is the same.


Regards,
Mihai


SCJP, SCJD, SCWCD, OCPJBCD
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Mihai Radulescu wrote:The interceptor life-cycle methods are called before the bean one.

Yes, I know. The problem in this case is that one of the life-cycle methods is never invoked.
I have been a little busy, as of lately, with other things so I haven't had time to investigate further.
I suspect that the fact that one of the life-cycle methods is configured using an annotation and the other is configured using the ejb-jar.xml deployment descriptor may have cause the strange behaviour.
Thanks for your help!
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi


I suspect that the fact that one of the life-cycle methods is configured using an annotation and the other is configured using the ejb-jar.xml deployment descriptor.


Take care the dd overwrites the annotations. This can be the reason why the method is only once called.

Regards,
Mihai
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Finally I had some time and inspiration to look into this problem.
I found that I made two mistakes in my code:
1. InvocationContext.proceed() must be invoked in a life-cycle event interceptor method in a default interceptor.

My failure to invoke proceed() resulted in the post-construct life-cycle event interceptor methods in subsequent interceptors, for instance in the EJB class or in other (non-default) interceptor classes, never being invoked.

2. A default interceptor need only to be registered in the ejb-jar.xml deployment descriptor.
This even though it contains an annotated post-construct interceptor method (as in the above example).
The mistake I made was to include it in the interceptors list in the @Interceptors annotation on the bean class as well as in the ejb-jar.xml deployment descriptor.
This resulted in the above interceptor method being invoked twice.
Hope this helps someone!
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

This is the classical "broke of interceptor chain" failure.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Life-Cycle Event Interceptor Method Skipped