]> source.dussan.org Git - vaadin-framework.git/commitdiff
Improve error message if vaadinPush.js failed to load (#11673)
authorJohannes Dahlström <johannesd@vaadin.com>
Wed, 22 May 2013 09:09:00 +0000 (12:09 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Wed, 22 May 2013 09:09:00 +0000 (12:09 +0300)
Change-Id: I46a2622585ed69a1db4c6abf4aca4387387a0f97

client/src/com/vaadin/client/ApplicationConnection.java
client/src/com/vaadin/client/communication/AtmospherePushConnection.java
client/src/com/vaadin/client/communication/PushConnection.java

index 4141f9f2dc75ac59b64d00bbc8e88175166ead6b..087ee87262b440eec871fbffa1fd437ea584bc95 100644 (file)
@@ -3404,7 +3404,13 @@ public class ApplicationConnection {
     public void setPushEnabled(boolean enabled) {
         if (enabled && push == null) {
             push = GWT.create(PushConnection.class);
-            push.init(this);
+            push.init(this, new CommunicationErrorHandler() {
+                @Override
+                public boolean onError(String details, int statusCode) {
+                    showCommunicationError(details, statusCode);
+                    return true;
+                }
+            });
         } else if (!enabled && push != null && push.isActive()) {
             push.disconnect(new Command() {
                 @Override
index ce3253ed50cfd489076771b72d5bf1a31e9e8eaa..997e84145c9723fb9534ba0d47467c29c291d9ec 100644 (file)
@@ -22,6 +22,7 @@ import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.user.client.Command;
 import com.vaadin.client.ApplicationConnection;
+import com.vaadin.client.ApplicationConnection.CommunicationErrorHandler;
 import com.vaadin.client.ResourceLoader;
 import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
 import com.vaadin.client.ResourceLoader.ResourceLoadListener;
@@ -117,6 +118,8 @@ public class AtmospherePushConnection implements PushConnection {
 
     private String transport;
 
+    private CommunicationErrorHandler errorHandler;
+
     /**
      * Keeps track of the disconnect confirmation command for cases where
      * pending messages should be pushed before actually disconnecting.
@@ -134,8 +137,10 @@ public class AtmospherePushConnection implements PushConnection {
      * .ApplicationConnection)
      */
     @Override
-    public void init(final ApplicationConnection connection) {
+    public void init(final ApplicationConnection connection,
+            CommunicationErrorHandler errorHandler) {
         this.connection = connection;
+        this.errorHandler = errorHandler;
 
         runWhenAtmosphereLoaded(new Command() {
             @Override
@@ -433,22 +438,30 @@ public class AtmospherePushConnection implements PushConnection {
         if (isAtmosphereLoaded()) {
             command.execute();
         } else {
-            VConsole.log("Loading " + ApplicationConstants.VAADIN_PUSH_JS);
+            final String pushJs = ApplicationConstants.VAADIN_PUSH_JS;
+            VConsole.log("Loading " + pushJs);
             ResourceLoader.get().loadScript(
-                    connection.getConfiguration().getVaadinDirUrl()
-                            + ApplicationConstants.VAADIN_PUSH_JS,
+                    connection.getConfiguration().getVaadinDirUrl() + pushJs,
                     new ResourceLoadListener() {
                         @Override
                         public void onLoad(ResourceLoadEvent event) {
-                            VConsole.log(ApplicationConstants.VAADIN_PUSH_JS
-                                    + " loaded");
-                            command.execute();
+                            if (isAtmosphereLoaded()) {
+                                VConsole.log(pushJs + " loaded");
+                                command.execute();
+                            } else {
+                                // If bootstrap tried to load vaadinPush.js,
+                                // ResourceLoader assumes it succeeded even if
+                                // it failed (#11673)
+                                onError(event);
+                            }
                         }
 
                         @Override
                         public void onError(ResourceLoadEvent event) {
-                            VConsole.error(event.getResourceUrl()
-                                    + " could not be loaded. Push will not work.");
+                            errorHandler.onError(
+                                    event.getResourceUrl()
+                                            + " could not be loaded. Push will not work.",
+                                    0);
                         }
                     });
         }
index 61656242bddc08a60616b2e267e8462b07ecd6fc..a4a3bbc0ccf5c85fda5e098b5ad839e70907c82d 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.client.communication;
 
 import com.google.gwt.user.client.Command;
 import com.vaadin.client.ApplicationConnection;
+import com.vaadin.client.ApplicationConnection.CommunicationErrorHandler;
 
 /**
  * Represents the client-side endpoint of a bidirectional ("push") communication
@@ -37,7 +38,8 @@ public interface PushConnection {
      * @param connection
      *            The ApplicationConnection
      */
-    public void init(ApplicationConnection connection);
+    public void init(ApplicationConnection connection,
+            CommunicationErrorHandler errorHandler);
 
     /**
      * Pushes a message to the server. Will throw an exception if the connection