Browse Source

Separate server message handling to its own class (#11733)

Change-Id: Ic4342171ecbdae4b6e6075fa9ed6d4eebe399a87
tags/7.6.0.alpha5
Artur Signell 9 years ago
parent
commit
2e8d06f89b

+ 1
- 1
client/src/com/vaadin/client/ApplicationConfiguration.java View File

* *
* @param c * @param c
*/ */
static void runWhenDependenciesLoaded(Command c) {
public static void runWhenDependenciesLoaded(Command c) {
if (dependenciesLoading == 0) { if (dependenciesLoading == 0) {
c.execute(); c.execute();
} else { } else {

+ 73
- 1445
client/src/com/vaadin/client/ApplicationConnection.java
File diff suppressed because it is too large
View File


+ 2
- 2
client/src/com/vaadin/client/JavaScriptConnectorHelper.java View File

/** /**
* The id of the previous response for which state changes have been * The id of the previous response for which state changes have been
* processed. If this is the same as the * processed. If this is the same as the
* {@link ApplicationConnection#getLastResponseId()}, it means that the
* {@link ApplicationConnection#getLastSeenServerSyncId()}, it means that the
* state change has already been handled and should not be done again. * state change has already been handled and should not be done again.
*/ */
private int processedResponseId = -1; private int processedResponseId = -1;
} }


private void processStateChanges() { private void processStateChanges() {
int lastResponseId = connector.getConnection().getLastResponseId();
int lastResponseId = connector.getConnection().getLastSeenServerSyncId();
if (processedResponseId == lastResponseId) { if (processedResponseId == lastResponseId) {
return; return;
} }

+ 2
- 2
client/src/com/vaadin/client/LayoutManager.java View File

"Can't start a new layout phase before the previous layout phase ends."); "Can't start a new layout phase before the previous layout phase ends.");
} }


if (connection.isUpdatingState()) {
if (connection.getServerMessageHandler().isUpdatingState()) {
// If assertions are enabled, throw an exception // If assertions are enabled, throw an exception
assert false : STATE_CHANGE_MESSAGE; assert false : STATE_CHANGE_MESSAGE;


/** /**
* Clean measured sizes which are no longer needed. Only for IE8. * Clean measured sizes which are no longer needed. Only for IE8.
*/ */
protected void cleanMeasuredSizes() {
public void cleanMeasuredSizes() {
} }


private static Logger getLogger() { private static Logger getLogger() {

+ 1
- 1
client/src/com/vaadin/client/LayoutManagerIE8.java View File

} }


@Override @Override
protected void cleanMeasuredSizes() {
public void cleanMeasuredSizes() {
Profiler.enter("LayoutManager.cleanMeasuredSizes"); Profiler.enter("LayoutManager.cleanMeasuredSizes");


// #12688: IE8 was leaking memory when adding&removing components. // #12688: IE8 was leaking memory when adding&removing components.

+ 2
- 2
client/src/com/vaadin/client/ValueMap.java View File

return this[name]; return this[name];
}-*/; }-*/;


native String getAsString(String name)
public native String getAsString(String name)
/*-{ /*-{
return '' + this[name]; return '' + this[name];
}-*/; }-*/;


native JavaScriptObject getJavaScriptObject(String name)
public native JavaScriptObject getJavaScriptObject(String name)
/*-{ /*-{
return this[name]; return this[name];
}-*/; }-*/;

+ 3
- 3
client/src/com/vaadin/client/communication/AtmospherePushConnection.java View File

String extraParams = UIConstants.UI_ID_PARAMETER + "=" String extraParams = UIConstants.UI_ID_PARAMETER + "="
+ connection.getConfiguration().getUIId(); + connection.getConfiguration().getUIId();


if (!connection.getCsrfToken().equals(
ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE)) {
String csrfToken = connection.getServerMessageHandler().getCsrfToken();
if (!csrfToken.equals(ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE)) {
extraParams += "&" + ApplicationConstants.CSRF_TOKEN_PARAMETER extraParams += "&" + ApplicationConstants.CSRF_TOKEN_PARAMETER
+ "=" + connection.getCsrfToken();
+ "=" + csrfToken;
} }


// uri is needed to identify the right connection when closing // uri is needed to identify the right connection when closing

+ 1542
- 0
client/src/com/vaadin/client/communication/ServerMessageHandler.java
File diff suppressed because it is too large
View File


+ 2
- 2
client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java View File

/** /**
* The id of the previous response for which state changes have been * The id of the previous response for which state changes have been
* processed. If this is the same as the * processed. If this is the same as the
* {@link ApplicationConnection#getLastResponseId()}, it means that we can
* {@link ApplicationConnection#getLastSeenServerSyncId()}, it means that we can
* skip some quite expensive calculations because we know that the state * skip some quite expensive calculations because we know that the state
* hasn't changed since the last time the values were calculated. * hasn't changed since the last time the values were calculated.
*/ */
*/ */
private void updateInternalState() { private void updateInternalState() {
// Avoid updating again for the same data // Avoid updating again for the same data
int lastResponseId = getConnection().getLastResponseId();
int lastResponseId = getConnection().getLastSeenServerSyncId();
if (processedResponseId == lastResponseId) { if (processedResponseId == lastResponseId) {
return; return;
} }

+ 11
- 18
uitest/src/com/vaadin/tests/widgetset/client/MockApplicationConnection.java View File

*/ */
package com.vaadin.tests.widgetset.client; package com.vaadin.tests.widgetset.client;


import java.util.Date;
import java.util.logging.Logger;

import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ValueMap;
import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.ApplicationConstants;
import com.vaadin.tests.widgetset.server.csrf.ui.CsrfTokenDisabled; import com.vaadin.tests.widgetset.server.csrf.ui.CsrfTokenDisabled;


*/ */
public class MockApplicationConnection extends ApplicationConnection { public class MockApplicationConnection extends ApplicationConnection {


private static final Logger LOGGER = Logger
.getLogger(MockApplicationConnection.class.getName());
// The last token received from the server.
private String lastCsrfTokenReceiver;
public MockApplicationConnection() {
super();
serverMessageHandler = new MockServerMessageHandler();
serverMessageHandler.setConnection(this);
}


// The last token sent to the server. // The last token sent to the server.
private String lastCsrfTokenSent; private String lastCsrfTokenSent;


@Override
public MockServerMessageHandler getServerMessageHandler() {
return (MockServerMessageHandler) super.getServerMessageHandler();
}

/** /**
* Provide the last token received from the server. <br/> * Provide the last token received from the server. <br/>
* We added this to test the change done on CSRF token. * We added this to test the change done on CSRF token.
* @see CsrfTokenDisabled * @see CsrfTokenDisabled
*/ */
public String getLastCsrfTokenReceiver() { public String getLastCsrfTokenReceiver() {
return lastCsrfTokenReceiver;
return getServerMessageHandler().lastCsrfTokenReceiver;
} }


/** /**
return lastCsrfTokenSent; return lastCsrfTokenSent;
} }


@Override
protected void handleUIDLMessage(Date start, String jsonText, ValueMap json) {
lastCsrfTokenReceiver = json
.getString(ApplicationConstants.UIDL_SECURITY_TOKEN_ID);

super.handleUIDLMessage(start, jsonText, json);
}

@Override @Override
public void doUidlRequest(String uri, JsonObject payload, boolean retry) { public void doUidlRequest(String uri, JsonObject payload, boolean retry) {
JsonValue jsonValue = payload.get(ApplicationConstants.CSRF_TOKEN); JsonValue jsonValue = payload.get(ApplicationConstants.CSRF_TOKEN);

+ 37
- 0
uitest/src/com/vaadin/tests/widgetset/client/MockServerMessageHandler.java View File

/*
* Copyright 2000-2014 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.widgetset.client;

import java.util.Date;

import com.vaadin.client.ValueMap;
import com.vaadin.client.communication.ServerMessageHandler;
import com.vaadin.shared.ApplicationConstants;

public class MockServerMessageHandler extends ServerMessageHandler {

// The last token received from the server.
protected String lastCsrfTokenReceiver;

@Override
public void handleUIDLMessage(Date start, String jsonText, ValueMap json) {
lastCsrfTokenReceiver = json
.getString(ApplicationConstants.UIDL_SECURITY_TOKEN_ID);

super.handleUIDLMessage(start, jsonText, json);
}

}

+ 2
- 2
uitest/src/com/vaadin/tests/widgetset/client/csrf/CsrfButtonConnector.java View File

} }


private String csrfTokenInfo() { private String csrfTokenInfo() {
return getMockConnection().getCsrfToken() + ", "
+ getMockConnection().getLastCsrfTokenReceiver() + ", "
return getMockConnection().getServerMessageHandler().getCsrfToken()
+ ", " + getMockConnection().getLastCsrfTokenReceiver() + ", "
+ getMockConnection().getLastCsrfTokenSent(); + getMockConnection().getLastCsrfTokenSent();
} }



Loading…
Cancel
Save