| Author |
EJB 3.0 Interceptors question
|
Deepak Jain
Ranch Hand
Joined: Aug 05, 2006
Posts: 637
|
|
From EJB IN Action 3.0 "In the pure AOP world, interception takes place at various points (called point cuts) including at the beginning of a method, at the end of a method, and when an exception is triggered." With @Interceptors annotation applied to a bean method, the registered class's AroundInvoke method will be invoked when the bean method is invoked by the client which will log the entry point of the method and finally invoke proceed() on InvocationContext. How can one log @ the end of the bean method and when an exception is thrown? as stated in the EJB 3 in action How can one access the return values
|
SCJP, SCWCD, SCBCD
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
How can one log @ the end of the bean method and when an exception is thrown?
That's an AOP concept, so maybe you should read something about AOP if you're interested in it. Your object is proxied, so when you think you're calling a method of your bean, you're actually calling the method of a proxy of your bean. In the proxy, anything can be controlled. Before/After calling the actual method of your bean, the proxy can do things, like calling interceptor methods. Same for exceptions, where the proxy can catch some exceptions and do something special when it happens.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Deepak Jain
Ranch Hand
Joined: Aug 05, 2006
Posts: 637
|
|
So is it supported by EJB 3 like AroundInvoke tags ? Are they any tags to do so.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
No, anything other than @AroundInvoke is not supported.
|
 |
Deepak Jain
Ranch Hand
Joined: Aug 05, 2006
Posts: 637
|
|
Limited supported in EJB 3.0. I hope they come up with annotations to handle exit and exceptions in a method. Only then one can think of implementing Logging [Cross Cutting concern] in a separate module. With current support its pretty much like a servlet filter.
|
 |
germano giudici
Greenhorn
Joined: Dec 01, 2008
Posts: 2
|
|
I think it's possible to use a try catch around the proceed method invocation, then log exception. The return value is taken from the return value of proceed method. Cheers Germano
|
 |
Niranjan Deshpande
Ranch Hand
Joined: Oct 16, 2005
Posts: 1277
|
|
The book already mentions that for elaborate AOP support one must think of dedicated frameworks like AspectJ.
|
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
|
 |
 |
|
|
subject: EJB 3.0 Interceptors question
|
|
|