• Post Reply Bookmark Topic Watch Topic
  • New Topic

When is a session object serializable?

 
pralav Swamy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
There are many session objects in our project which has over 1000 classes. What would you suggest as the best practice to identify all of the session objects. I am using eclipse. How to detect they are serialized or not. If not serialized how could i make sure they are serializable or not.?
Appreciate your time.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just throwing out some ideas. Do you mind employing a HttpSessionAttributeListener and in the call back methods check if the objects that are being added to session implement Serializable ?
I know not a great answer but you will get some idea of objects that are'nt yet serializable.
 
pralav Swamy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey karthik,

Thanks for the reply.. could you elaborate on it?.. I am green horn and what you said just went way over ma head ..if it's asking too much dont bother abt it.. thanks a lot
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pralav,

this is what i meant - If you implement HttpSessionAttributeListener
and configure that in your web application, the interface methods like 'attributeAdded' will be called when a workflow/jsp/anything tries to set a session attribute in the HttpSession object. You will receive a notification of the event.
The you can query HttpSessionBindingEvent for the object that was added to the session.

HttpSessionBindingEvent.getValue()

The you can check if this object implements serializable and log to some log file if it doesnt.

So if you access all the major parts of the workflow, you will have some idea of the objects that were added to session and do not implement serializable from the log file.

I also vaguely remeber weblogic throwing warning messages on the console when it would encounter a non-serializable object being added to the session. Not sure if others do. If they do then you dont have to do anything.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you making this post in an EJB forum, I would interpret your question in this way: how to detect if a stateful session bean is passivated (which could involve serialization). To do this, you can put some code in the ejbPassivate() method, eg writing to a log.

You won't ask such a question of an entity bean as passivation means that the instance is being disassociated from an entity object identity and moved back into the pool.
 
pralav Swamy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow!! karhtik and chung - Thank you guys.. Yes I am looking for only session objects. The way I am looking is I did search for setAttribute in the project in eclipse env. This got me all the session.setAttribute lines of code which were like 5 or 6 of them. What I am trying to do is find if these are in classes that implement serialization. If not see wheter I can serialize it or not. I have already found the session objects. Just want a good procedure to tell if I can serialize them or not. Please let me know if you guys have any suggestion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!