]> source.dussan.org Git - vaadin-framework.git/commitdiff
Send communication error if UI with given id is not found (#11485)
authorArtur Signell <artur@vaadin.com>
Fri, 26 Apr 2013 12:53:13 +0000 (15:53 +0300)
committerArtur Signell <artur@vaadin.com>
Fri, 26 Apr 2013 12:56:22 +0000 (15:56 +0300)
Change-Id: I83da8e1732296b6549a56de62b8c09660e39a8ec

server/src/com/vaadin/server/communication/PushHandler.java
server/src/com/vaadin/server/communication/UidlRequestHandler.java

index 0b3401ec1d398afad373e132722373b8503deb32..1277fe88c52749bc9a4e3f35f8f52a1191048f0a 100644 (file)
@@ -258,9 +258,14 @@ public class PushHandler implements AtmosphereHandler {
                 // Sets UI.currentInstance
                 final UI ui = service.findUI(vaadinRequest);
                 if (ui == null) {
-                    // This should not happen
-                    getLogger().warning(
-                            "Could not find the requested UI in session");
+                    // This a request through an already open push connection to
+                    // a UI which no longer exists.
+                    resource.getResponse()
+                            .getWriter()
+                            .write(UidlRequestHandler.getUINotFoundErrorJSON(
+                                    service, vaadinRequest));
+                    // End the connection
+                    resource.resume();
                     return;
                 }
 
index 053426f90ef5fca3004b0cb708c27268c49c0e00..04ff5f9e87c7fdf6e31a5ca0db1352dbcb12b9aa 100644 (file)
@@ -71,8 +71,10 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements
         }
         UI uI = session.getService().findUI(request);
         if (uI == null) {
-            // This should not happen
-            getLogger().warning("Could not find the requested UI in session");
+            // This should not happen but it will if the UI has been closed. We
+            // really don't want to see it in the server logs though
+            response.getWriter().write(
+                    getUINotFoundErrorJSON(session.getService(), request));
             return true;
         }
 
@@ -284,4 +286,31 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements
 
         return true;
     }
+
+    /**
+     * Returns the JSON which should be returned to the client when a request
+     * for a non-existent UI arrives.
+     * 
+     * @param service
+     *            The VaadinService
+     * @param vaadinRequest
+     *            The request which triggered this, or null if not available
+     * @since 7.1
+     * @return A JSON string
+     */
+    static String getUINotFoundErrorJSON(VaadinService service,
+            VaadinRequest vaadinRequest) {
+        SystemMessages ci = service.getSystemMessages(
+                vaadinRequest.getLocale(), vaadinRequest);
+        // Session Expired is not really the correct message as the
+        // session exists but the requested UI does not.
+        // Using Communication Error for now.
+        String json = VaadinService.createCriticalNotificationJSON(
+                ci.getCommunicationErrorCaption(),
+                ci.getCommunicationErrorMessage(), null,
+                ci.getCommunicationErrorURL());
+
+        return json;
+    }
+
 }