views:

3908

answers:

4

We want to split a working application in two different wars in order to be able to update one app without affecting the other. Each webapp will have different ui, different users and different deploy schedule.

The easiest path seams to be sharing the same session, so if app A set session.setAttribute("foo", "bar") app B will be able to see it.

Is there a way to share the HttpSession state for both apps in the same Tomcat instance?

Our app is running on a dedicated tomcat 5.5, there are no other apps running on the same tomcat instance, so any security concerns regarding the session sharing are not a problem.

If it's not possible or this session sharing is a really bad idea please leave a comment.

+5  A: 

You should not share HttpSession; but you can share other objects. For example, you can register an object via JNDI and access the same object in all your apps (databases use this to pool connections).

Aaron Digulla
+1  A: 

If the to webapps are so closely coupled that they need to share objects why are you splitting it in two? Even if you manage them somewhat independently any decent build management system should be able to create a single WAR file for deployment.

A solution like Aaron suggest with JNDI will work, but only if both webapps are running on the same server. If the units are tightly coupled and you are going to be running it on the same server anyway ... might as well have a single WAR

If you really do want them to stand independently I'd seriously examine the data exchange between the two. Ideally you'd want them to only share relevant data with one another. This data could be passed back and forth via POST (or GET if more appropriate) parameters, you might even consider using cookies.

Kris
We are splitting the webapps to be able to update one app without affecting the other. Each webapp will have different ui, different users and different deploy schedule.
Serhii
Then you should definitely make sure they only communicate via some API, not by sharing class instances (unless via something like JMX).
Kris
+6  A: 

One thing to be aware of is that two web apps will use different classloaders. If you want to share objects, they need to use the same version of the class from the same classloader (or else you will get LinkageErrors). That means either putting them in a classloader shared by both web apps (system classpath for example) OR using serialization to effectively drain and reconstitute the object in the right classloader with the correct version of the class.

Alex Miller
A: 

You should not split your app that way in order by have high availability. You could deploy the whole app on many tomcat instances.

cherouvim
It's not an availability problem. We want two different wars because each one will have it's own purpose, like an admin app and a users app.
Serhii