• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to integrate two web applications having two different context paths

 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sessions cannot be shared between different web apps. You'll need to pass any data explicitly using HTTP.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1743
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohit Virbhadre,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic