This post originated from an RSS feed registered with Java Buzz
by Norman Richards.
Original Post: Redeploy web apps without losing the HTTP session
Feed Title: Orb [norman richards]
Feed URL: http://members.capmac.org/~orb/blog.cgi/tech/java?flav=rss
Feed Description: Monkey number 312,978,199
The bug fix cycle on a web application can be time consuming. You've worked yourself into the application and found a bug. You fix it and redeploy. The redeploy should be fast, but it can take quite a few clicks to drill into an application far enough to get back to where you were because you usually lose your HTTP session when an application goes away. If your fix is pure JSP, sure you can overwrite your old JSPs and keep working, but fixes are often a bit more complex.
It's always bothered me, but I realized today that using JBossCache for HTTP session replication in JBoss solves this problem. If you run with session replication (add tc5-cluster-service.xml and mark your app as distributable) then your HTTP session is actually preserved on application redeploy even if you only have a single node. If you run into a logic problem, you just need to fix the code and redeploy the app then reload the page. You'll be right where you left off. Very cool.
There are some tricks here. In order to use HTTP session replication, everything that goes into the session needs to be serializable. (this shouldn't need to be true with TreeCacheAOP but with the standard TreeCache that is used now in JBossCache, that is true) This takes a bit of effort and can be a real headache if you haven't been careful about what goes into the session. It can also be a headache if you don't really take care of serialization details like SerialVersionUID. This bit me today when I changed a method on one of my JSF managed beans. JBossCache couldn't restore the session correctly because of the SerialVersionUID mismatch. Woops.
I feel dumb for not realizing this sooner, but I rarely develop an application with clustering on. However, it's so useful that I plan to develop all my applications as distributable, where possible, to take advantage of the longer lived sessions.