File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Sharing session data between web apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sharing session data between web apps" Watch "Sharing session data between web apps" New topic
Author

Sharing session data between web apps

Suprakash Das
Greenhorn

Joined: Nov 26, 2000
Posts: 18
Hi,
The software i am currently has about 8-10 web apps linking to each other at various stages. Most pages require authentication. My problem is how do we share common data such as userId and locale preferences across the web applications. Obviously the HttpSession and ServletContext are ruled out.
Has someone faced this problem before? How did u overcome this?
This is urgent so please let me know if anyone has a solution.
Thanks in advance,
Das
Ricardo Cortes
Ranch Hand

Joined: Jan 23, 2002
Posts: 140
Have you thought about persisting any of the data to a database? I dunno if that will work for you but that's my first guess. Or, maybe beans?


Sun Certified J2EE Architect for the J2EE Platform (Part 1)<br />Sun Certified Web Component Developer for the J2EE Platform<br />Sun Certified Programmer for the Java 2 Platform
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

We were discussing this a while back and its heavily vendor specific - what app serbver are you on?
I was looking to allow a Single Sign On ability between applications on Websphere, but also had a look at Tomcat at the same time.
Websphere allows Single Sign On between separate web-apps, but only if it has been enabled via config settings, and ONLY if the web applications share a similar DNS. Therefore you can share between www.domain.com and sub.domain.com, but not between www.domain1.com and www.domain2.com
I think Websphere enables this by having the separate web-applications share the same session ID, which gets turned into individual or shared sessions at the server depending on configuration.
Websphere Portal Server also supports Single Sign On, but I think it enables this by being implemented as a single web-app with multiple channels - ie there is only a single point of contact to the application server...
Dave
Suprakash Das
Greenhorn

Joined: Nov 26, 2000
Posts: 18
Thanks Dave,
The code is going to run on WebSphere V4.0 Single Server Edition.
We don't have a problem about the domain because all the web apps will be running on the same box.
Can you please tell me how to configure the app server to use the same session id across web apps? Or point me to some documentation?
Thanks a lot,
Das
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
The servlet API is specifically designed to prevent what you are trying to do. Web Applications are supposed to be completely independent - they are not supposed to share IDs etc etc. You need to re-factor your design or share information through a database. You could also share information through an independent application running RMI.
Bill
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

check out the getContext() method of ServletContext i/f.


Groovy
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
check out the getContext() method of ServletContext i/f.

That just won't do.
According to the docs, "...this method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container."
But the specs say that:
"HttpSession objects must be scoped at the application (or servlet context) level.
The underlying mechanism, such as the cookie used to establish the session, can be the same for different contexts, but the object referenced, including the attributes in that object, must never be shared between contexts by the container.
To illustrate this requirement with an example: if a servlet uses the RequestDispatcher to call a servlet in another web application, any sessions
created for and visible to the callee servlet must be different from those visible to the calling servlet."
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Originally posted by Suprakash Das:
Hi,
The software i am currently has about 8-10 web apps linking to each other at various stages. Most pages require authentication. My problem is how do we share common data such as userId and locale preferences across the web applications. Obviously the HttpSession and ServletContext are ruled out.
Has someone faced this problem before? How did u overcome this?
This is urgent so please let me know if anyone has a solution.
Thanks in advance,
Das

This could be slightly painful -- create a cookie that contains a unique userid. The cookie can be accessed by all web apps in the same domain. Use that cookie as a key into a small database table that contains the shared information. Cache the information in the HttpSession of each of your individual web apps so that it's read exactly once per web app. A single "Profile" class could accomplish all of these for you...in fact this is basically how the UserProfile class works in WebSphere Personalization and Portal Server...
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
Consider Paul's rocket mass heater.
 
subject: Sharing session data between web apps
 
Similar Threads
Can two different web application share a variable
Threads in a Servlet
Project Directory not browse in my site.
How can i share the session between webapps?
How to let a standalone application talk to web app?