From: Artur Signell Date: Fri, 26 Apr 2013 12:53:13 +0000 (+0300) Subject: Send communication error if UI with given id is not found (#11485) X-Git-Tag: 7.1.0.beta1~31 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ed97f8bcdd7472710ea8ddd88b74bd88016c510b;p=vaadin-framework.git Send communication error if UI with given id is not found (#11485) Change-Id: I83da8e1732296b6549a56de62b8c09660e39a8ec --- diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java index 0b3401ec1d..1277fe88c5 100644 --- a/server/src/com/vaadin/server/communication/PushHandler.java +++ b/server/src/com/vaadin/server/communication/PushHandler.java @@ -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; } diff --git a/server/src/com/vaadin/server/communication/UidlRequestHandler.java b/server/src/com/vaadin/server/communication/UidlRequestHandler.java index 053426f90e..04ff5f9e87 100644 --- a/server/src/com/vaadin/server/communication/UidlRequestHandler.java +++ b/server/src/com/vaadin/server/communication/UidlRequestHandler.java @@ -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; + } + }