• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to integrate two web applications having two different context paths

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sessions cannot be shared between different web apps. You'll need to pass any data explicitly using HTTP.
 
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rohit Virbhadre,
Your post was moved to a new topic.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic