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 What is the best way to share an object across multiple applications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "What is the best way to share an object across multiple applications" Watch "What is the best way to share an object across multiple applications" New topic
Author

What is the best way to share an object across multiple applications

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

I have three applications that are deployed in Tomcat as three war files. I need to reuse existing code which at the moment manages the logged on user information in a hashTable defined as



The string key is the sessionID and the UserObject is a normal class that has the following methods



The three existing applications have to reuse these user management code which means all three have to use the same instance of the HashTable. I realize that there are better ways of implementing Single Sign services but i am in a position where i have no choice but to reuse existing code/implementation.

I am looking for ways where i can modify the existing applications so that they can access the same instance of the UserManager class which is the class that contains the HashTable. I plan to create a new war file that will contain the UserManager class and other common classes but now the problem is that the servlet spec does not allow acess to data on individual applications i.e. app1 cant access app2's data.

I have been looking around on Google and found that possible solutions.

Solution 1

Add a new application (app4) which the other three applications will use to authenticate the user. The existing war files (app1, app2 and app3) would use app4 for the authentication by using the following approach.

App4 initialises the UserManagerInstance



App1, app2 and app3 would refer to the object as



Solution 2

The other solution is to add the UserManager to a JNDI context and have apps1-3 access it via JNDI.

Questions

- Which of the two solutions do you think is better?

- With solution2, how will the UserManager object be initialised before it is put on the ? I am not very familiar with JNDi so would really like to see an example of how i can initialise the object on Tomcat's JNDI and how i can access it.

- The new application will basically be providing a service to the other applications. Is there a better way of providing this service bearing in mind that the framework in use is Struts 1.

Environment used
--------------------------
Tomcat 6
JDK 6
Solaris 9
Struts 1.2

Thanks








 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the best way to share an object across multiple applications