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 4f38055916..28e7828c70 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 @@ -236,11 +236,18 @@ public class AtmosphereServerPush implements ServerPush { return; } - this.resource.set(null); + AtmosphereResource currentResource = this.resource.getAndSet(null); synchronized (schedules) { schedules.clear(); } + if (currentResource != null ) { + try { + currentResource.close(); + } catch (IOException e) { + } + } + if (Executions.getCurrent() != null) { if (log.isDebugEnabled()) log.debug("Stopping server push for " + desktop); @@ -262,7 +269,14 @@ public class AtmosphereServerPush implements ServerPush { if (!resource.isSuspended()) { resource.suspend(); } - this.resource.set(resource); + AtmosphereResource oldResource = this.resource.getAndSet(resource); + if (oldResource != null) { + try { + if (!oldResource.isCancelled()) + oldResource.close(); + } catch (Throwable e) { + } + } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/ZkAtmosphereHandler.java b/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/ZkAtmosphereHandler.java index a3c5c3e65f..25b91f0ff4 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/ZkAtmosphereHandler.java +++ b/org.adempiere.ui.zk/WEB-INF/src/fi/jawsy/jawwa/zk/atmosphere/ZkAtmosphereHandler.java @@ -44,6 +44,7 @@ import org.zkoss.zk.ui.sys.WebAppCtrl; public class ZkAtmosphereHandler implements AtmosphereHandler { private static final String SESSION_NOT_FOUND = "SessionNotFound"; + private static final String DESKTOP_NOT_FOUND = "DesktopNotFound"; private final Logger log = LoggerFactory.getLogger(this.getClass()); @Override @@ -58,14 +59,14 @@ public class ZkAtmosphereHandler implements AtmosphereHandler { if (log.isDebugEnabled()) log.debug("Could not find desktop: " + dtid); } - return new Either("Could not find desktop", desktop); + return new Either(DESKTOP_NOT_FOUND, desktop); } return new Either("Webapp does not implement WebAppCtrl", null); } private Either getDesktopId(HttpServletRequest request) { String dtid = request.getParameter("dtid"); - return new Either(dtid, "Could not find desktop id"); + return new Either(dtid, DESKTOP_NOT_FOUND); } private Either getServerPush(AtmosphereResource resource) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/metainfo/zk/lang-addon.xml b/org.adempiere.ui.zk/WEB-INF/src/metainfo/zk/lang-addon.xml index 2744cf2ea2..48dd2b0364 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/metainfo/zk/lang-addon.xml +++ b/org.adempiere.ui.zk/WEB-INF/src/metainfo/zk/lang-addon.xml @@ -45,7 +45,7 @@ Copyright (C) 2007 Ashley G Ramdass (ADempiere WebUI). - + 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 b365ad2122..54e42e624d 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 @@ -40,7 +40,7 @@ var me = this; this.ajaxOptions.error = function(jqxhr, textStatus, errorThrown) { if (me.trace) - console.log("error: " + textStatus + " dtid: " + me.desktop.id); + console.log("error: " + textStatus + " dtid: " + me.desktop.id + " errorThrown: " + errorThrown); if (textStatus != "timeout" && textStatus != "abort" && errorThrown != "SessionNotFound") { if (typeof console == "object") { console.error(textStatus); @@ -56,9 +56,12 @@ me.failures = 0; }; this.ajaxOptions.complete = function() { - if (me.trace) + if (me.trace) { console.log("complete"+ " dtid: " + me.desktop.id); - if (me._req && me._req.statusText == "SessionNotFound" && me._req.status == 400) { + if (me._req) + console.log(me._req.status + " " + me._req.statusText); + } + if (me._req && (me._req.statusText == "SessionNotFound" || me._req.statusText == "DesktopNotFound") && me._req.status == 400) { ; } else { me._schedule();