Thursday, May 17, 2007

Session timeout handing in AJAX call

DWR has a global handler textHtmlHandler for this purpose. When a DWR request receives a response that isn't Javascript. It indicates a server session has timed out, and we can redirect user to logon screen in this handler. So any DWR call doesn't need to worry about session timeout.

dwr.engine.setTextHtmlHandler(function() {

Unfortunately, Dojo doesn't have such mechanism, so for each or FormBind, we have to deal with it individually as shown below.

load: function(type, data, evt) {
sessionTimeoutCheck(data, evt);

I have modified dojo source code (doLoad method in BrowserIO.js) to support a global/transparent session timeout for dojo. I don't think Dojo itself will support this feature in the future. This is because dojo's response could be 'text/html' mimeType, which is typically used in setURL of contentPane. And the server normally returns the logon page when session timeout occurs. So dojo cannot know whether it is a requested page or timeout page. DWR is simplier since it doesn't support text/html and we can treat a html response as timeout.

** More on DWR's error handling - It has global/batch/call three levels of fine-grained support.

global error handler:


call level error handlers:

Remote.method(params, {
callback:function(data) { ... },
errorHandler:function(errorString, exception) { ... }

or, in batch level:

Remote.method(params, function(data) { ... });
// Other remote calls
errorHandler:function(errorString, exception) { ... }

No comments: