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
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;
private String transport;
+ private CommunicationErrorHandler errorHandler;
+
/**
* Keeps track of the disconnect confirmation command for cases where
* pending messages should be pushed before actually disconnecting.
* .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
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);
}
});
}
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
* @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