Greetings,
Virtually everything I have done with WO has been responding to others' requests, but now I find myself needing to connect to google and get information back from the response. Specifically, I have an ERRest based app which is being used as a push notification server for Apple's Push Notification service (APNs). I used a (highly recommended) third party framework called Java-APNS to connect to the APNs servers. Now, I need to tweak it so it also supports Android's version of push notifications. Specifically, Google's Cloud to Device Messaging service (C2DM). There appear to be no pre-built third party frameworks to connect to this service, apparently because everyone but me knows how to use existing libraries to make an http connection with credentials, then parse the response for the necessary information.
Well, in reality, there are many tutorials for doing this sort of thing using HTTPConnection etc. and Google provides sample code for some of it, but I wanted to do it the WO Way using WO classes. I can use the Apache classes if necessary, but it seems unlikely that that would be necessary.
With the help of several people, Pascal, Travis, Dave A, I am able to make a connection and get an "OK" response back to google, but the response does not seem to correspond to what I was expecting, and there appears to be no "Auth" token, which is the entire point of the exercise.
I am using WO 5.4.3, ERRest, and Wonder from a few weeks ago.
String content = "accountType" + "=" + "GOOGLE" + "&" + "Passwd" + "=" + "MYPASSWORD" + "&" + "source" + "=" + "MYCOMPANY-MYAPP-1.0.0" + "&" + "service" + "=" + "ac2dm";
String myEncodedContents = ERXStringUtilities.urlEncode(content); request.appendContentString(myEncodedContents); connection.setReceiveTimeout(90 * 1000); // 90 second timeout -- this might be too long!?! String requestURI = request.uri();
connectionSuccess = connection.sendRequest(request); if (connectionSuccess) { c2dmResponse = connection.readResponse(); // read google's response c2dmResponseString = c2dmResponse.contentString(); NSLog.debug.appendln("the response looks like: " + c2dmResponse + "\n\n"); NSLog.debug.appendln("the response content looks like: " + c2dmResponseString + "\n\n"); } else { // handle possible error codes NSLog.debug.appendln("the response is: " + c2dmResponse); }
DEBUG NSLog - the response looks like: <er.extensions.appserver.ERXResponse (<er.extensions.appserver.ERXResponse httpVersion=HTTP/1.1 headers={cache-control=[private, max-age=0], content-length=[651], content-type=[text/html; charset=UTF-8], date=[Wed, 15 Jun 2011 19:27:29 GMT], expires=[Wed, 15 Jun 2011 19:27:29 GMT], server=[GSE], x-content-type-options=[nosniff], x-xss-protection=[1; mode=block]} content-length=651 cookies=null userInfo={} storePageInBacktrackCache=true >) status=200>
I asked the response for it's contentString and got this HTML:
DEBUG NSLog - the response content looks like: <html><head> <script type="text/_javascript_"> function autoSubmit() { document.forms["hiddenpost"].submit(); } </script></head> <body ><div><span style="font-size:1.2em">Processing...</span></div> <form action=""https://google.com/accounts/ClientLogin">https://google.com/accounts/ClientLogin" method="POST" id="hiddenpost" name="hiddenpost"><input type="hidden" name="accountType=GOOGLE&Email=email@hidden&Passwd=MYPASSWORD&source=MYCOMPANY-MYAPP-1.0.0&service=ac2dm" value=""> <noscript><input type="submit" name="nojssubmit" value="You should turn on _javascript_ support." id="nojssubmit"></noscript></form></body></html>
I ran curl and got the response I was expecting:
SID=[...] LSID=[...] Auth=[...the thing I am actually trying to get...]
So I was wondering if someone could suggest to me how, using WOResponse or whatever, I can ask the response for the "Auth" token I am supposed to get in the body of the response from google, I would appreciate it.
Thanks
Andrew
|