aspose file tools*
The moose likes Servlets and the fly likes Context Share between 2 Web Apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Context Share between 2 Web Apps" Watch "Context Share between 2 Web Apps" New topic
Author

Context Share between 2 Web Apps

Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41
My guess is this problem is related to cookies and session handling.

Problem description

WebAppA (J2EE) allows only single instance on desktop. This is achieved by window name as desktop allows only single window with same name.

Now I want to implement interaction � context share between 2 web applications. Process flow will be as follows

1. WebAppA instance in running within browser of the desktop with session1 on app server1
2. User clicks URL with context parameters (book id, param id etc) in WebApp2. This is received by app server 2 and session 2 is created. Response is received by desktop with java script code. That checks for cookie and window handle presence for WebAppA.
3. It founds WebAppA is running on the desktop.
4. This javascript code needs to transfer context parameters to Session 1.

What are the best ways to handle this?
1. Maintaining 2 different cookies? One for session1 and one for session 2?
2. Or 2 handle this situation at servlet side. This may need DB to store session identity. Though I am not sure how?

Any other options?

Other points we need to take care are �
If WebAppA instance is not running and user is authorized in webApp2, we will need to authorize and authenticate user in webAppA without making him to login to WebAppA.
What are the best ways to do this? Are cookies reliable for this?
Authentication � user id / password for WebAppA and WebAppB are different but can be mapped with some key.


Thanks
Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41
Any comments?
Did I post it to wrong group?

Thanks,
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

WebAppA (J2EE) allows only single instance on desktop. This is achieved by window name as desktop allows only single window with same name.


I'm not sure what you mean by this.
Servlets apps don't run on a desktop, they run on a server and are accessed via a client app (usually a browser).
There is no way for a server side app to know how many browser instances are running on a client's machine.
[ January 09, 2007: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Servlet apps run perfectly on desktop. I prefer web interfaced desktop application that old type swing/awt/swt


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Originally posted by D Rog:
Servlet apps run perfectly on desktop.


No, they don't. You can run local apps using a local server, but they are still web apps -- not desktop apps.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41
Pls. read the message. - Both WebAppA and WebAppB run on app server in cluster environment. on Application user will access web application on browser. Browser will have window handle with window name. For e.g JavaRanch big Moose Saloon was given same window name "MySaloon" then you can not have 2 browsers running JavaRanch big Moose Saloon on desktop.

You can achieve this by simple trick with javascript by allowing jsp to run through window.open method with same name.

Issue I am trying to solve is -

Let say I want to transfer context information - web contents - parameters from Google to javaranch application. - How to do it?

Though I have other constraints of allowing how many browser windows to allow and extend this communication further - between Citrix metaframe and browser
How to achieve this?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I did read the message and it wasn't clear.
That's why I asked for clarification.
You're opening the other browser instance with Javascript; now it's more clear.

There are several ways to pass data from one app to another; hidden form fields, query string variables, a shared database, rmi, webservices, and, depending on the container, you might have some cross-context capabilities.
Since you have handles from one browser instance to the other, you could also pass some of the data via javascript calls.

Which is best, would depend on the specifics of your situation.
What have you tried so far?
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

It was discussed many times, application context isn't sharable, it's even not movable between nodes. So you need to create some share point, as sharable file system, database and so on.
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Originally posted by Bear Bibeault:


No, they don't. You can run local apps using a local server, but they are still web apps -- not desktop apps.
Give me a definiton of desktop application, otherwise your words cost nothing.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

D Rog,
If you wish to debate the definition of a desktop app, please start a new thread. Let's not hijack Vis Deo's thread with off topic disucssions.

Thanks,
-Ben
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Originally posted by Vis Deo:
Pls. read the message


Pls is not a word. Please use real words such as "please" when posting.
Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41
Thanks for all response.

Hope this clarifies my requirement

WebAppB has href � URL with target window new for WebAppA � like
http://webAppA.com/abc.jsp?ubb=get_topic&f=7&t=018460

1.User1 has one browser1 open for webAppA and he is middle of doing something. that is session1 on appserver1
2.Then User1 goes to browser2 of WebApp2. And clicks above URL for WebAppA. New browser3 window submits above URL. Response is received by browser3 from appserverN with new session. The javascript code in the browser3 response checks for presence of browsers for WebAppA. It founds the instance of Browser1.
3.The code will close browser3 and make the Browser1 active and will prompt user1 that you have active session for WebAppA. The code will prompt the user something like � �You have active session for WebAppA, Do you want to abort the activities in WebAppA and bring the parameters from the url you cliked and start request�

User will need to have choice to continue with what ever he was doing in WebAppA in browser1 and bring these (ubb=get_topic&f=7&t=018460) parameters latter in the browser1 � like some button bring datafrom previous click/request.

There will be many other alternative flows. This may be the most crucial one to handle.

The solution

WebAppA for browser1 will have cookie1 for session1
When the new request comes in on browser3, WebAppA it may create another cookie for session2 and writes those parameters in that cookie
1. WebAppA is responsible to read all cookie(1 & 2) data for WebAppA
2. Should it share the same cookie?
What are the advantages � disadvantages with these 2 approaches?

Is there any other solution that can be implemented from AppServer side ?

Thanks
[ January 09, 2007: Message edited by: Vis Deo ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What are the advantages � disadvantages with these 2 approaches?


If the two apps are running under different domains (google.com, and javaranch.com) you won't be able to use cookies for this.
Browsers don't send cookie data from one domain to another another.

My first instinct would be to use query string variables.

Out of curiosity..
If the two apps have to be so tightly coupled, why are they two separate apps?
[ January 09, 2007: Message edited by: Ben Souther ]
Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41
These 2 applications are not tightly coupled but are based on same key - like member identity.
Transfering data - parameters from one app to other saves time for users as they don't have to remember member id. to save time of busy people - like doctors. They just have appointments for 7-15 mins and within this time they need to use lots of web apps to complete their tasks -

Coming ack to cookie part - WebAppA and WebAppB will not share same cookie

Lets see if I open 2 hotmail sessions on my desktop - can tchnology allows to create 2 different cookies? If so then first browser window for webAppA wil have cookie 1 and when user clicks link in webApp2 - new browser will be opened url with parameters will be submitted to app server. response will be received. That received response will create another cookie for webAppA and will store these parameter received from webApp2

I am poor in cookie and seesion handling.

Thanks
Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41
We will expand this to between think client running on Citrix metaframe and web app on desktop browser. Citrix metaframe is remote terminal.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Context Share between 2 Web Apps