Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » HTTPSession, multiple browser tabs/windows and "Page reload"(How can I identify the browser window of a HTTPSession?)
HTTPSession, multiple browser tabs/windows and "Page reload" [message #1743006] Fri, 09 September 2016 11:57 Go to next message
Gunnar Adams is currently offline Gunnar AdamsFriend
Messages: 49
Registered: May 2016
Member
Hi,
we are using the HttpSession to store the "model" of our application from which it is possible to recreate the user interface at any time.
This allows us to survive a page reload in the browser quite gracefully.

I now found that RAP is able to handle multiple browser windows/tabs as individual uiSessions.
This poses a problem for us, because, if a user attempts to open a second instance of our application in a new browser tab, the first instance (bound to the HttpSession) will be used instead of creating a new one.

Is there some kind of "logical" HTTPSession object, which could be used to identify the browser window from which an entry point has been called?
Are you using the window.sessionStorage to store the Client identifier? If yes, this would survive a reload of the page in that tab, right?
Is it possible to access the uiSession identifier from the server side in order to store the model data?

I am thinking about doing somthing like the following:

Per HTTPSession maintain a list of IDs associated with different browser windows.
The individual application instance is stored and retrieved from the HTTPSession via this ID.
The entry point should check at the earliest opportunity, if there is an ID reqistered in window.sessionStorage (what would be the best way to do this?) and select the correct (existing or new) application instance on the server side to be used for the new uiSession.
If an ID is found for this browser window, get the application instance with that ID from the HTTPSession object.
On creation of a new application instance, execute script on the client, which sets the unique ID in window.sessionStorage.

Questions:
1. Does that make any sense?
2. Wouldn't it be nice to expose something like a LogicalHTTPSession directly in RAP?

Best regards,
Gunnar



Re: HTTPSession, multiple browser tabs/windows and "Page reload" [message #1743494 is a reply to message #1743006] Thu, 15 September 2016 23:13 Go to previous messageGo to next message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 221
Registered: February 2011
Senior Member
The rwt connection id is re-created every time you refresh the page, it's not bound to a particular window or tab.
It's the cid=xxxxxx parameter on every request

I don't see why you couldn't edit rwt/remote/Connection.js in the RWT bundle to add an extra querystring parameter to every request in the _createRequest function. Initialise the new ID (create or fetch from window.sessionStorage) in the constructor and use that in your server side code to identify which tab/window the request is coming from.

I wouldn't try and re-use the same rwt connection id, that may have unknown side effects.
Re: HTTPSession, multiple browser tabs/windows and "Page reload" [message #1743542 is a reply to message #1743494] Fri, 16 September 2016 09:36 Go to previous message
Gunnar Adams is currently offline Gunnar AdamsFriend
Messages: 49
Registered: May 2016
Member
Thank you very much for your answer.
Until now I have not been looking too much into the workings of the RAPClient, also because my Javascript knowledge is limited.
Thanks for pointing me in the right direction.

I came up with the following code:

Connection.js:


additional code in construct():

if (window.sessionStorage.getItem('rwtsessid') === null) {
this.newWindowSessId();
} else {
this._windowsessId = window.sessionStorage.getItem('rwtsessid');
}


newWindowSessId : function() {
this._windowsessId = new Date().valueOf();
window.sessionStorage.setItem('rwtsessid',this._windowsessId);
return this._windowsessId;
},

_createRequest : function() {
var cid = "";
var wid = "";
if( this._connectionId ) {
cid = ( this._url.indexOf( "?" ) === -1 ? "?cid=" : "&cid=" ) + this._connectionId;
} else
if (this._windowsessId ) {
wid = ( this._url.indexOf( "?" ) === -1 ? "?wid=" : "&wid=" ) + this._windowsessId;
}
var result = new rwt.remote.Request( this._url + cid + wid, "POST", "application/json" );
result.setSuccessHandler( this._handleSuccess, this );
result.setErrorHandler( this._handleError, this );
return result;
},

Explanation:
I found that the request object accessible from AbstractEntryPoint.createUI() will not yet contain the cid parameter. Because I need to select the corresponding application instance object by combination of sessionid (via HttpSession) and the transmitted wid parameter, The "wid" needs only to be transmitted for this "first" request.

My createUI() function in the entry point looks something like this:

public int createUI() {

HttpSession httpsess = RWT.getUISession().getHttpSession();
String wid = RWT.getRequest().getParameter("wid");
if (httpsess.getAttribute("sessionmgr"+wid) == null) {
msman = new SessionManager(this);
msman.newSession();
httpsess.setAttribute("sessionmgr"+wid, msman);
} else {
msman = (SessionManager) httpsess.getAttribute("sessionmgr"+wid);
msman.recreateSessions();
}

The msman object is my application's "model", which will (re)create the user interface widgets.
Of course, I still have to implement code which removes the application instance from the HttpSession Object when the application instance is closed (and this is not the last remaining session).

Now I am able to launch several different sessions of the application in multiple browser tabs, also surviving the reload of the different pages

Question:
Is there a chance, that this functionality could make it back into the official RWT bundle? In view of future RAP updates and maintainability of our project, I do not like the idea of patching the code.

Thank you very much and best regards
Gunnar
Previous Topic:Occasional NullPointerException on TableEditor
Next Topic:Running RAP on WebSphere 8.5 for z/OS
Goto Forum:
  


Current Time: Thu Mar 28 20:09:13 GMT 2024

Powered by FUDForum. Page generated in 0.03702 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top