From 5c108ea34e2ea70be7f0fb266cd3db46b94d3585 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 4 Aug 2014 14:12:59 +0300 Subject: Do not call requestStart/end multiple times when using push (#14228) All HTTP request based push request invoke onRequestStart/End in the servlet. We need to trigger start/end separately in push handler only for websocket messages Change-Id: I16064ea88b0c70812f247028ddb23560536db70d --- .../com/vaadin/server/communication/PushHandler.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java index 93f1434c94..67e5f87153 100644 --- a/server/src/com/vaadin/server/communication/PushHandler.java +++ b/server/src/com/vaadin/server/communication/PushHandler.java @@ -71,9 +71,10 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter { AtmosphereRequest req = resource.getRequest(); if (req.getMethod().equalsIgnoreCase("GET")) { - callWithUi(resource, establishCallback); + callWithUi(resource, establishCallback, false); } else if (req.getMethod().equalsIgnoreCase("POST")) { - callWithUi(resource, receiveCallback); + callWithUi(resource, receiveCallback, + resource.transport() == TRANSPORT.WEBSOCKET); } } @@ -200,15 +201,22 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter { * the atmosphere resource for the current request * @param callback * the push callback to call when a UI is found and locked + * @param websocket + * true if this is a websocket message (as opposed to a HTTP + * request) */ private void callWithUi(final AtmosphereResource resource, - final PushEventCallback callback) { + final PushEventCallback callback, boolean websocket) { AtmosphereRequest req = resource.getRequest(); VaadinServletRequest vaadinRequest = new VaadinServletRequest(req, service); VaadinSession session = null; - service.requestStart(vaadinRequest, null); + if (websocket) { + // For any HTTP request we have already started the request in the + // servlet + service.requestStart(vaadinRequest, null); + } try { try { session = service.findVaadinSession(vaadinRequest); @@ -279,7 +287,9 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter { } } finally { try { - service.requestEnd(vaadinRequest, null, session); + if (websocket) { + service.requestEnd(vaadinRequest, null, session); + } } catch (Exception e) { getLogger().log(Level.WARNING, "Error while ending request", e); -- cgit v1.2.3