• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between Interceptors and Callback methods in EJB3

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,


I the process of Learning EJB Interceptors . I came across

The interceptor method runs before any of the bean's business methods are invoked.

In essence , interceptors give you a way to add functionality to your business methods without modifying the methods' code. For example, you can use an interceptor to validate parameters before they're passed to a business method, or perform security checks at the time the business method is called.


As per my thinking these tasks can be achivied using @PostConstruct callback methods know .

so please tell me when to use Interceptors and Callback methods ??
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The @PostConstruct gets invoked only at the bean construction. It's not invoked before every business method invocation. The interceptor methods (@AroundInvoke) allow you to provide hooks before every business method is invoked.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that was a good explanation .
import javax.ejb.*;


Can you please tell me

For example if i have Method Level Interceptor like this when exactly this Interceptor is executed actually ?

I mean after the execution of sayHello or Before sayHello
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi Kiran Varre..

It's nice to see you..
as far as i know.. EJB interceptors is executed before method execution..
Perhaps you could change your code as followed :




Hope this help..
Please correct me if i'm wrong..

Thanks
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much , you solved my another query also that is how to write a Seperate class for Interceptor .

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!