File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HttpSessionActivationListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HttpSessionActivationListener" Watch "HttpSessionActivationListener" New topic
Author

HttpSessionActivationListener

nisha chidella
Ranch Hand

Joined: Jul 24, 2008
Posts: 57
If a web Application is not distributed, do we get a error if we write a listener that implements HttpSessionActivationListener ?
I am referring to HFSJ chapter 6 Listener examples.




I am getting error 404 and the server log shows this ---

Feb 17, 2009 10:56:52 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class com.example.Dog
java.lang.InstantiationException: com.example.Dog
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3787)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1116)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1214)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Unknown Source)

It works fine if the class doesn't implement HttpSessionActivationListener.


SCJP 5.0(100%)
Preparing for SCWCD
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

java.lang.InstantiationException: com.example.Dog

There is no default public constructor in your class. How is the container going to instanciate it ?


[My Blog]
All roads lead to JavaRanch
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
It works fine if the class doesn't implement HttpSessionActivationListener.


Christophe

but if this class dosen't implement HttpSessionActivationListener then how it works without providing a default constructor?


Thanks <br />Poonam Agarwal SCWCD 86%
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Sorry, that's a mistake. I don't think you need a default constructor for listeners like HttpSessionBindingListener and HttpSessionActivationListener, because these listeners are not declared in web.xml. For example, the container will scan all objects in the session, and call any necessary method on objects implementing HttpSessionActivationListener, when the session is migrated.

Now, the problem is : did you configure this listener in web.xml ? How ?
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Chritophe,

Each listener class must have a public constructor taking NO arguments.

Now, the problem is : did you configure this listener in web.xml ? How ?


HttpSessionActivationListener and HttpSessionBindingListener are default to check by the container is there is any implementation class available.

there is no need to configure these listeners in web.xml using <listener> tag. Right??

Is this problem because of HttpSessionActivationListener is declared for the non-distribured application???

Please correct me if I am wrong


Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

there is no need to configure these listeners in web.xml using <listener> tag. Right??

Right. But what happens if you do ? I'd like to hear nisha's answer before going further.

Is this problem because of HttpSessionActivationListener is declared for the non-distribured application?

Definitely not.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
I'd like to hear nisha's answer before going further.


I dont know about the nisha but my doubt about using HttpSessionActivationListener in non-distribured env has been cleared by you.



Thanks Buddy
nisha chidella
Ranch Hand

Joined: Jul 24, 2008
Posts: 57
thanks christopher. that was the problem. there was no default constructor.


I don't think you need a default constructor for listeners like HttpSessionBindingListener and HttpSessionActivationListener, because these listeners are not declared in web.xml.


HttpSessionBindingListener doesn't need to be configured in web.xml but HttpSessionActivationListener has to be configured in web.xml, which i did correctly, but for which i forgot the default constructor.
nisha chidella
Ranch Hand

Joined: Jul 24, 2008
Posts: 57
sorry, now i went through this : http://faq.javaranch.com/java/DeclaringListeners

so we don't need to declare both HttpSessionBindingListener and HttpSessionActivationListener in DD.

it works with or without declaring the Listener in DD but it needs a default constructor for HttpSessionActivationListener.
it works without the default constructor for HttpSessionBindingListener because i have a overloaded constructor for the class and this class is being instantiated from other a ServletContextListener class using this overloaded constructor. so this class gets instantiated when the context is initialized. so why do i need a default constructor for HttpSessionActivationListener ?

am really confused. please help. sorry if it's a very silly question. but am not getting this.
nisha chidella
Ranch Hand

Joined: Jul 24, 2008
Posts: 57
ok...my problem is solved..we don't need default constructor for HttpSessionActivationListener too.

all this problem because i configured the Listener in DD. I think i should read HFSJ Errata before i read the book. it's in bold letters "HttpSessionActivationListener must be configured in DD". what a big error.



Right. But what happens if you do ? I'd like to hear nisha's answer before going further.



If we do and we don't provide default constructor, we get:

java.lang.InstantiationException


thanks for the help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSessionActivationListener