Revision: 8846
Author: [email protected]
Date: Wed Sep 22 11:52:53 2010
Log: Add base64 encoding and decoding to JsonRequestProcessor.java and
changes the delimiter we use to '@'.
Review at http://gwt-code-reviews.appspot.com/885803
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8846
Modified:
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/JsoList.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyImpl.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyJsoImpl.java
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java
Wed Sep 22 07:25:43 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java
Wed Sep 22 11:52:53 2010
@@ -163,7 +163,7 @@
for(var recordKey in related) {
// Workaround for __gwt_ObjectId appearing in Chrome dev mode.
if (!related.hasOwnProperty(recordKey)) continue;
- var schemaAndId = recordKey.split(/-/, 3);
+ var schemaAndId = recordKey.split(/@/, 3);
var jso = related[recordKey];
[email protected]::pushToValueStore(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)(schemaAndId[2],
jso);
}
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
Wed Sep 22 07:25:43 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
Wed Sep 22 11:52:53 2010
@@ -67,7 +67,7 @@
}-*/;
public final String getEncodedId() {
- String parts[] = getSchemaAndId().split("-");
+ String parts[] = getSchemaAndId().split("@");
return parts[1];
}
@@ -76,7 +76,7 @@
}-*/;
public final String getSchema() {
- String parts[] = getSchemaAndId().split("-");
+ String parts[] = getSchemaAndId().split("@");
return parts[0];
}
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/JsoList.java
Wed Sep 22 04:32:28 2010
+++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/JsoList.java
Wed Sep 22 11:52:53 2010
@@ -213,7 +213,7 @@
private T get0(int i) {
if (TypeLibrary.isProxyType(property.getLeafType())) {
- String key[] = ((JsArrayString) array).get(i).split("-", 3);
+ String key[] = ((JsArrayString) array).get(i).split("@", 3);
return (T)
rf.getValueStore().getRecordBySchemaAndId(rf.getSchema(key[2]),
key[0], rf);
} else {
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyImpl.java
Wed Sep 22 07:25:43 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyImpl.java
Wed Sep 22 11:52:53 2010
@@ -40,7 +40,7 @@
protected static String getWireFormatId(String id, boolean isFuture,
ProxySchema<?> schema) {
- return id + "-" + (isFuture ? "IS" : "NO") + "-" + schema.getToken();
+ return id + "@" + (isFuture ? "IS" : "NO") + "@" + schema.getToken();
}
private final ProxyJsoImpl jso;
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyJsoImpl.java
Wed Sep 22 04:32:28 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/ProxyJsoImpl.java
Wed Sep 22 11:52:53 2010
@@ -242,7 +242,7 @@
return null;
} else {
// TODO: should cache this or modify JSO field in place
- String schemaAndId[] = relatedId.split("-");
+ String schemaAndId[] = relatedId.split("@");
assert schemaAndId.length == 3;
ProxySchema<?> schema =
getRequestFactory().getSchema(schemaAndId[2]);
return (V)
getRequestFactory().getValueStore().getRecordBySchemaAndId(schema,
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
Wed Sep 22 04:32:28 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
Wed Sep 22 11:52:53 2010
@@ -575,7 +575,7 @@
sw.println("public ProxySchema<? extends ProxyImpl> getType(String
token) {");
sw.indent();
- sw.println("String[] bits = token.split(\"-\");");
+ sw.println("String[] bits = token.split(\"@\");");
for (JClassType publicProxyType : generatedProxyTypes) {
String qualifiedSourceName =
publicProxyType.getQualifiedSourceName();
sw.println("if (bits[0].equals(\"" + qualifiedSourceName + "\")) {");
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Wed Sep 22 04:32:28 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Wed Sep 22 11:52:53 2010
@@ -22,6 +22,8 @@
import com.google.gwt.requestfactory.shared.WriteOperation;
import com.google.gwt.requestfactory.shared.impl.CollectionProperty;
import com.google.gwt.requestfactory.shared.impl.Property;
+import com.google.gwt.user.server.Base64Utils;
+
import static com.google.gwt.requestfactory.shared.impl.RequestData.*;
import org.json.JSONArray;
@@ -103,7 +105,7 @@
}
if (String.class.isAssignableFrom(entityIdType)) {
- return encodedId.substring(FAKE_ENCODED.length());
+ return base64Decode(encodedId);
}
return decodeParameterValue(entityIdType, encodedId);
@@ -128,7 +130,7 @@
@Override
public String toString() {
- return encodedId + "-" + (isFuture ? "IS" : "NO") + "-"
+ return encodedId + "@" + (isFuture ? "IS" : "NO") + "@"
+ proxyType.getName();
}
}
@@ -147,9 +149,25 @@
public static final String RELATED = "related";
- private static final String FAKE_ENCODED = "encoded*";
-
private static final Logger log =
Logger.getLogger(JsonRequestProcessor.class.getName());
+
+ // Decodes a string encoded as web-safe base64
+ public static String base64Decode(String encoded) {
+ byte[] decodedBytes;
+ try {
+ decodedBytes = Base64Utils.fromBase64(encoded);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "EntityKeyId was not Base64 encoded: " + encoded);
+ }
+ return new String(decodedBytes);
+ }
+
+ // Encodes a string with web-safe base64
+ public static String base64Encode(String decoded) {
+ byte[] decodedBytes = decoded.getBytes();
+ return Base64Utils.toBase64(decodedBytes);
+ }
@SuppressWarnings("unchecked")
public static Class<EntityProxy> getRecordFromClassToken(String
recordToken) {
@@ -1148,7 +1166,7 @@
private String encodeId(Object id) throws JSONException {
if (id instanceof String) {
- return FAKE_ENCODED + id;
+ return base64Encode((String) id);
}
return encodePropertyValue(id).toString();
}
@@ -1204,10 +1222,10 @@
/**
* Given param0, return the EntityKey. String is of the form
- * "239-NO-com....EmployeeRecord" or "239-IS-com...EmployeeRecord".
+ * "2...@[email protected]" or "2...@[email protected]".
*/
private EntityKey getEntityKey(String string) {
- String parts[] = string.split("-");
+ String parts[] = string.split("@");
assert parts.length == 3;
String encodedId = parts[0];
@@ -1285,7 +1303,7 @@
private String getSchemaAndId(Class<? extends EntityProxy> proxyType,
Object newId) {
- return proxyType.getName() + "-" + newId;
+ return proxyType.getName() + "@" + newId;
}
private SerializedEntity getSerializedEntity(EntityKey entityKey)
@@ -1434,7 +1452,7 @@
propertyValue = JSONObject.NULL;
} else if (encodedEntityId != null) {
propertyValue = encodedEntityId
- + "-NO-"
+ + "@NO@"
+ operationRegistry.getSecurityProvider().encodeClassType(
p.getType());
} else if (p instanceof CollectionProperty) {
@@ -1443,7 +1461,7 @@
String encodedIdVal = isEntityReference(val, p.getType());
if (encodedIdVal != null) {
propertyValue = encodedIdVal
- + "-NO-"
+ + "@NO@"
+ operationRegistry.getSecurityProvider().encodeClassType(
p.getType());
} else {
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Wed Sep 22 07:25:43 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Wed Sep 22 11:52:53 2010
@@ -184,7 +184,7 @@
foo.put("intId", 45);
foo.put("nullField", "test");
foo.put("barNullField", SimpleBar.getSingleton().getId()
- + "-IS-" + SimpleBarProxy.class.getName());
+ + "@IS@" + SimpleBarProxy.class.getName());
foo.put("barField", JSONObject.NULL);
JSONObject result = getResultFromServer(foo);
@@ -279,16 +279,16 @@
List<String> oneToMany = (List<String>) foo.get("oneToManyField");
assertEquals(2, oneToMany.size());
-
assertEquals("encoded*1L-NO-com.google.gwt.requestfactory.shared.SimpleBarProxy",
oneToMany.get(0));
-
assertEquals("encoded*1L-NO-com.google.gwt.requestfactory.shared.SimpleBarProxy",
oneToMany.get(1));
+ assertEquals(JsonRequestProcessor.base64Encode("1L")
+ "@[email protected]",
oneToMany.get(0));
+ assertEquals(JsonRequestProcessor.base64Encode("1L")
+ "@[email protected]",
oneToMany.get(1));
List<String> selfOneToMany = (List<String>)
foo.get("selfOneToManyField");
assertEquals(1, selfOneToMany.size());
-
assertEquals("999-NO-com.google.gwt.requestfactory.shared.SimpleFooProxy",
selfOneToMany.get(0));
+
assertEquals("9...@[email protected]",
selfOneToMany.get(0));
Set<String> oneToManySet = (Set<String>) foo.get("oneToManySetField");
assertEquals(1, oneToManySet.size());
-
assertEquals("encoded*1L-NO-com.google.gwt.requestfactory.shared.SimpleBarProxy",
oneToManySet.iterator().next());
+ assertEquals(JsonRequestProcessor.base64Encode("1L")
+ "@[email protected]",
oneToManySet.iterator().next());
return foo;
}
@@ -320,7 +320,7 @@
+ ReflectionBasedOperationRegistry.SCOPE_SEPARATOR
+ "sum\", "
+ "\"" + RequestData.PARAM_TOKEN + "0\":"
- + "\"1-NO-com.google.gwt.requestfactory.shared.SimpleFooProxy\","
+ + "\"1...@[email protected]\","
+ "\""
+ RequestData.PARAM_TOKEN
+ "1\": [1, 2, 3] }");
@@ -338,10 +338,10 @@
+ ReflectionBasedOperationRegistry.SCOPE_SEPARATOR
+ "processList\", "
+ "\"" + RequestData.PARAM_TOKEN + "0\":"
- + "\"1-NO-com.google.gwt.requestfactory.shared.SimpleFooProxy\","
+ + "\"1...@[email protected]\","
+ "\""
+ RequestData.PARAM_TOKEN
- + "1\":
[\"1-NO-com.google.gwt.requestfactory.shared.SimpleFooProxy\",
\"1-NO-com.google.gwt.requestfactory.shared.SimpleFooProxy\",
\"1-NO-com.google.gwt.requestfactory.shared.SimpleFooProxy\"] }");
+ + "1\":
[\"1...@[email protected]\",
\"1...@[email protected]\",
\"1...@[email protected]\"] }");
assertEquals("GWTGWTGWT", results.getString("result"));
}
@@ -358,7 +358,7 @@
sync.put(RequestData.OPERATION_TOKEN,
"com.google.gwt.requestfactory.shared.SimpleFooRequest::persist");
sync.put(RequestData.CONTENT_TOKEN, operation.toString());
- sync.put(RequestData.PARAM_TOKEN + "0", foo.getString("id") + "-NO"
+ "-"
+ sync.put(RequestData.PARAM_TOKEN + "0", foo.getString("id") + "@NO"
+ "@"
+ SimpleFooProxy.class.getName());
return requestProcessor.processJsonRequest(sync.toString());
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors