Connecting to
Web Services on Android




       Sean Sullivan
       June 2, 2010
HTTP request


HTTP response
•   HTTP
•   XML
•   JSON
•   OAuth
+ 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
JSON processing
• json.org package
• Google GSON library
• XStream + Jettison
                   *


• json-lib
        *
...
XML processing
• org.w3c.dom package (DOM)
• org.xml.sax package (SAX)
• org.xmlpull package (XPP)
• XStream
• JDOM
• Apac...
RSS and Atom

• Rome library *
• Apache Abdera library   *




                              * does not work on Android 1.x
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 Google GSON for JSON processing
• OAuth has a learning...
Thank you
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Connecting to Web Services on Android June 2 2010
Upcoming SlideShare
Loading in...5
×

Connecting to Web Services on Android June 2 2010

9,693

Published on

Open Source Bridge 2010
June 2, 2010
Portland Oregon

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

No Downloads
Views
Total Views
9,693
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
395
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Connecting to Web Services on Android June 2 2010

  1. 1. Connecting to Web Services on Android Sean Sullivan June 2, 2010
  2. 2. HTTP request HTTP response
  3. 3. • HTTP • XML • JSON • OAuth
  4. 4. + HTTP Option 1 • java.net.URL • java.net.HttpURLConnection Option 2 • HttpClient 4.0 API
  5. 5. HttpClient 4.0 API • org.apache.http.client.HttpClient • org.apache.http.impl.client.DefaultHttpClient
  6. 6. 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
  7. 7. HttpClient 4.0 API • org.apache.http.HttpResponse • org.apache.http.StatusLine • org.apache.http.HttpEntity • org.apache.http.utils.EntityUtils
  8. 8. HttpClient programming • HTTP response status code • I/O exceptions • timeouts • gzip
  9. 9. HttpClient programming synchronous invocation public HttpResponse execute(HttpUriRequest request) asynchronous invocation public HttpResponse execute(HttpUriRequest request, ResponseHandler handler)
  10. 10. UI programming • user clicks on button • onClick listener • Don’t block the UI thread! • Tip: use java.lang.Runnable
  11. 11. Response formats • XML • JSON • RSS, Atom • other
  12. 12. JSON processing • json.org package • Google GSON library • XStream + Jettison * • json-lib * * does not work on Android 1.x
  13. 13. 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.x
  14. 14. RSS and Atom • Rome library * • Apache Abdera library * * does not work on Android 1.x
  15. 15. Client libraries code.google.com/p/jfireeagle code.google.com/p/jpoco code.google.com/p/meetup-java-client
  16. 16. Client libraries code.google.com/p/gdata-java-client code.google.com/p/upcoming-java-client flickrj.sourceforge.net
  17. 17. Conclusion • HttpClient API • use XStream for XML processing • use Google GSON for JSON processing • OAuth has a learning curve
  18. 18. Thank you
  1. A particular slide catching your eye?

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

×