我正在使用GWT构建一个Facebook平台Web应用程序并将其托管在App Engine上。
我要在回调URL中添加使用提供的查询字符串参数的验证代码。 GWT允许我通过调用Window.Location.getParameterMap()获得这些参数,并且返回的Map是不可变的。
我可能是错的,但是我认为这个问题与FB,GWT或App Engine无关,而更多的是我对Map对象的误解。
我不认为我的代码尝试修改提供的Map,但是出现的错误似乎表明我的代码正在尝试修改不可变的Map。
有人可以看一下,让我知道我在修改不可修改的地图吗?
我会提供堆栈跟踪,但是找不到找到堆栈跟踪的方法来显示在App Engine日志中。
在此先感谢您的帮助:-)
/**
* Validation Test
* To generate the signature for these arguments:
* 1. Remove the fb_sig key and value pair.
* 2. Remove the "fb_sig_" prefix from all of the keys.
* 3. Sort the array alphabetically by key.
* 4. Concatenate all key/value pairs together in the format "k=v".
* 5. Append your secret key.
* 6. Take the md5 hash of the whole string.
* @param fbQueryStringParams
* @return String
*/
public String test(Map<String,List<java.lang.String>> fbQueryStringParams) {
String appSecret = TinyFBClient.APP_SECRET;
String fbSig = fbQueryStringParams.get("fb_sig").get(0);
StringBuilder sb = new StringBuilder();
TreeMap<String,String> sortedMap = new TreeMap<String,String>();
// Get a Set view of the Map of query string parameters.
Set<Map.Entry<String,List<java.lang.String>>> mapEntries = fbQueryStringParams.entrySet();
// Iterate through the Set view, inserting into a SortedMap all Map.Entry's
// that do not have a Key value of "fb_sig".
Iterator<Map.Entry<String,List<java.lang.String>>> i = mapEntries.iterator();
while(i.hasNext()) {
Map.Entry<String,List<java.lang.String>> mapEntry = i.next();
if(!mapEntry.getKey().equals("fb_sig")) { // 1. Remove the fb_sig key and value pair.
sortedMap.put(mapEntry.getKey(),mapEntry.getValue().get(0)); // 3. Sort the array alphabetically by key.
}
}
// Get a Set view of the Map of alphabetically sorted Map.Entry objects.
Set<Map.Entry<String,String>> sortedMapEntries = sortedMap.entrySet();
// Iterate through the Set view, appending the concatenated key's and value's
// to a StringBuilder object.
Iterator<Map.Entry<String,String>> ii = sortedMapEntries.iterator();
while(ii.hasNext()) {
Map.Entry<String,String> mapEntry = ii.next();
// 4. Concatenate all key/value pairs together in the format "k=v".
sb.append(mapEntry.getKey().replaceAll("fb_sig_","")); // 2. Remove the "fb_sig_" prefix from all of the keys.
sb.append("=");
sb.append(mapEntry.getValue());
}
sb.append(appSecret); // 5. Append your secret key.
String md5 = DigestUtils.md5Hex(sb.toString()); // 6. Take the md5 hash of the whole string.
// Build and return an output String for display.
StringBuilder output = new StringBuilder();
output.append("fbSig = "+fbSig);
output.append("<br/>");
output.append("md5 = "+md5);
return output.toString();
}
最佳答案
将Windows.Location.getParameterMap()复制到HashMap中,它将起作用:
因此,您可以通过RPC发送新的HashMap>(Windows.Location.getParameterMap())。
问题是unmodifiableMap无法为GWT序列化。我知道它有一个可序列化的标记,但是在GWT中它的工作原理有些不同。大多数集合类具有自定义的GWT实现,有些不100%兼容。