web services and android - osspac 2009
DESCRIPTION
Web Services and Android OSSPAC February 18 2009 SingaporeTRANSCRIPT
![Page 1: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/1.jpg)
Web Services and Android
Sean SullivanOSSPAC
18 February 2009
![Page 2: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/2.jpg)
![Page 3: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/3.jpg)
• HTTP
• OAuth
• XML
• JSON
![Page 4: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/4.jpg)
+
![Page 5: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/5.jpg)
XML response
HTTP request
![Page 6: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/6.jpg)
![Page 7: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/7.jpg)
http://code.google.com/p/jfireeagle
+
![Page 8: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/8.jpg)
• HttpClient API
• XStream
• OAuth Java library
jfireeagle project
![Page 9: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/9.jpg)
“An open protocol to allow secure API authorization in a simple and standard method from desktop and web applications”
![Page 10: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/10.jpg)
• use OAuth to access protected data
• your application needs to obtain an access token from the service provider
• service provider will issue access token after the user grants permission
![Page 12: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/12.jpg)
jfireeagle
http://code.google.com/p/jfireeagle/wiki/Android
jpoco
http://code.google.com/p/jpoco/wiki/Android
+
![Page 13: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/13.jpg)
+ HTTP
Option 1
• java.net.URL
• java.net.HttpURLConnection
Option 2
• HttpClient 4.0 API
![Page 14: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/14.jpg)
HttpClient 4.0 API
• org.apache.http.client.HttpClient
• org.apache.http.impl.client.DefaultHttpClient
![Page 15: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/15.jpg)
HttpClient 4.0 API
• org.apache.http.client.methods.HttpGet
• org.apache.http.client.methods.HttpPost
• org.apache.http.client.methods.HttpPut
• org.apache.http.client.methods.HttpDelete
![Page 16: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/16.jpg)
HttpClient 4.0 API
• org.apache.http.HttpResponse
• org.apache.http.StatusLine
• org.apache.http.HttpEntity
• org.apache.http.utils.EntityUtils
![Page 17: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/17.jpg)
HttpClient programming
• HTTP response status code
• I/O exceptions
• timeouts
• gzip?
![Page 18: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/18.jpg)
HttpClient programming
synchronous invocation public HttpResponse execute(HttpUriRequest request)
asynchronous invocation public HttpResponse execute(HttpUriRequest request,
ResponseHandler handler)
![Page 19: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/19.jpg)
UI programming
• user clicks on button
• onClick listener
• Don’t block the UI thread!
• Tip: use java.lang.Runnable
![Page 20: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/20.jpg)
Response formats
• XML
• JSON
• RSS, Atom
• other
![Page 21: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/21.jpg)
XML processing
• org.w3c.dom package (DOM)
• org.xml.sax package (SAX)
• org.xmlpull package (XPP)
• XStream
• JDOM
• Apache XmlBeans ** does not work on Android 1.0 or 1.1
![Page 22: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/22.jpg)
JSON processing
• org.json package
• Google GSON library *
• XStream + Jettison *
• json-lib *
* does not work on Android 1.0 or 1.1
![Page 23: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/23.jpg)
RSS and Atom
• Rome library *
• Apache Abdera library *
* does not work on Android 1.0 or 1.1
![Page 24: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/24.jpg)
Client libraries
code.google.com/p/jfireeagle
code.google.com/p/jpoco
code.google.com/p/meetup-java-client
![Page 25: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/25.jpg)
Client libraries
code.google.com/p/upcoming-java-client
flickrj.sourceforge.net
code.google.com/p/gdata-java-client
![Page 26: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/26.jpg)
Conclusion
• HttpClient API
• use XStream for XML processing
• use org.json package for JSON processing
• OAuth has a learning curve
![Page 27: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/27.jpg)
Thank you
![Page 28: Web Services and Android - OSSPAC 2009](https://reader031.vdocuments.net/reader031/viewer/2022020306/54620862b4af9f711c8b4592/html5/thumbnails/28.jpg)
Resources
• http://code.google.com/android/documentation.html
• http://hc.apache.org/httpcomponents-client
• http://code.google.com/p/oauth
• http://xstream.codehaus.org