ServerMessageHandler -> MessageHandler ServerCommunicationHandler -> MessageSender State -> ApplicationState CommunicationProblemHandler -> ConnectionStateHandler CommunicationProblemEvent -> XhrConnectionError Change-Id: I2eccfea9cf6a275eba02ac605b6a172e496bd004tags/7.6.0.alpha5
@@ -42,14 +42,15 @@ import com.google.gwt.user.client.Timer; | |||
import com.google.gwt.user.client.ui.HasWidgets; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.client.ApplicationConfiguration.ErrorMessage; | |||
import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; | |||
import com.vaadin.client.ResourceLoader.ResourceLoadEvent; | |||
import com.vaadin.client.ResourceLoader.ResourceLoadListener; | |||
import com.vaadin.client.communication.CommunicationProblemHandler; | |||
import com.vaadin.client.communication.ConnectionStateHandler; | |||
import com.vaadin.client.communication.DefaultConnectionStateHandler; | |||
import com.vaadin.client.communication.Heartbeat; | |||
import com.vaadin.client.communication.ReconnectingCommunicationProblemHandler; | |||
import com.vaadin.client.communication.MessageHandler; | |||
import com.vaadin.client.communication.MessageSender; | |||
import com.vaadin.client.communication.RpcManager; | |||
import com.vaadin.client.communication.ServerCommunicationHandler; | |||
import com.vaadin.client.communication.ServerMessageHandler; | |||
import com.vaadin.client.communication.ServerRpcQueue; | |||
import com.vaadin.client.componentlocator.ComponentLocator; | |||
import com.vaadin.client.metadata.ConnectorBundleLoader; | |||
@@ -139,11 +140,11 @@ public class ApplicationConnection implements HasHandlers { | |||
/** Event bus for communication events */ | |||
private EventBus eventBus = GWT.create(SimpleEventBus.class); | |||
public enum State { | |||
public enum ApplicationState { | |||
INITIALIZING, RUNNING, TERMINATED; | |||
} | |||
private State state = State.INITIALIZING; | |||
private ApplicationState applicationState = ApplicationState.INITIALIZING; | |||
/** | |||
* The communication handler methods are called at certain points during | |||
@@ -364,14 +365,13 @@ public class ApplicationConnection implements HasHandlers { | |||
loadingIndicator.setConnection(this); | |||
serverRpcQueue = GWT.create(ServerRpcQueue.class); | |||
serverRpcQueue.setConnection(this); | |||
communicationProblemHandler = GWT | |||
.create(ReconnectingCommunicationProblemHandler.class); | |||
communicationProblemHandler.setConnection(this); | |||
serverMessageHandler = GWT.create(ServerMessageHandler.class); | |||
serverMessageHandler.setConnection(this); | |||
serverCommunicationHandler = GWT | |||
.create(ServerCommunicationHandler.class); | |||
serverCommunicationHandler.setConnection(this); | |||
connectionStateHandler = GWT | |||
.create(DefaultConnectionStateHandler.class); | |||
connectionStateHandler.setConnection(this); | |||
messageHandler = GWT.create(MessageHandler.class); | |||
messageHandler.setConnection(this); | |||
messageSender = GWT.create(MessageSender.class); | |||
messageSender.setConnection(this); | |||
} | |||
public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) { | |||
@@ -433,14 +433,14 @@ public class ApplicationConnection implements HasHandlers { | |||
String jsonText = configuration.getUIDL(); | |||
if (jsonText == null) { | |||
// initial UIDL not in DOM, request from server | |||
getServerCommunicationHandler().resynchronize(); | |||
getMessageSender().resynchronize(); | |||
} else { | |||
// initial UIDL provided in DOM, continue as if returned by request | |||
// Hack to avoid logging an error in endRequest() | |||
getServerCommunicationHandler().startRequest(); | |||
getServerMessageHandler().handleMessage( | |||
ServerMessageHandler.parseJson(jsonText)); | |||
getMessageSender().startRequest(); | |||
getMessageHandler().handleMessage( | |||
MessageHandler.parseJson(jsonText)); | |||
} | |||
// Tooltip can't be created earlier because the | |||
@@ -463,9 +463,8 @@ public class ApplicationConnection implements HasHandlers { | |||
* @return true if the client has some work to be done, false otherwise | |||
*/ | |||
private boolean isActive() { | |||
return !getServerMessageHandler().isInitialUidlHandled() | |||
|| isWorkPending() | |||
|| getServerCommunicationHandler().hasActiveRequest() | |||
return !getMessageHandler().isInitialUidlHandled() || isWorkPending() | |||
|| getMessageSender().hasActiveRequest() | |||
|| isExecutingDeferredCommands(); | |||
} | |||
@@ -485,13 +484,13 @@ public class ApplicationConnection implements HasHandlers { | |||
} | |||
client.getProfilingData = $entry(function() { | |||
var smh = ap.@com.vaadin.client.ApplicationConnection::getServerMessageHandler(); | |||
var smh = ap.@com.vaadin.client.ApplicationConnection::getMessageHandler(); | |||
var pd = [ | |||
smh.@com.vaadin.client.communication.ServerMessageHandler::lastProcessingTime, | |||
smh.@com.vaadin.client.communication.ServerMessageHandler::totalProcessingTime | |||
smh.@com.vaadin.client.communication.MessageHandler::lastProcessingTime, | |||
smh.@com.vaadin.client.communication.MessageHandler::totalProcessingTime | |||
]; | |||
pd = pd.concat(smh.@com.vaadin.client.communication.ServerMessageHandler::serverTimingInfo); | |||
pd[pd.length] = smh.@com.vaadin.client.communication.ServerMessageHandler::bootstrapTime; | |||
pd = pd.concat(smh.@com.vaadin.client.communication.MessageHandler::serverTimingInfo); | |||
pd[pd.length] = smh.@com.vaadin.client.communication.MessageHandler::bootstrapTime; | |||
return pd; | |||
}); | |||
@@ -598,9 +597,9 @@ public class ApplicationConnection implements HasHandlers { | |||
int cssWaits = 0; | |||
protected ServerRpcQueue serverRpcQueue; | |||
protected CommunicationProblemHandler communicationProblemHandler; | |||
protected ServerMessageHandler serverMessageHandler; | |||
protected ServerCommunicationHandler serverCommunicationHandler; | |||
protected ConnectionStateHandler connectionStateHandler; | |||
protected MessageHandler messageHandler; | |||
protected MessageSender messageSender; | |||
static final int MAX_CSS_WAITS = 100; | |||
@@ -1475,7 +1474,7 @@ public class ApplicationConnection implements HasHandlers { | |||
} | |||
public void setApplicationRunning(boolean applicationRunning) { | |||
if (getState() == State.TERMINATED) { | |||
if (getApplicationState() == ApplicationState.TERMINATED) { | |||
if (applicationRunning) { | |||
getLogger() | |||
.severe("Tried to restart a terminated application. This is not supported"); | |||
@@ -1485,17 +1484,17 @@ public class ApplicationConnection implements HasHandlers { | |||
"Tried to stop a terminated application. This should not be done"); | |||
} | |||
return; | |||
} else if (getState() == State.INITIALIZING) { | |||
} else if (getApplicationState() == ApplicationState.INITIALIZING) { | |||
if (applicationRunning) { | |||
state = State.RUNNING; | |||
applicationState = ApplicationState.RUNNING; | |||
} else { | |||
getLogger() | |||
.warning( | |||
"Tried to stop the application before it has started. This should not be done"); | |||
} | |||
} else if (getState() == State.RUNNING) { | |||
} else if (getApplicationState() == ApplicationState.RUNNING) { | |||
if (!applicationRunning) { | |||
state = State.TERMINATED; | |||
applicationState = ApplicationState.TERMINATED; | |||
eventBus.fireEvent(new ApplicationStoppedEvent()); | |||
} else { | |||
getLogger() | |||
@@ -1506,13 +1505,14 @@ public class ApplicationConnection implements HasHandlers { | |||
} | |||
/** | |||
* Checks if the application is in the {@link State#RUNNING} state. | |||
* Checks if the application is in the {@link ApplicationState#RUNNING} | |||
* state. | |||
* | |||
* @since | |||
* @return true if the application is in the running state, false otherwise | |||
*/ | |||
public boolean isApplicationRunning() { | |||
return state == State.RUNNING; | |||
return applicationState == ApplicationState.RUNNING; | |||
} | |||
public <H extends EventHandler> HandlerRegistration addHandler( | |||
@@ -1568,11 +1568,11 @@ public class ApplicationConnection implements HasHandlers { | |||
* application to go back to a previous state, i.e. a stopped application | |||
* can never be re-started | |||
* | |||
* @since | |||
* @since 7.6 | |||
* @return the current state of this application | |||
*/ | |||
public State getState() { | |||
return state; | |||
public ApplicationState getApplicationState() { | |||
return applicationState; | |||
} | |||
/** | |||
@@ -1589,17 +1589,17 @@ public class ApplicationConnection implements HasHandlers { | |||
* | |||
* @return the server RPC queue | |||
*/ | |||
public CommunicationProblemHandler getCommunicationProblemHandler() { | |||
return communicationProblemHandler; | |||
public ConnectionStateHandler getConnectionStateHandler() { | |||
return connectionStateHandler; | |||
} | |||
/** | |||
* Gets the server message handler for this application | |||
* Gets the (server to client) message handler for this application | |||
* | |||
* @return the server message handler | |||
* @return the message handler | |||
*/ | |||
public ServerMessageHandler getServerMessageHandler() { | |||
return serverMessageHandler; | |||
public MessageHandler getMessageHandler() { | |||
return messageHandler; | |||
} | |||
/** | |||
@@ -1612,12 +1612,12 @@ public class ApplicationConnection implements HasHandlers { | |||
} | |||
/** | |||
* Gets the server communication handler for this application | |||
* Gets the (client to server) message sender for this application | |||
* | |||
* @return the server communication handler | |||
* @return the message sender | |||
*/ | |||
public ServerCommunicationHandler getServerCommunicationHandler() { | |||
return serverCommunicationHandler; | |||
public MessageSender getMessageSender() { | |||
return messageSender; | |||
} | |||
/** | |||
@@ -1628,7 +1628,7 @@ public class ApplicationConnection implements HasHandlers { | |||
} | |||
public int getLastSeenServerSyncId() { | |||
return getServerMessageHandler().getLastSeenServerSyncId(); | |||
return getMessageHandler().getLastSeenServerSyncId(); | |||
} | |||
} |
@@ -70,6 +70,13 @@ public class LayoutManager { | |||
}; | |||
private boolean everythingNeedsMeasure = false; | |||
/** | |||
* Sets the application connection this instance is connected to. Called | |||
* internally by the framework. | |||
* | |||
* @param connection | |||
* the application connection this instance is connected to | |||
*/ | |||
public void setConnection(ApplicationConnection connection) { | |||
if (this.connection != null) { | |||
throw new RuntimeException( | |||
@@ -252,7 +259,7 @@ public class LayoutManager { | |||
"Can't start a new layout phase before the previous layout phase ends."); | |||
} | |||
if (connection.getServerMessageHandler().isUpdatingState()) { | |||
if (connection.getMessageHandler().isUpdatingState()) { | |||
// If assertions are enabled, throw an exception | |||
assert false : STATE_CHANGE_MESSAGE; | |||
@@ -194,7 +194,7 @@ public class AtmospherePushConnection implements PushConnection { | |||
String extraParams = UIConstants.UI_ID_PARAMETER + "=" | |||
+ connection.getConfiguration().getUIId(); | |||
String csrfToken = connection.getServerMessageHandler().getCsrfToken(); | |||
String csrfToken = connection.getMessageHandler().getCsrfToken(); | |||
if (!csrfToken.equals(ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE)) { | |||
extraParams += "&" + ApplicationConstants.CSRF_TOKEN_PARAMETER | |||
+ "=" + csrfToken; | |||
@@ -270,7 +270,7 @@ public class AtmospherePushConnection implements PushConnection { | |||
} | |||
if (state == State.CONNECT_PENDING) { | |||
getCommunicationProblemHandler().pushNotConnected(message); | |||
getConnectionStateHandler().pushNotConnected(message); | |||
return; | |||
} | |||
@@ -307,7 +307,7 @@ public class AtmospherePushConnection implements PushConnection { | |||
switch (state) { | |||
case CONNECT_PENDING: | |||
state = State.CONNECTED; | |||
getCommunicationProblemHandler().pushOk(this); | |||
getConnectionStateHandler().pushOk(this); | |||
break; | |||
case DISCONNECT_PENDING: | |||
// Set state to connected to make disconnect close the connection | |||
@@ -355,16 +355,16 @@ public class AtmospherePushConnection implements PushConnection { | |||
protected void onMessage(AtmosphereResponse response) { | |||
String message = response.getResponseBody(); | |||
ValueMap json = ServerMessageHandler.parseWrappedJson(message); | |||
ValueMap json = MessageHandler.parseWrappedJson(message); | |||
if (json == null) { | |||
// Invalid string (not wrapped as expected) | |||
getCommunicationProblemHandler().pushInvalidContent(this, message); | |||
getConnectionStateHandler().pushInvalidContent(this, message); | |||
return; | |||
} else { | |||
getLogger().info( | |||
"Received push (" + getTransportType() + ") message: " | |||
+ message); | |||
connection.getServerMessageHandler().handleMessage(json); | |||
connection.getMessageHandler().handleMessage(json); | |||
} | |||
} | |||
@@ -386,17 +386,17 @@ public class AtmospherePushConnection implements PushConnection { | |||
*/ | |||
protected void onError(AtmosphereResponse response) { | |||
state = State.DISCONNECTED; | |||
getCommunicationProblemHandler().pushError(this); | |||
getConnectionStateHandler().pushError(this); | |||
} | |||
protected void onClose(AtmosphereResponse response) { | |||
state = State.CONNECT_PENDING; | |||
getCommunicationProblemHandler().pushClosed(this); | |||
getConnectionStateHandler().pushClosed(this); | |||
} | |||
protected void onClientTimeout(AtmosphereResponse response) { | |||
state = State.DISCONNECTED; | |||
getCommunicationProblemHandler().pushClientTimeout(this); | |||
getConnectionStateHandler().pushClientTimeout(this); | |||
} | |||
protected void onReconnect(JavaScriptObject request, | |||
@@ -404,7 +404,7 @@ public class AtmospherePushConnection implements PushConnection { | |||
if (state == State.CONNECTED) { | |||
state = State.CONNECT_PENDING; | |||
} | |||
getCommunicationProblemHandler().pushReconnectPending(this); | |||
getConnectionStateHandler().pushReconnectPending(this); | |||
} | |||
public static abstract class AbstractJSO extends JavaScriptObject { | |||
@@ -575,7 +575,7 @@ public class AtmospherePushConnection implements PushConnection { | |||
@Override | |||
public void onError(ResourceLoadEvent event) { | |||
getCommunicationProblemHandler() | |||
getConnectionStateHandler() | |||
.pushScriptLoadError(event.getResourceUrl()); | |||
} | |||
}); | |||
@@ -603,8 +603,8 @@ public class AtmospherePushConnection implements PushConnection { | |||
return Logger.getLogger(AtmospherePushConnection.class.getName()); | |||
} | |||
private CommunicationProblemHandler getCommunicationProblemHandler() { | |||
return connection.getCommunicationProblemHandler(); | |||
private ConnectionStateHandler getConnectionStateHandler() { | |||
return connection.getConnectionStateHandler(); | |||
} | |||
} |
@@ -22,24 +22,24 @@ import com.vaadin.client.ApplicationConnection; | |||
import elemental.json.JsonObject; | |||
/** | |||
* Interface for handling problems which occur during communication with the | |||
* server. | |||
* Interface for handling problems and other events which occur during | |||
* communication with the server. | |||
* | |||
* The handler is responsible for handling any problem in XHR, heartbeat and | |||
* push connections in a way it sees fit. The default implementation is | |||
* {@link ReconnectingCommunicationProblemHandler}. | |||
* {@link DefaultConnectionStateHandler}. | |||
* | |||
* @since 7.6 | |||
* @author Vaadin Ltd | |||
*/ | |||
public interface CommunicationProblemHandler { | |||
public interface ConnectionStateHandler { | |||
/** | |||
* Sets the application connection this handler is connected to. Called | |||
* Sets the application connection this instance is connected to. Called | |||
* internally by the framework. | |||
* | |||
* @param connection | |||
* the application connection this handler is connected to | |||
* the application connection this instance is connected to | |||
*/ | |||
void setConnection(ApplicationConnection connection); | |||
@@ -134,11 +134,11 @@ public interface CommunicationProblemHandler { | |||
* Called when an exception occurs during an XmlHttpRequest request to the | |||
* server. | |||
* | |||
* @param communicationProblemEvent | |||
* @param xhrConnectionError | |||
* An event containing what was being sent to the server and what | |||
* exception occurred | |||
*/ | |||
void xhrException(CommunicationProblemEvent communicationProblemEvent); | |||
void xhrException(XhrConnectionError xhrConnectionError); | |||
/** | |||
* Called when invalid content (not JSON) was returned from the server as | |||
@@ -148,7 +148,7 @@ public interface CommunicationProblemHandler { | |||
* An event containing what was being sent to the server and what | |||
* was returned | |||
*/ | |||
void xhrInvalidContent(CommunicationProblemEvent communicationProblemEvent); | |||
void xhrInvalidContent(XhrConnectionError xhrConnectionError); | |||
/** | |||
* Called when invalid status code (not 200) was returned by the server as | |||
@@ -158,7 +158,7 @@ public interface CommunicationProblemHandler { | |||
* An event containing what was being sent to the server and what | |||
* was returned | |||
*/ | |||
void xhrInvalidStatusCode(CommunicationProblemEvent problemEvent); | |||
void xhrInvalidStatusCode(XhrConnectionError xhrConnectionError); | |||
/** | |||
* Called whenever a XmlHttpRequest to the server completes successfully |
@@ -32,7 +32,7 @@ import com.vaadin.shared.ui.ui.UIState.ReconnectDialogConfigurationState; | |||
import elemental.json.JsonObject; | |||
/** | |||
* Default implementation of the communication problem handler. | |||
* Default implementation of the connection state handler. | |||
* <p> | |||
* Handles temporary errors by showing a reconnect dialog to the user while | |||
* trying to re-establish the connection to the server and re-send the pending | |||
@@ -44,8 +44,7 @@ import elemental.json.JsonObject; | |||
* @since 7.6 | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReconnectingCommunicationProblemHandler implements | |||
CommunicationProblemHandler { | |||
public class DefaultConnectionStateHandler implements ConnectionStateHandler { | |||
private ApplicationConnection connection; | |||
private ReconnectDialog reconnectDialog = GWT.create(ReconnectDialog.class); | |||
@@ -120,8 +119,7 @@ public class ReconnectingCommunicationProblemHandler implements | |||
} | |||
private static Logger getLogger() { | |||
return Logger.getLogger(ReconnectingCommunicationProblemHandler.class | |||
.getName()); | |||
return Logger.getLogger(DefaultConnectionStateHandler.class.getName()); | |||
} | |||
/** | |||
@@ -134,9 +132,9 @@ public class ReconnectingCommunicationProblemHandler implements | |||
} | |||
@Override | |||
public void xhrException(CommunicationProblemEvent event) { | |||
public void xhrException(XhrConnectionError xhrConnectionError) { | |||
debug("xhrException"); | |||
handleRecoverableError(Type.XHR, event.getPayload()); | |||
handleRecoverableError(Type.XHR, xhrConnectionError.getPayload()); | |||
} | |||
@Override | |||
@@ -286,7 +284,7 @@ public class ReconnectingCommunicationProblemHandler implements | |||
} | |||
if (payload != null) { | |||
getLogger().info("Re-sending last message to the server..."); | |||
getConnection().getServerCommunicationHandler().send(payload); | |||
getConnection().getMessageSender().send(payload); | |||
} else { | |||
// Use heartbeat | |||
getLogger().info("Trying to re-establish server connection..."); | |||
@@ -400,11 +398,11 @@ public class ReconnectingCommunicationProblemHandler implements | |||
} | |||
@Override | |||
public void xhrInvalidContent(CommunicationProblemEvent event) { | |||
public void xhrInvalidContent(XhrConnectionError xhrConnectionError) { | |||
debug("xhrInvalidContent"); | |||
endRequest(); | |||
String responseText = event.getResponse().getText(); | |||
String responseText = xhrConnectionError.getResponse().getText(); | |||
/* | |||
* A servlet filter or equivalent may have intercepted the request and | |||
* served non-UIDL content (for instance, a login page if the session | |||
@@ -418,7 +416,8 @@ public class ReconnectingCommunicationProblemHandler implements | |||
WidgetUtil.redirect(refreshToken.getGroup(2)); | |||
} else { | |||
handleUnrecoverableCommunicationError( | |||
"Invalid JSON response from server: " + responseText, event); | |||
"Invalid JSON response from server: " + responseText, | |||
xhrConnectionError); | |||
} | |||
} | |||
@@ -441,24 +440,24 @@ public class ReconnectingCommunicationProblemHandler implements | |||
} | |||
@Override | |||
public void xhrInvalidStatusCode(CommunicationProblemEvent event) { | |||
public void xhrInvalidStatusCode(XhrConnectionError xhrConnectionError) { | |||
debug("xhrInvalidStatusCode"); | |||
Response response = event.getResponse(); | |||
Response response = xhrConnectionError.getResponse(); | |||
int statusCode = response.getStatusCode(); | |||
getLogger().warning("Server returned " + statusCode + " for xhr"); | |||
if (statusCode == 401) { | |||
// Authentication/authorization failed, no need to re-try | |||
endRequest(); | |||
handleUnauthorized(event); | |||
handleUnauthorized(xhrConnectionError); | |||
return; | |||
} else { | |||
// 404, 408 and other 4xx codes CAN be temporary when you have a | |||
// proxy between the client and the server and e.g. restart the | |||
// server | |||
// 5xx codes may or may not be temporary | |||
handleRecoverableError(Type.XHR, event.getPayload()); | |||
handleRecoverableError(Type.XHR, xhrConnectionError.getPayload()); | |||
} | |||
} | |||
@@ -466,10 +465,10 @@ public class ReconnectingCommunicationProblemHandler implements | |||
* @since | |||
*/ | |||
private void endRequest() { | |||
getConnection().getServerCommunicationHandler().endRequest(); | |||
getConnection().getMessageSender().endRequest(); | |||
} | |||
protected void handleUnauthorized(CommunicationProblemEvent event) { | |||
protected void handleUnauthorized(XhrConnectionError xhrConnectionError) { | |||
/* | |||
* Authorization has failed (401). Could be that the session has timed | |||
* out. | |||
@@ -485,10 +484,10 @@ public class ReconnectingCommunicationProblemHandler implements | |||
} | |||
private void handleUnrecoverableCommunicationError(String details, | |||
CommunicationProblemEvent event) { | |||
XhrConnectionError xhrConnectionError) { | |||
int statusCode = -1; | |||
if (event != null) { | |||
Response response = event.getResponse(); | |||
if (xhrConnectionError != null) { | |||
Response response = xhrConnectionError.getResponse(); | |||
if (response != null) { | |||
statusCode = response.getStatusCode(); | |||
} |
@@ -96,11 +96,11 @@ public class Heartbeat { | |||
int status = response.getStatusCode(); | |||
if (status == Response.SC_OK) { | |||
connection.getCommunicationProblemHandler().heartbeatOk(); | |||
connection.getConnectionStateHandler().heartbeatOk(); | |||
} else { | |||
// Handler should stop the application if heartbeat should | |||
// no longer be sent | |||
connection.getCommunicationProblemHandler() | |||
connection.getConnectionStateHandler() | |||
.heartbeatInvalidStatusCode(request, response); | |||
} | |||
@@ -111,7 +111,7 @@ public class Heartbeat { | |||
public void onError(Request request, Throwable exception) { | |||
// Handler should stop the application if heartbeat should no | |||
// longer be sent | |||
connection.getCommunicationProblemHandler().heartbeatException( | |||
connection.getConnectionStateHandler().heartbeatException( | |||
request, exception); | |||
schedule(); | |||
} |
@@ -37,9 +37,9 @@ import com.google.gwt.user.client.Timer; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.client.ApplicationConfiguration; | |||
import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.ApplicationConnection.ApplicationState; | |||
import com.vaadin.client.ApplicationConnection.MultiStepDuration; | |||
import com.vaadin.client.ApplicationConnection.ResponseHandlingStartedEvent; | |||
import com.vaadin.client.ApplicationConnection.State; | |||
import com.vaadin.client.ComponentConnector; | |||
import com.vaadin.client.ConnectorHierarchyChangeEvent; | |||
import com.vaadin.client.ConnectorMap; | |||
@@ -76,14 +76,14 @@ import elemental.json.JsonArray; | |||
import elemental.json.JsonObject; | |||
/** | |||
* ServerMessageHandler is responsible for handling all incoming messages (JSON) | |||
* A MessageHandler is responsible for handling all incoming messages (JSON) | |||
* from the server (state changes, RPCs and other updates) and ensuring that the | |||
* connectors are updated accordingly. | |||
* | |||
* @since 7.6 | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ServerMessageHandler { | |||
public class MessageHandler { | |||
public static final String JSON_COMMUNICATION_PREFIX = "for(;;);["; | |||
public static final String JSON_COMMUNICATION_SUFFIX = "]"; | |||
@@ -205,17 +205,18 @@ public class ServerMessageHandler { | |||
} | |||
/** | |||
* Sets the application connection this queue is connected to | |||
* Sets the application connection this instance is connected to. Called | |||
* internally by the framework. | |||
* | |||
* @param connection | |||
* the application connection this queue is connected to | |||
* the application connection this instance is connected to | |||
*/ | |||
public void setConnection(ApplicationConnection connection) { | |||
this.connection = connection; | |||
} | |||
private static Logger getLogger() { | |||
return Logger.getLogger(ServerMessageHandler.class.getName()); | |||
return Logger.getLogger(MessageHandler.class.getName()); | |||
} | |||
/** | |||
@@ -236,9 +237,9 @@ public class ServerMessageHandler { | |||
+ "Please verify that the server is up-to-date and that the response data has not been modified in transmission."); | |||
} | |||
if (connection.getState() == State.RUNNING) { | |||
if (connection.getApplicationState() == ApplicationState.RUNNING) { | |||
handleJSON(json); | |||
} else if (connection.getState() == State.INITIALIZING) { | |||
} else if (connection.getApplicationState() == ApplicationState.INITIALIZING) { | |||
// Application is starting up for the first time | |||
connection.setApplicationRunning(true); | |||
connection.executeWhenCSSLoaded(new Command() { | |||
@@ -325,8 +326,8 @@ public class ServerMessageHandler { | |||
if (json.containsKey(ApplicationConstants.CLIENT_TO_SERVER_ID)) { | |||
int serverNextExpected = json | |||
.getInt(ApplicationConstants.CLIENT_TO_SERVER_ID); | |||
getServerCommunicationHandler().setClientToServerMessageId( | |||
serverNextExpected, isResynchronize(json)); | |||
getMessageSender().setClientToServerMessageId(serverNextExpected, | |||
isResynchronize(json)); | |||
} | |||
if (serverId != -1) { | |||
@@ -1440,7 +1441,7 @@ public class ServerMessageHandler { | |||
if (isResponse(json)) { | |||
// End the request if the received message was a | |||
// response, not sent asynchronously | |||
getServerCommunicationHandler().endRequest(); | |||
getMessageSender().endRequest(); | |||
} | |||
} | |||
@@ -1516,7 +1517,7 @@ public class ServerMessageHandler { | |||
// has been lost | |||
// Drop pending messages and resynchronize | |||
pendingUIDLMessages.clear(); | |||
getServerCommunicationHandler().resynchronize(); | |||
getMessageSender().resynchronize(); | |||
} | |||
} | |||
}; | |||
@@ -1673,8 +1674,8 @@ public class ServerMessageHandler { | |||
return connection.getRpcManager(); | |||
} | |||
private ServerCommunicationHandler getServerCommunicationHandler() { | |||
return connection.getServerCommunicationHandler(); | |||
private MessageSender getMessageSender() { | |||
return connection.getMessageSender(); | |||
} | |||
/** |
@@ -35,15 +35,15 @@ import elemental.json.JsonArray; | |||
import elemental.json.JsonObject; | |||
/** | |||
* ServerCommunicationHandler is responsible for sending messages to the server. | |||
* | |||
* Internally either XHR or push is used for communicating, depending on the | |||
* application configuration. | |||
* MessageSender is responsible for sending messages to the server. | |||
* <p> | |||
* Internally uses {@link XhrConnection} and/or {@link PushConnection} for | |||
* delivering messages, depending on the application configuration. | |||
* | |||
* @since 7.6 | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ServerCommunicationHandler { | |||
public class MessageSender { | |||
private ApplicationConnection connection; | |||
private boolean hasActiveRequest = false; | |||
@@ -55,15 +55,16 @@ public class ServerCommunicationHandler { | |||
private XhrConnection xhrConnection; | |||
private PushConnection push; | |||
public ServerCommunicationHandler() { | |||
public MessageSender() { | |||
xhrConnection = GWT.create(XhrConnection.class); | |||
} | |||
/** | |||
* Sets the application connection this handler is connected to | |||
* Sets the application connection this instance is connected to. Called | |||
* internally by the framework. | |||
* | |||
* @param connection | |||
* the application connection this handler is connected to | |||
* the application connection this instance is connected to | |||
*/ | |||
public void setConnection(ApplicationConnection connection) { | |||
this.connection = connection; | |||
@@ -71,7 +72,7 @@ public class ServerCommunicationHandler { | |||
} | |||
private static Logger getLogger() { | |||
return Logger.getLogger(ServerCommunicationHandler.class.getName()); | |||
return Logger.getLogger(MessageSender.class.getName()); | |||
} | |||
public void sendInvocationsToServer() { | |||
@@ -148,13 +149,13 @@ public class ServerCommunicationHandler { | |||
startRequest(); | |||
JsonObject payload = Json.createObject(); | |||
String csrfToken = getServerMessageHandler().getCsrfToken(); | |||
String csrfToken = getMessageHandler().getCsrfToken(); | |||
if (!csrfToken.equals(ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE)) { | |||
payload.put(ApplicationConstants.CSRF_TOKEN, csrfToken); | |||
} | |||
payload.put(ApplicationConstants.RPC_INVOCATIONS, reqInvocations); | |||
payload.put(ApplicationConstants.SERVER_SYNC_ID, | |||
getServerMessageHandler().getLastSeenServerSyncId()); | |||
payload.put(ApplicationConstants.SERVER_SYNC_ID, getMessageHandler() | |||
.getLastSeenServerSyncId()); | |||
payload.put(ApplicationConstants.CLIENT_TO_SERVER_ID, | |||
clientToServerMessageId++); | |||
@@ -341,12 +342,12 @@ public class ServerCommunicationHandler { | |||
+ "server to client: " + serverToClient; | |||
} | |||
private CommunicationProblemHandler getCommunicationProblemHandler() { | |||
return connection.getCommunicationProblemHandler(); | |||
private ConnectionStateHandler getConnectionStateHandler() { | |||
return connection.getConnectionStateHandler(); | |||
} | |||
private ServerMessageHandler getServerMessageHandler() { | |||
return connection.getServerMessageHandler(); | |||
private MessageHandler getMessageHandler() { | |||
return connection.getMessageHandler(); | |||
} | |||
private VLoadingIndicator getLoadingIndicator() { |
@@ -49,7 +49,7 @@ public interface PushConnection { | |||
* <p> | |||
* Implementation detail: If the push connection is not connected and the | |||
* message can thus not be sent, the implementation must call | |||
* {@link CommunicationProblemHandler#pushNotConnected(JsonObject)}, which | |||
* {@link ConnectionStateHandler#pushNotConnected(JsonObject)}, which | |||
* will retry the send later. | |||
* <p> | |||
* This method must not be called if the push connection is not |
@@ -67,10 +67,11 @@ public class ServerRpcQueue { | |||
} | |||
/** | |||
* Sets the application connection this queue is connected to | |||
* Sets the application connection this instance is connected to. Called | |||
* internally by the framework. | |||
* | |||
* @param connection | |||
* the application connection this queue is connected to | |||
* the application connection this instance is connected to | |||
*/ | |||
public void setConnection(ApplicationConnection connection) { | |||
this.connection = connection; | |||
@@ -203,8 +204,7 @@ public class ServerRpcQueue { | |||
// Somebody else cleared the queue before we had the chance | |||
return; | |||
} | |||
connection.getServerCommunicationHandler() | |||
.sendInvocationsToServer(); | |||
connection.getMessageSender().sendInvocationsToServer(); | |||
} | |||
}; | |||
@@ -30,8 +30,11 @@ public class TranslatedURLReference extends URLReference { | |||
private ApplicationConnection connection; | |||
/** | |||
* Sets the application connection this instance is connected to. Called | |||
* internally by the framework. | |||
* | |||
* @param connection | |||
* the connection to set | |||
* the application connection this instance is connected to | |||
*/ | |||
public void setConnection(ApplicationConnection connection) { | |||
this.connection = connection; |
@@ -71,10 +71,11 @@ public class XhrConnection { | |||
} | |||
/** | |||
* Sets the application connection this queue is connected to | |||
* Sets the application connection this instance is connected to. Called | |||
* internally by the framework. | |||
* | |||
* @param connection | |||
* the application connection this queue is connected to | |||
* the application connection this instance is connected to | |||
*/ | |||
public void setConnection(ApplicationConnection connection) { | |||
this.connection = connection; | |||
@@ -127,12 +128,8 @@ public class XhrConnection { | |||
@Override | |||
public void onError(Request request, Throwable exception) { | |||
getCommunicationProblemHandler().xhrException( | |||
new CommunicationProblemEvent(request, payload, exception)); | |||
} | |||
private ServerCommunicationHandler getServerCommunicationHandler() { | |||
return connection.getServerCommunicationHandler(); | |||
getConnectionStateHandler().xhrException( | |||
new XhrConnectionError(request, payload, exception)); | |||
} | |||
@Override | |||
@@ -141,11 +138,10 @@ public class XhrConnection { | |||
if (statusCode != 200) { | |||
// There was a problem | |||
CommunicationProblemEvent problemEvent = new CommunicationProblemEvent( | |||
XhrConnectionError problemEvent = new XhrConnectionError( | |||
request, payload, response); | |||
getCommunicationProblemHandler().xhrInvalidStatusCode( | |||
problemEvent); | |||
getConnectionStateHandler().xhrInvalidStatusCode(problemEvent); | |||
return; | |||
} | |||
@@ -157,27 +153,25 @@ public class XhrConnection { | |||
String contentType = response.getHeader("Content-Type"); | |||
if (contentType == null | |||
|| !contentType.startsWith("application/json")) { | |||
getCommunicationProblemHandler().xhrInvalidContent( | |||
new CommunicationProblemEvent(request, payload, | |||
response)); | |||
getConnectionStateHandler().xhrInvalidContent( | |||
new XhrConnectionError(request, payload, response)); | |||
return; | |||
} | |||
// for(;;);["+ realJson +"]" | |||
String responseText = response.getText(); | |||
ValueMap json = ServerMessageHandler.parseWrappedJson(responseText); | |||
ValueMap json = MessageHandler.parseWrappedJson(responseText); | |||
if (json == null) { | |||
// Invalid string (not wrapped as expected or can't parse) | |||
getCommunicationProblemHandler().xhrInvalidContent( | |||
new CommunicationProblemEvent(request, payload, | |||
response)); | |||
getConnectionStateHandler().xhrInvalidContent( | |||
new XhrConnectionError(request, payload, response)); | |||
return; | |||
} | |||
getCommunicationProblemHandler().xhrOk(); | |||
getConnectionStateHandler().xhrOk(); | |||
getLogger().info("Received xhr message: " + responseText); | |||
getServerMessageHandler().handleMessage(json); | |||
getMessageHandler().handleMessage(json); | |||
} | |||
/** | |||
@@ -233,8 +227,8 @@ public class XhrConnection { | |||
}.schedule(retryTimeout); | |||
} | |||
} catch (RequestException e) { | |||
getCommunicationProblemHandler().xhrException( | |||
new CommunicationProblemEvent(null, payload, e)); | |||
getConnectionStateHandler().xhrException( | |||
new XhrConnectionError(null, payload, e)); | |||
} | |||
} | |||
@@ -255,12 +249,12 @@ public class XhrConnection { | |||
} | |||
private CommunicationProblemHandler getCommunicationProblemHandler() { | |||
return connection.getCommunicationProblemHandler(); | |||
private ConnectionStateHandler getConnectionStateHandler() { | |||
return connection.getConnectionStateHandler(); | |||
} | |||
private ServerMessageHandler getServerMessageHandler() { | |||
return connection.getServerMessageHandler(); | |||
private MessageHandler getMessageHandler() { | |||
return connection.getMessageHandler(); | |||
} | |||
private static native boolean resendRequest(Request request) |
@@ -21,13 +21,13 @@ import com.google.gwt.http.client.Response; | |||
import elemental.json.JsonObject; | |||
/** | |||
* Event describing a problem which took place during communication with the | |||
* server | |||
* XhrConnectionError provides detail about an error which occured during an XHR | |||
* request to the server | |||
* | |||
* @since 7.6 | |||
* @author Vaadin Ltd | |||
*/ | |||
public class CommunicationProblemEvent { | |||
public class XhrConnectionError { | |||
private Throwable exception; | |||
private Request request; | |||
@@ -44,7 +44,7 @@ public class CommunicationProblemEvent { | |||
* @param exception | |||
* the exception describing the problem | |||
*/ | |||
public CommunicationProblemEvent(Request request, JsonObject payload, | |||
public XhrConnectionError(Request request, JsonObject payload, | |||
Throwable exception) { | |||
this.request = request; | |||
this.exception = exception; | |||
@@ -61,7 +61,7 @@ public class CommunicationProblemEvent { | |||
* @param response | |||
* the response for the request | |||
*/ | |||
public CommunicationProblemEvent(Request request, JsonObject payload, | |||
public XhrConnectionError(Request request, JsonObject payload, | |||
Response response) { | |||
this.request = request; | |||
this.response = response; |
@@ -166,7 +166,7 @@ public class InfoSection implements Section { | |||
addRow("Theme", connection.getUIConnector().getActiveTheme()); | |||
String communicationMethodInfo = connection | |||
.getServerCommunicationHandler().getCommunicationMethodName(); | |||
.getMessageSender().getCommunicationMethodName(); | |||
int pollInterval = connection.getUIConnector().getState().pollInterval; | |||
if (pollInterval > 0) { | |||
communicationMethodInfo += " (poll interval " + pollInterval |
@@ -2616,7 +2616,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, | |||
@Override | |||
public void run() { | |||
if (client.getServerCommunicationHandler().hasActiveRequest() | |||
if (client.getMessageSender().hasActiveRequest() | |||
|| navKeyDown) { | |||
// if client connection is busy, don't bother loading it more | |||
VConsole.log("Postponed rowfetch"); |
@@ -488,7 +488,7 @@ public class VDragAndDropManager { | |||
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { | |||
@Override | |||
public boolean execute() { | |||
if (!client.getServerCommunicationHandler() | |||
if (!client.getMessageSender() | |||
.hasActiveRequest()) { | |||
removeActiveDragSourceStyleName(dragSource); | |||
return false; |
@@ -748,11 +748,11 @@ public class UIConnector extends AbstractSingleComponentContainerConnector | |||
} | |||
if (stateChangeEvent.hasPropertyChanged("pushConfiguration")) { | |||
getConnection().getServerCommunicationHandler().setPushEnabled( | |||
getConnection().getMessageSender().setPushEnabled( | |||
getState().pushConfiguration.mode.isEnabled()); | |||
} | |||
if (stateChangeEvent.hasPropertyChanged("reconnectDialogConfiguration")) { | |||
getConnection().getCommunicationProblemHandler() | |||
getConnection().getConnectionStateHandler() | |||
.configurationUpdated(); | |||
} | |||
@@ -28,29 +28,27 @@ public class ServerMessageHandlerTest { | |||
@Test | |||
public void unwrapValidJson() { | |||
String payload = "{'foo': 'bar'}"; | |||
Assert.assertEquals( | |||
payload, | |||
ServerMessageHandler.stripJSONWrapping("for(;;);[" + payload | |||
+ "]")); | |||
Assert.assertEquals(payload, | |||
MessageHandler.stripJSONWrapping("for(;;);[" + payload + "]")); | |||
} | |||
@Test | |||
public void unwrapUnwrappedJson() { | |||
String payload = "{'foo': 'bar'}"; | |||
Assert.assertNull(ServerMessageHandler.stripJSONWrapping(payload)); | |||
Assert.assertNull(MessageHandler.stripJSONWrapping(payload)); | |||
} | |||
@Test | |||
public void unwrapNull() { | |||
Assert.assertNull(ServerMessageHandler.stripJSONWrapping(null)); | |||
Assert.assertNull(MessageHandler.stripJSONWrapping(null)); | |||
} | |||
@Test | |||
public void unwrapEmpty() { | |||
Assert.assertNull(ServerMessageHandler.stripJSONWrapping("")); | |||
Assert.assertNull(MessageHandler.stripJSONWrapping("")); | |||
} | |||
} |
@@ -28,21 +28,21 @@ public class MockApplicationConnection extends ApplicationConnection { | |||
public MockApplicationConnection() { | |||
super(); | |||
serverMessageHandler = new MockServerMessageHandler(); | |||
serverMessageHandler.setConnection(this); | |||
serverCommunicationHandler = new MockServerCommunicationHandler(); | |||
serverCommunicationHandler.setConnection(this); | |||
messageHandler = new MockServerMessageHandler(); | |||
messageHandler.setConnection(this); | |||
messageSender = new MockServerCommunicationHandler(); | |||
messageSender.setConnection(this); | |||
} | |||
@Override | |||
public MockServerMessageHandler getServerMessageHandler() { | |||
return (MockServerMessageHandler) super.getServerMessageHandler(); | |||
public MockServerMessageHandler getMessageHandler() { | |||
return (MockServerMessageHandler) super.getMessageHandler(); | |||
} | |||
@Override | |||
public MockServerCommunicationHandler getServerCommunicationHandler() { | |||
public MockServerCommunicationHandler getMessageSender() { | |||
return (MockServerCommunicationHandler) super | |||
.getServerCommunicationHandler(); | |||
.getMessageSender(); | |||
} | |||
/** | |||
@@ -52,7 +52,7 @@ public class MockApplicationConnection extends ApplicationConnection { | |||
* @see CsrfTokenDisabled | |||
*/ | |||
public String getLastCsrfTokenReceiver() { | |||
return getServerMessageHandler().lastCsrfTokenReceiver; | |||
return getMessageHandler().lastCsrfTokenReceiver; | |||
} | |||
/** | |||
@@ -62,7 +62,7 @@ public class MockApplicationConnection extends ApplicationConnection { | |||
* @see CsrfTokenDisabled | |||
*/ | |||
public String getLastCsrfTokenSent() { | |||
return getServerCommunicationHandler().lastCsrfTokenSent; | |||
return getMessageSender().lastCsrfTokenSent; | |||
} | |||
} |
@@ -15,13 +15,13 @@ | |||
*/ | |||
package com.vaadin.tests.widgetset.client; | |||
import com.vaadin.client.communication.ServerCommunicationHandler; | |||
import com.vaadin.client.communication.MessageSender; | |||
import com.vaadin.shared.ApplicationConstants; | |||
import elemental.json.JsonObject; | |||
import elemental.json.JsonValue; | |||
public class MockServerCommunicationHandler extends ServerCommunicationHandler { | |||
public class MockServerCommunicationHandler extends MessageSender { | |||
// The last token sent to the server. | |||
String lastCsrfTokenSent; |
@@ -16,10 +16,10 @@ | |||
package com.vaadin.tests.widgetset.client; | |||
import com.vaadin.client.ValueMap; | |||
import com.vaadin.client.communication.ServerMessageHandler; | |||
import com.vaadin.client.communication.MessageHandler; | |||
import com.vaadin.shared.ApplicationConstants; | |||
public class MockServerMessageHandler extends ServerMessageHandler { | |||
public class MockServerMessageHandler extends MessageHandler { | |||
// The last token received from the server. | |||
protected String lastCsrfTokenReceiver; |
@@ -70,7 +70,7 @@ public class CsrfButtonConnector extends AbstractComponentConnector { | |||
} | |||
private String csrfTokenInfo() { | |||
return getMockConnection().getServerMessageHandler().getCsrfToken() | |||
return getMockConnection().getMessageHandler().getCsrfToken() | |||
+ ", " + getMockConnection().getLastCsrfTokenReceiver() + ", " | |||
+ getMockConnection().getLastCsrfTokenSent(); | |||
} |