Reputation: 35
I'm building a Java EE 6 web application where users have to login through a managed bean that is session-scoped. What are EJB interceptors and how can they help me in my program. I have been reading about them, but the materials I read seem a little absurd in explanation. Anyone to put it in the lay terms for me. Thanks in advance
Upvotes: 0
Views: 1225
Reputation: 3387
Interceptors are objects that are able to interpose themselves on method calls or the life cycle events of EJB's or any CDI beans.
Common usages:
Interceptors are the best friends of EJB's :
So, here are the interceptors. For your purpose (login page) as Leonardo said a Filter will be better, but keep the interceptors in your toolbox.
Upvotes: 1
Reputation:
IMO, I don't think interceptors will help you much in this case, because it's used to wrap EJB methods, and probably most of these methods will have to be available only when the user is already logged in the system. It sounds like an unnecessary overhead to check for every EJB method if it's being requested by an authorized user or not. A Filter is usually what you really want when you are trying to restrict the app usage because it works on the request level and you can just check if a user is logged in if there's some Session object there.
Interceptors are certainly useful for horizontal features such as profiling and auditing.
Upvotes: 0
Reputation: 4541
I dont especially know interceptors in Java EE 6 but I know those from Struts 2 framework and it looks to be the same in fact.
The point is that transverse tasks should not be in your classes (logging, identification, security, ...).. so it has been decided to be put inside interceptors.
When the request arrives, before arriving to (and after leaving) your action, I would say, it is intercepted by some other classes that can verify, change or do anything you think is appropriate..
This is a good way of programming so POO is more respected. Your business classes are no more contaminated with pieces of codes that should not be there and more, with pieces of codes that should be accessible from all of the application
Upvotes: 1