Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionActivationListener

 
nisha chidella
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.InstantiationException: com.example.Dog

There is no default public constructor in your class. How is the container going to instanciate it ?
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic