*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes [listener]Can someone tell me how many listeners should register in the DD? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "[listener]Can someone tell me how many listeners should register in the DD?" Watch "[listener]Can someone tell me how many listeners should register in the DD?" New topic
Author

[listener]Can someone tell me how many listeners should register in the DD?

liny
Greenhorn

Joined: Dec 08, 2004
Posts: 10
Hi, everybody:
There are eight listeners below:
--------------------
ServletContextListener
ServletContextAttributeListener
ServletRequestListener
ServletRequestAttributeListener
HttpSessionListener
HttpSessionAttributeListener
HttpSessionActivationListener
HttpSessionBindingListener
--------------------
Can you tell me what should register in the DD , and what not to?
Sri Ram
Ranch Hand

Joined: Sep 08, 2002
Posts: 48
except HttpSessionActivationListener & HttpSessionBindingListener all others need to be registered in DD.

Vanniarajan
liny
Greenhorn

Joined: Dec 08, 2004
Posts: 10
Are you sure???
According to HFS&J, HttpSessionActivationlistener must be configured in the DD!(See page 261)
I think the list below must be registered in the DD:
-------------------------------
ServletContextListener
ServletContextAttributeListener
HttpSessionListener
HttpSessionAttributeListener
HttpSessionActivationlistener
-------------------------------

The HttpSessionBindinglistener have no need to be configured in the DD.
But I don't know if the ServletRequestListener and the ServletRequestAttributeListener have to be configured in the DD!
Please tell me! Thanks!
Gabriel Forro
Ranch Hand

Joined: Apr 16, 2004
Posts: 59
Hi,

every listener should be registered in DD except HttpSessionBindingListener.


Gabriel
hasan khan
Ranch Hand

Joined: Aug 04, 2003
Posts: 222

sorry to say i dont know the correct answer but i dont agree with Gabrie


SCJP, SCWCD
Pabak Nanda
Greenhorn

Joined: Nov 04, 2004
Posts: 24
I am fully agree with Gabriel Forro. Except HttpSessionBinidingListener you have to configure all other ( 7 other ) listener.
The configuration is like

<listener>
<listener-class>Fully qualified Class Name </listener-class>
</listener>


Thanks,
Pabak
liny
Greenhorn

Joined: Dec 08, 2004
Posts: 10
Originally posted by Pabak Nanda:
I am fully agree with Gabriel Forro. Except HttpSessionBinidingListener you have to configure all other ( 7 other ) listener.
The configuration is like


Thanks,
Pabak


Yes! That's right!
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3179
    
    3
Originally posted by liny liny:


Yes! That's right!


Nope,

Vanniarajan gave correct answer:

*HttpSessionActivationListener* AND *HttpSessionBindingListener* must not be registered in deployment descriptor, instead, they are implemented by session attribute objects.

Here is what specification says :

Containers must notify any session attributes implementing the
HttpSessionActivationListener during migration of a session. They must notify listeners of passivation prior to serialization of a session, and of activation after deserialization of a session.

So, you can see - attributes themselves implement this interface, attributes are listenes, not some special class, which configured via DD.

Also, refer these articles :

http://www.macromedia.com/support/jrun/ts/documents/tn18279.htm
http://e-docs.bea.com/wls/docs70/webapp/app_events.html

regards,
MZ


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Romy Huang
Ranch Hand

Joined: Sep 30, 2003
Posts: 35
*HttpSessionBindingListener* must not be registered in deployment descriptor, not *HttpSessionActivationListener*.


In HF servlet & JSP page 261 says this.
[ December 09, 2004: Message edited by: Romy Huang ]
Romy Huang
Ranch Hand

Joined: Sep 30, 2003
Posts: 35
These articles ref to servlet 2.3, now servlet 2.4

Originally posted by Mikalai Zaikin:

Also, refer these articles :

http://www.macromedia.com/support/jrun/ts/documents/tn18279.htm
http://e-docs.bea.com/wls/docs70/webapp/app_events.html

regards,
MZ

[ December 09, 2004: Message edited by: Romy Huang ]
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3179
    
    3
Ok, refer to JavaDoc API (J2EE 1.4):

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSessionActivationListener.html


