Re: Confused by java.util.Collections$UnmodifiableMap problem when using Window.Location.getParameterMap() : Source Code Included.
Hi,
I did a small test locally... and I am right: the unmodifiableMap is
not Serializable... at least not in that direction.
A simple fix would be to copy the ParameterMap to a regular HashMap
like this:
new HashMap<String, List<String>>(Window.Location.getParameterMap())
PS: Can you vote for me in stackoverflow ?
David
On Nov 26, 12:41 pm, redboffin <lostlittleal...@googlemail.com> wrote:
> Hello All :-)
>
> I am building a sandpit web application using GWT that is hosted on
> App Engine and displayed within facebook as a canvas app.
>
> I am trying to implement validation, usinghttp://wiki.developers.facebook.com/index.php/User:Google_Web_Toolkit...
> as a guide.
>
> The problem I am encountering is that when I try to use the Map
> returned by Window.Location.getParameterMap() a java.util.Collections
> $UnmodifiableMap problem occurs, even though I'm not modifying the Map
> (at least I don't think I am modifying the Map).
>
> I would be really grateful if someone could take the time to help my
> understand what I am doing wrong here or point out where I should post
> this problem if this forum is not a suitable place to raise this
> problem.
>
> Thank you in advance :-)
>
> Source Code Below.
>
> The onModuleLoad() code within my EntryPoint class is below;
>
> fbValidationService.test(Window.Location.getParameterMap(), new
> AsyncCallback<String>() {
>
> public void onFailure(Throwable caught) {
>
> // Show the RPC error message to the user
>
> RootPanel.get("serverResponse").add(new HTML("Remote Procedure
> Call : Test 261109 10:51 - Failure"));
> RootPanel.get("serverResponse").add(new HTML(SERVER_ERROR));
> RootPanel.get("serverResponse").add(new HTML(caught.getMessage
> ()));
> RootPanel.get("serverResponse").add(new HTML("Stack Trace"));
> StackTraceElement[] stackTrace = caught.getStackTrace();
> for(int i = 0 ; i < stackTrace.length ; i++) {
> StackTraceElement element = stackTrace[i];
> RootPanel.get("serverResponse").add(new HTML(element.getFileName
> ()));
> RootPanel.get("serverResponse").add(new HTML(element.getClassName
> ()));
> RootPanel.get("serverResponse").add(new HTML(element.getMethodName
> ()));
> RootPanel.get("serverResponse").add(new HTML(Integer.toString
> (element.getLineNumber())));
> }
>
> }
>
> public void onSuccess(String result) {
>
> // Show the RPC result to the user
>
> RootPanel.get("serverResponse").add(new HTML("Remote Procedure
> Call : Test - Success"));
> RootPanel.get("serverResponse").add(new HTML(result));
>
> }
>
> });
>
> The test() method within the RemoteServiceServlet object is below;
>
> /**
> * 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();
>
> }
>
> The output displayed on the web app (when displayed within facebook)
> is below;
>
> Remote Procedure Call : Test 261109 10:51 - Failure
> An error occurred while attempting to contact the server. Please check
> your network connection and try again.
> java.util.Collections$UnmodifiableMap
> Stack Trace
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home