• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3.0 Interceptors question

 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is it supported by EJB 3 like AroundInvoke tags ?
Are they any tags to do so.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, anything other than @AroundInvoke is not supported.
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The book already mentions that for elaborate AOP support one must think of
dedicated frameworks like AspectJ.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic