summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-02-20 15:56:30 +0200
committerVaadin Code Review <review@vaadin.com>2015-02-20 15:38:26 +0000
commit1dcfb9821bbfa72fefd44a7fef26561fd6edf5e6 (patch)
tree5abbdad2b8d3d3c7a38001bff068a28f51ba2a68
parentfd8078d691f6b6eec407882280730104f5027e3d (diff)
downloadvaadin-framework-1dcfb9821bbfa72fefd44a7fef26561fd6edf5e6.tar.gz
vaadin-framework-1dcfb9821bbfa72fefd44a7fef26561fd6edf5e6.zip
Ensure resource is valid before writing to it (#16862)
Change-Id: I61e0003a2301100a5f0bfc18581a279207c4e812
-rw-r--r--server/src/com/vaadin/server/communication/PushHandler.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java
index 6ee81270cd..7e7183193a 100644
--- a/server/src/com/vaadin/server/communication/PushHandler.java
+++ b/server/src/com/vaadin/server/communication/PushHandler.java
@@ -28,6 +28,7 @@ import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResource.TRANSPORT;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter;
+import org.atmosphere.cpr.AtmosphereResourceImpl;
import org.atmosphere.handler.AbstractReflectorAtmosphereHandler;
import com.vaadin.server.ErrorEvent;
@@ -45,6 +46,7 @@ import com.vaadin.server.VaadinSession;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.communication.PushMode;
import com.vaadin.ui.UI;
+
import elemental.json.JsonException;
/**
@@ -472,6 +474,15 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter {
*/
private static void sendRefreshAndDisconnect(AtmosphereResource resource)
throws IOException {
+ if (resource instanceof AtmosphereResourceImpl
+ && !((AtmosphereResourceImpl) resource).isInScope()) {
+ // The resource is no longer valid so we should not write
+ // anything to it
+ getLogger()
+ .fine("sendRefreshAndDisconnect called for resource no longer in scope");
+ return;
+ }
+
AtmospherePushConnection connection = new AtmospherePushConnection(null);
connection.connect(resource);
try {
@@ -490,6 +501,14 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter {
AtmosphereResource resource, String notificationJson) {
// TODO Implemented differently from sendRefreshAndDisconnect
try {
+ if (resource instanceof AtmosphereResourceImpl
+ && !((AtmosphereResourceImpl) resource).isInScope()) {
+ // The resource is no longer valid so we should not write
+ // anything to it
+ getLogger()
+ .fine("sendNotificationAndDisconnect called for resource no longer in scope");
+ return;
+ }
resource.getResponse().getWriter().write(notificationJson);
resource.resume();
} catch (Exception e) {