diff --git a/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java b/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java index 315f87f8db..cd8f41fb93 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java +++ b/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/AtmosphereServerPush.java @@ -242,13 +242,16 @@ public class AtmosphereServerPush implements ServerPush { return; } - if (log.isDebugEnabled()) - log.debug("Stopping server push for " + desktop); - Clients.response("jawwa.atmosphere.serverpush", new AuScript(null, "jawwa.atmosphere.stopServerPush('" + desktop.getId() + "');")); - try { - commitResponse(); - } catch (IOException e) { + this.resource.set(null); + synchronized (schedules) { + schedules.clear(); } + + if (Executions.getCurrent() != null) { + if (log.isDebugEnabled()) + log.debug("Stopping server push for " + desktop); + Clients.response("jawwa.atmosphere.serverpush", new AuScript(null, "jawwa.atmosphere.stopServerPush('" + desktop.getId() + "');")); + } } public void onRequest(AtmosphereResource resource) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java index a8741802ff..91f311fdd6 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java @@ -369,6 +369,10 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb */ public void logout() { + Desktop desktop = Executions.getCurrent().getDesktop(); + if (desktop.isServerPushEnabled()) + desktop.enableServerPush(false); + Session session = logout0(); DesktopCache desktopCache = ((SessionCtrl)session).getDesktopCache(); @@ -383,6 +387,10 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb desktopCache.removeDesktop(Executions.getCurrent().getDesktop()); } public void logoutAfterTabDestroyed(){ + Desktop desktop = Executions.getCurrent().getDesktop(); + if (desktop.isServerPushEnabled()) + desktop.enableServerPush(false); + Session session = logout0(); //clear context, invalidate session @@ -392,7 +400,7 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb protected Session logout0() { - Session session = Executions.getCurrent().getDesktop().getSession(); + Session session = Executions.getCurrent() != null ? Executions.getCurrent().getDesktop().getSession() : null; if (keyListener != null) { keyListener.detach(); @@ -409,7 +417,8 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb getPage().removeComponents(); //clear session attributes - session.getAttributes().clear(); + if (session != null) + session.getAttributes().clear(); //logout ad_session AEnv.logout(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js b/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js index c7fe0bf790..45f9fd78aa 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js +++ b/org.adempiere.ui.zk/WEB-INF/src/web/js/jawwa/atmosphere/serverpush.js @@ -4,7 +4,9 @@ if (dt._serverpush) dt._serverpush.stop(); - var spush = new jawwa.atmosphere.ServerPush(dt, timeout); + //change to true to enable trace of execution + var trace = false; + var spush = new jawwa.atmosphere.ServerPush(dt, timeout, trace); spush.start(); }; jawwa.atmosphere.stopServerPush = function(dtid) { @@ -18,6 +20,7 @@ delay: 10, failures: 0, timeout: 0, + trace: false, ajaxOptions: { url: zk.ajaxURI("/comet", {au: true}), type: "GET", @@ -27,14 +30,17 @@ data: null, dataType: "text" }, - $init: function(desktop, timeout) { + $init: function(desktop, timeout, trace) { this.desktop = desktop; this.timeout = timeout; this.ajaxOptions.data = { dtid: this.desktop.id }; this.ajaxOptions.timeout = this.timeout; + this.trace = trace; var me = this; this.ajaxOptions.error = function(jqxhr, textStatus, errorThrown) { - if (textStatus != "timeout") { + if (me.trace) + console.log("error: " + textStatus + " dtid: " + me.desktop.id); + if (textStatus != "timeout" && textStatus != "abort") { if (typeof console == "object") { console.error(textStatus); console.error(errorThrown); @@ -43,10 +49,14 @@ } }; this.ajaxOptions.success = function(data) { + if (me.trace) + console.log("success" + " dtid: " + me.desktop.id); zAu.cmd0.echo(this.desktop); me.failures = 0; }; this.ajaxOptions.complete = function() { + if (me.trace) + console.log("complete"+ " dtid: " + me.desktop.id); me._schedule(); }; }, @@ -62,16 +72,22 @@ if (!this.active) return; + if (this.trace) + console.log("_send"+ " dtid: " + this.desktop.id); var jqxhr = $.ajax(this.ajaxOptions); this._req = jqxhr; zAu.cmd0.echo(this.desktop); }, start: function() { + if (this.trace) + console.log("start"+ " dtid: " + this.desktop.id); this.desktop._serverpush = this; this.active = true; this._send(); }, stop: function() { + if (this.trace) + console.log("stop"+ " dtid: " + this.desktop.id); this.active = false; this.desktop._serverpush = null; if (this._req) {