summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-09-28 20:14:48 +0300
committerArtur Signell <artur@vaadin.com>2012-09-28 20:14:52 +0300
commit41f2e9e753bb12372160a8cb2e8d2f68d7318d96 (patch)
tree247095ab903542fc41fa591847581f0a74d7c2f5 /server
parentca59c93fb4dbc112e5deb5f5a4b10c0c730a4be4 (diff)
downloadvaadin-framework-41f2e9e753bb12372160a8cb2e8d2f68d7318d96.tar.gz
vaadin-framework-41f2e9e753bb12372160a8cb2e8d2f68d7318d96.zip
Serialize and deserialize diff state manually (#9717, #9767)
Extended UISerialization test to both serialize and deserialize and also validate ConnectorTracker (de)serialization Change-Id: Ifb8228bd56ec3635e4267e78160eef14dd9ff318
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/AbstractCommunicationManager.java2
-rw-r--r--server/src/com/vaadin/ui/ConnectorTracker.java45
2 files changed, 43 insertions, 4 deletions
diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java
index 8ea0b88b74..b7b97cbefd 100644
--- a/server/src/com/vaadin/server/AbstractCommunicationManager.java
+++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java
@@ -1279,7 +1279,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
stateType, uI.getConnectorTracker());
if (supportsDiffState) {
connectorTracker.setDiffState(connector,
- encodeResult.getEncodedValue());
+ (JSONObject) encodeResult.getEncodedValue());
}
return (JSONObject) encodeResult.getDiff();
}
diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java
index 3fb83eeb92..ddb02129d4 100644
--- a/server/src/com/vaadin/ui/ConnectorTracker.java
+++ b/server/src/com/vaadin/ui/ConnectorTracker.java
@@ -15,6 +15,7 @@
*/
package com.vaadin.ui;
+import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
@@ -25,6 +26,9 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractCommunicationManager;
import com.vaadin.server.ClientConnector;
@@ -59,7 +63,7 @@ public class ConnectorTracker implements Serializable {
private boolean writingResponse = false;
private UI uI;
- private transient Map<ClientConnector, Object> diffStates = new HashMap<ClientConnector, Object>();
+ private transient Map<ClientConnector, JSONObject> diffStates = new HashMap<ClientConnector, JSONObject>();
/**
* Gets a logger for this class
@@ -409,11 +413,11 @@ public class ConnectorTracker implements Serializable {
return dirtyConnectors;
}
- public Object getDiffState(ClientConnector connector) {
+ public JSONObject getDiffState(ClientConnector connector) {
return diffStates.get(connector);
}
- public void setDiffState(ClientConnector connector, Object diffState) {
+ public void setDiffState(ClientConnector connector, JSONObject diffState) {
diffStates.put(connector, diffState);
}
@@ -457,4 +461,39 @@ public class ConnectorTracker implements Serializable {
}
this.writingResponse = writingResponse;
}
+
+ /* Special serialization to JSONObjects which are not serializable */
+ private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+ // Convert JSONObjects in diff state to String representation as
+ // JSONObject is not serializable
+ HashMap<ClientConnector, String> stringDiffStates = new HashMap<ClientConnector, String>(
+ diffStates.size());
+ for (ClientConnector key : diffStates.keySet()) {
+ stringDiffStates.put(key, diffStates.get(key).toString());
+ }
+ out.writeObject(stringDiffStates);
+ };
+
+ /* Special serialization to JSONObjects which are not serializable */
+ private void readObject(java.io.ObjectInputStream in) throws IOException,
+ ClassNotFoundException {
+ in.defaultReadObject();
+
+ // Read String versions of JSONObjects and parse into JSONObjects as
+ // JSONObject is not serializable
+ diffStates = new HashMap<ClientConnector, JSONObject>();
+ @SuppressWarnings("unchecked")
+ HashMap<ClientConnector, String> stringDiffStates = (HashMap<ClientConnector, String>) in
+ .readObject();
+ diffStates = new HashMap<ClientConnector, JSONObject>();
+ for (ClientConnector key : stringDiffStates.keySet()) {
+ try {
+ diffStates.put(key, new JSONObject(stringDiffStates.get(key)));
+ } catch (JSONException e) {
+ throw new IOException(e);
+ }
+ }
+
+ }
}