我正在構建一個使用GWT並將其託管在App Engine上的Facebook平臺Web應用程序。
我正在添加使用提供的查詢字符串參數在回調url中的驗證代碼。 GWT允許我通過調用Window.Location.getParameterMap()來獲得這些參數,並且返回的Map是不可變的。
我可能是錯的,但我認爲這個問題與FB,GWT或App Engine沒有任何關係,更多的是我對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();
}
也請發佈錯誤消息,並指出它抱怨哪一行。 –
看起來不錯,但哪張地圖是不可修改的?該方法的參數? –
對不起,我是新來這個網站,並錯過了您的意見。 完整的錯誤消息和行將是完美的,但我努力從Throwable.getMessage()產生「java.util.Collections $ UnmodifiableMap」 這些都是我可以得到的。另外,該方法的參數是不可修改的。我一直都知道(它在文檔中),但我不確定我的代碼是否無意中嘗試修改該地圖。 感謝您的意見:-) – Darren