0
Web Services and Android



         Sean Sullivan
           OSSPAC
       18 February 2009
•   HTTP
•   OAuth
•   XML
•   JSON
+
HTTP request


XML response
+




http://code.google.com/p/jfireeagle
jfireeagle project
• HttpClient API
• XStream
• OAuth Java library
“An open protocol to allow secure API
authorization in a simple and standard method
from desktop and web applications”
• use OAuth to access protected data
• your application needs to obtain an access
  token from the service provider
• serv...
+




http://code.google.com/p/oauth
+


jfireeagle

   http://code.google.com/p/jfireeagle/wiki/Android

jpoco

    http://code.google.com/p/jpoco/wiki/Android
+ HTTP
Option 1
  • java.net.URL
  • java.net.HttpURLConnection
Option 2
  • HttpClient 4.0 API
HttpClient 4.0 API


•   org.apache.http.client.HttpClient
•   org.apache.http.impl.client.DefaultHttpClient
HttpClient 4.0 API

• org.apache.http.client.methods.HttpGet
• org.apache.http.client.methods.HttpPost
• org.apache.http.c...
HttpClient 4.0 API

•   org.apache.http.HttpResponse
•   org.apache.http.StatusLine
•   org.apache.http.HttpEntity
•   org...
HttpClient programming

• HTTP response status code
• I/O exceptions
• timeouts
• gzip?
HttpClient programming

synchronous invocation
  public HttpResponse execute(HttpUriRequest request)




asynchronous invo...
UI programming

• user clicks on button
• onClick listener
• Don’t block the UI thread!
• Tip: use java.lang.Runnable
Response formats

• XML
• JSON
• RSS, Atom
• other
XML processing
• org.w3c.dom package (DOM)
• org.xml.sax package (SAX)
• org.xmlpull package (XPP)
• XStream
• JDOM
• Apac...
JSON processing
• org.json package
• Google GSON library   *


• XStream + Jettison
                   *


• json-lib
    ...
RSS and Atom

• Rome library *
• Apache Abdera library   *




                              * does not work on Android 1....
Client libraries

    code.google.com/p/jfireeagle

    code.google.com/p/jpoco

    code.google.com/p/meetup-java-client
Client libraries
  code.google.com/p/gdata-java-client


  code.google.com/p/upcoming-java-client


  flickrj.sourceforge.n...
Conclusion

• HttpClient API
• use XStream for XML processing
• use org.json package for JSON processing
• OAuth has a lea...
Thank you
Resources

•   http://code.google.com/android/documentation.html

•   http://hc.apache.org/httpcomponents-client

•   http...
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009
Upcoming SlideShare
Loading in...5
×

Web Services and Android - OSSPAC 2009

5,284

Published on

Web Services and Android
OSSPAC
February 18 2009
Singapore

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
5,284
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
297
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Web Services and Android - OSSPAC 2009"

  1. 1. Web Services and Android Sean Sullivan OSSPAC 18 February 2009
  2. 2. • HTTP • OAuth • XML • JSON
  3. 3. +
  4. 4. HTTP request XML response
  5. 5. + http://code.google.com/p/jfireeagle
  6. 6. jfireeagle project • HttpClient API • XStream • OAuth Java library
  7. 7. “An open protocol to allow secure API authorization in a simple and standard method from desktop and web applications”
  8. 8. • 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
  9. 9. + http://code.google.com/p/oauth
  10. 10. + jfireeagle http://code.google.com/p/jfireeagle/wiki/Android jpoco http://code.google.com/p/jpoco/wiki/Android
  11. 11. + HTTP Option 1 • java.net.URL • java.net.HttpURLConnection Option 2 • HttpClient 4.0 API
  12. 12. HttpClient 4.0 API • org.apache.http.client.HttpClient • org.apache.http.impl.client.DefaultHttpClient
  13. 13. 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
  14. 14. HttpClient 4.0 API • org.apache.http.HttpResponse • org.apache.http.StatusLine • org.apache.http.HttpEntity • org.apache.http.utils.EntityUtils
  15. 15. HttpClient programming • HTTP response status code • I/O exceptions • timeouts • gzip?
  16. 16. HttpClient programming synchronous invocation public HttpResponse execute(HttpUriRequest request) asynchronous invocation public HttpResponse execute(HttpUriRequest request, ResponseHandler handler)
  17. 17. UI programming • user clicks on button • onClick listener • Don’t block the UI thread! • Tip: use java.lang.Runnable
  18. 18. Response formats • XML • JSON • RSS, Atom • other
  19. 19. 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
  20. 20. JSON processing • org.json package • Google GSON library * • XStream + Jettison * • json-lib * * does not work on Android 1.0 or 1.1
  21. 21. RSS and Atom • Rome library * • Apache Abdera library * * does not work on Android 1.0 or 1.1
  22. 22. Client libraries code.google.com/p/jfireeagle code.google.com/p/jpoco code.google.com/p/meetup-java-client
  23. 23. Client libraries code.google.com/p/gdata-java-client code.google.com/p/upcoming-java-client flickrj.sourceforge.net
  24. 24. Conclusion • HttpClient API • use XStream for XML processing • use org.json package for JSON processing • OAuth has a learning curve
  25. 25. Thank you
  26. 26. Resources • http://code.google.com/android/documentation.html • http://hc.apache.org/httpcomponents-client • http://code.google.com/p/oauth • http://xstream.codehaus.org
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×