Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(Re)start session on QueryStatus from TIWMonitor
#1
Hi,

Scenario:

In a project I am working on, we use hardware devices running a webbrowser as a display but no touchscreen, mouse or keyboard attached.
They are configured to load a webpage https://webserver.local/externaldisplay
The page https://webserver.local/externaldisplay is handled by a TContentForm in a IntraWeb application.
That page contains a TIWMonitor to poll the server and act based on the response.
When there is a network error or the server is stopped, the client should display a message informing the user of the device.
When the server is restarted the communication has to be restored. No user intervention should be necessary.

Part of this is working.

* After starting up the device, a session is created and the page is loaded via the content handler
* The page is refreshed based on the TIWMonitor response
* When I close the server, a message is displayed in the browser
  TIWMonitor.jsCallbackName gets called with value as a parameter. value == -1 when the server is gone.

But when I restart the server, the value keeps being -1. Reason is the old session does not exists anymore.
What should I do to create a new session on a $/QueryStatus call?
Or in what other way can I get the client to keep working after a server restart?
Reply
#2
This is a very specific scenario and the QueryStatus call was specifically crafted not to create a session. I'll have to create a test case here to better see the (broader) implications of it...
Reply
#3
Hi Alexandre,

I went ahead yesterday with changes to the current version IW15.3.12
  • In IW15.3.12 I can't make a difference in the function TIWMonitor.jsCallbackName between the situation
    ** No server or network problem and
    ** Server is back but session doesn't exist
I understand the current implementation to not create a session on QueryStatus but by making it possible to detect the second situation I would be able to restart a new session.
Therefor I changed the initial value of the xValue variable to -2 in IWCommon.IW.Session.queryStatus. onError the would call TIWMonitor.jsCallbackName with value == -2 and with -1 when there is no session.

My TIWMonitor.jsCallbackName looks like:

Code:
function monitorCalled(value) {
  if (value === -2) {
    // network error, see updated IWCommon.IW.Session.queryStatus
    $('#no-server').show();
  }
  else if (value === -1) {
    // server back but session gone, should be restarted
    window.location.reload(true);
  }
  else {
    $('#no-server').hide();
  }
}

This didn't work at first. I got a 404 Not found exception. I don't exactly understand why but the solution seems setting TIWSessionController.PostRedirectGet = prgEnabled. It's still not 100% foolproof but it is a good start.
Preferable I would be able to start a new session from monitorCalled() without the need to reload() so it would keep trying when it doesn't work the first time.
Reply
#4
Hi Jeroen,

Yes, I understand your changes and they make sense.

The most safe way to restart it is reloading the page, yes, because restoring the state of the whole page from different session seems to me just not viable (given that reloading the page is not a major problem here).

I'll check the cause of the 404 and get back to you.

Cheers,
Reply
#5
Hi Jeoren,

I recreated the 404 status here when restablishing the connection (and creating a new session).

This happens because the browser will repost all the fields from the first request when resubmiting the page (creating a new POST request) when you do

Code:
window.location.reload();


It happens that IW has a built-in safety check to avoid creating sessions when the request doesn't look correct. In this case, the initial request was repeated by the browser, but the server doesn't recognize the session (I'm considering that the server has been restarted, for instance, so it has no recollection of the initial session).
When this safety check fails, IW will respond with a 404, and that's what you got.

When you configured the applicationt o use the Post/Redirect/Get mechanism, the POST request is followed by a GET. So, when reloading the browser will actually send a GET request, instead of a POST and the safety check above doesn't fail, so the session starts.

A better way to reload the page is using this code in your monitorCalled() function:

Code:
window.location = window.location.href;

This will actually "renavigate" to the same URL, so the browser will not re-POST the old parameters back. In practice it works like you were typing it yourself in the browser address bar.

There is another option that also works:

Code:
window.location.assign(document.URL);


So, in short you can either:

a) Keep the PRG pattern and use the window.location.reload() method

b) Disable the PRG pattern and load it using the modified code above

I believe your changes in IWCommon.js are safe and we are going to implement that as well.

Cheers,
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)