javax.servlet.http
Interface HttpSessionActivationListener

--------------------------------------------------------------------------------

public interface HttpSessionActivationListener
extends java.util.EventListener

Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated. A container that migrates session between VMs or persists sessions is required to notify all attributes bound to sessions implementing HttpSessionActivationListener.


Since:
2.3



----------------------------------------------------------------------

Attributes which are bound to session are notified themselves, not special listeners.

----------------------------------------------------------------------

Please, take a look here:

http://java.sun.com/webservices/docs/1.2/tutorial/doc/Servlets11.html


Notifying Objects That Are Associated with a Session

Recall that your application can notify Web context and session listener objects of servlet life cycle events (Handling Servlet Life Cycle Events).

You can also notify objects of certain events related to their association with a session such as the following:

- When the object is added to or removed from a session. To receive this notification, your object must implement the javax.http.HttpSessionBindingListener interface.
- When the session to which the object is attached will be passivated or activated. A session will be passivated or activated when it is moved between virtual machines or saved to and restored from persistent storage. To receive this notification, your object must implement the javax.http.HttpSessionActivationListener interface.



P.S. I do not have a HF S & JSP book, so can not say on the page 261.

P.P.S. The purpose of this interface - to allow object (a.k.a. session attribute) store himself in some persistent storage (like DB, or serialize on disk) and later allow to restore himself. I don't see any sense to delegate this to different class (a.k.a. listener configured in DD) for the following reason:
1) (many listeners for each type) if you have 10 types of object potentially stored in session - you have to configure them in DD, whenever object of new type is added - change DD is necessary.
2) (single listener for all types) separate listener can not get access to object itself - note interface privides only 2 new methods with only session as argument. how separate listener supposed to store object in persistent place?

regards,
MZ
Romy Huang
Ranch Hand

Joined: Sep 30, 2003
Posts: 35
I check servlet special yesterday before I post that. now I wrie a progrom to test it. You are right. HttpSessionActivationListener don't need to register in DD. Thank you to clear that.
hasan khan
Ranch Hand

Joined: Aug 04, 2003
Posts: 222

check
http://e-docs.bea.com/wls/docs90/webapp/app_events.html#178631
Charith Fernando
Ranch Hand

Joined: Sep 12, 2005
Posts: 67
that was an interesting thread... coz when i read HFSJ i thought that i need to register HttpSessionActivationListener in the DD.. but when i did some questions it seem the other way.. but i think i have cleared all my doubts now... so let me summarise what i learnt... and please point out if i'm wrong...

HttpSessionBindingListener Doest have to be registered in the DD but
HttpSessionActivationListener has to be registered if it is written as a seperate class without implementing it in the attribute class it self...

am i correct?


Charith I Fernando<br />SCJP5, SCWCD, SCBCD, BSc(Hons) IS<br />+94 773 263 222 (mobile)
M Jairam
Greenhorn

Joined: Nov 04, 2005
Posts: 22
I think Charith Fernando is correct.

Please note that my conclusions are based on my own observations after reading the error page from O'reilly for HFSJ, contents in this thread and specifically HFSJ page 262.

The question of if a listener has to be entered in DD depends on the type of class implementing the listener.

First let us look at each of the listeners and see who can implement them (HSFJ Page 262):

HttpSessionListener ........Implemented by some class (other than attribute class).

HttpSessionAttributeListener...Implemented by some class (other than attribute class).

These two have to be entered in the DD - otherwise the container will not know of it existance.

HttpSessionBindingListener...Implemented by an Attribute class.

This does not have to be entered in DD - because any attribute added to a session, can be checked to see if it implements this listener interface and thus can be notified.

Now comes the interesting part:

HttpSessionActivationListener....Implemented by an Attribute class AND by some other class.

Now, my believe is that you will have to enter this listener in DD if it is implemented by "some other class" and does not have to be entered in DD if it is implemented only by Attribute classes.

Let us know if Charith and my observation is wrong.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [listener]Can someone tell me how many listeners should register in the DD?
 
Similar Threads
About Listeners
listener register order?
HttpSessionBinding listener
what listeners don't need to register in DD
osgi: question about bundle communication / design