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 How to integrate two web applications having two different context paths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to integrate two web applications having two different context paths" Watch "How to integrate two web applications having two different context paths" New topic
Author

How to integrate two web applications having two different context paths

Praveen Yendluri
Ranch Hand

Joined: Apr 13, 2011
Posts: 34
Hi,

I have an application working perfectly currently. Say it as "APP1".The context path of APP1 is /APP1

Now I am introducing a new link into that application. Clicking on the new link will call home page of another application, say "APP2".

The context path of APP2 was different form APP1. The context path of APP2 is /APP2.

At the same time the session that was created in APP1 should be forwarded to the APP2.

Can any one help me how to access the web application that was resided in different context path and how to forward the same session to second web application?

Thanks,
Praveen
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Sessions cannot be shared between different web apps. You'll need to pass any data explicitly using HTTP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

I'm using this topic to clarify one of my question....

Bear,

If I had this case and I wanted to change the design.... Can I go ahead and store the "session" in a database and use it in the other app? is it a good practice ? or is it risky ? what other design can I use to share the session between two apps ?

Regards...


Time is what we want the most, but what we use the worst. -- William Penn
Praveen Yendluri
Ranch Hand

Joined: Apr 13, 2011
Posts: 34
Folks,

Please let me know how to access the web application that was resided in different context path ?

Thanks,
Praveen
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Robin John wrote:ICan I go ahead and store the "session" in a database and use it in the other app?
I would not store the session. Why would you want to store the session? If it's to get at the data stored within it, then just exchange the data.

But why a database? If the intent is to merely pass the data to an HTTP operation, pass it using HTTP and avoid all the overhead of DB operations.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Praveen Yendluri wrote:,Please let me know how to access the web application that was resided in different context path ?

What part has you stumped? You can make HTTP requests to the other app. Is that what you are having trouble with.

As already pointed out, session-sharing is not possible.
Guy Cooke
Greenhorn

Joined: Mar 30, 2011
Posts: 4
Praveen,

I see you have been told here that this is not possible to share sessions, but this is not entirely correct.

What you are asking for, it sounds like, is "session replication." It is possible, but the way you do it depends on your application server and your application.

The idea of storing session state information in the database is perfectly acceptable. You may be able to find existing implementations of this for your platform.

Other strategies usually involve "in memory session replication" (another buzz-phrase you can search for). This may be supported by your application container/application server and you just need to set it up. Again, this will be different between application servers. You will need to research the options for yours.

If you run out of options and have to make your own, you might want to start by looking at the javax.servlet.http.HttpSessionListener interface. You might use this to instantiate and destroy sessions in your database, if you want to go that way. It would be easy to write code to load and store the session information you are interested in retaining in the database at the beginning and end of each request. In this case you would have to be able to modify APP1 and APP2.

Good luck!

Guy.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

I'm still waiting to hear what's actually trying to be accomplished. "I want to send a string from the session to another app" is vastly different from "I want to set up clustering".
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
It is possible to access a web app in a different context
Its even part of the Servlet API



Most of the time this call will return null.
On Tomcat you can explicitly configure a web application to allow cross context calls. (http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Common_Attributes)
I'm not sure what other servers do (if anything)

So you can start sharing information at the level of ServletContext attributes.
In order to share session information, you would have to implement something like the HttpSessionContext used to do (with a SessionListener)

On the whole though, sharing information across two web applications on the same server is problematic.
I would take another look at this and ask if you really want to go down this path.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Rohit Virbhadre,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to integrate two web applications having two different context paths
 
Similar Threads
How to replicate sessions between two web applications on the same tomcat?
Sending data between two webapps
multiple apps pointing so same docbase locking the log files from rolling
Tunneling Concept Query
Session problem!