IDEMPIERE-4154 ServerPush Adjustments. AtmosphereResource: use recommended suspend method for infinite suspend. ZkAtmosphereHandler: add server log for errors. serverpush.js: use POST to avoid cache issue, include session parameter to be consistent with other zkau request.

This commit is contained in:
hengsin 2020-02-23 20:59:15 +08:00
parent 667c4f7675
commit 0871b81c87
3 changed files with 13 additions and 4 deletions

View File

@ -268,7 +268,7 @@ public class AtmosphereServerPush implements ServerPush {
}
if (!resource.isSuspended()) {
resource.suspend(-1);
resource.suspend();
}
this.resource.set(resource);

View File

@ -29,6 +29,8 @@ import org.atmosphere.cpr.AtmosphereRequest;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.atmosphere.cpr.AtmosphereResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.http.WebManager;
@ -41,6 +43,8 @@ import org.zkoss.zk.ui.sys.WebAppCtrl;
*/
public class ZkAtmosphereHandler implements AtmosphereHandler {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void destroy() {
}
@ -49,6 +53,7 @@ public class ZkAtmosphereHandler implements AtmosphereHandler {
if (session.getWebApp() instanceof WebAppCtrl) {
WebAppCtrl webAppCtrl = (WebAppCtrl) session.getWebApp();
Desktop desktop = webAppCtrl.getDesktopCache(session).getDesktopIfAny(dtid);
log.warn("Could not find desktop: " + dtid);
return new Either<String, Desktop>("Could not find desktop", desktop);
}
return new Either<String, Desktop>("Webapp does not implement WebAppCtrl", null);
@ -101,10 +106,12 @@ public class ZkAtmosphereHandler implements AtmosphereHandler {
private Either<String, Session> getSession(AtmosphereResource resource, HttpServletRequest request) {
Session session = WebManager.getSession(resource.getAtmosphereConfig().getServletContext(), request, false);
if (session == null)
if (session == null) {
log.warn("Could not find session: " + request.getRequestURI());
return new Either<String, Session>("Could not find session", null);
else
} else {
return new Either<String, Session>(null, session);
}
}
@Override
@ -116,6 +123,7 @@ public class ZkAtmosphereHandler implements AtmosphereHandler {
Either<String, AtmosphereServerPush> serverPushEither = getServerPush(resource);
String error = serverPushEither.getLeftValue();
if (error != null && serverPushEither.getRightValue() == null) {
log.warn("Bad Request. Error="+error+", Request="+resource.getRequest().getRequestURI());
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().write(error);
response.getWriter().flush();

View File

@ -23,7 +23,7 @@
trace: false,
ajaxOptions: {
url: zk.ajaxURI("/comet", {au: true}),
type: "GET",
type: "POST",
cache: false,
async: true,
global: false,
@ -35,6 +35,7 @@
this.timeout = timeout;
this.ajaxOptions.data = { dtid: this.desktop.id };
this.ajaxOptions.timeout = this.timeout;
this.ajaxOptions.url = zk.ajaxURI("/comet", {au: true,desktop:this.desktop.id,ignoreSession:false}),
this.trace = trace;
var me = this;
this.ajaxOptions.error = function(jqxhr, textStatus, errorThrown) {