• Like
  • Save

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Java ME and Web 2.0

  • 2,650 views
Uploaded on

This presentation describes how to access Web 2.0 lightweight web services using Java ME devices. It also propose a geo-referenced interface to Upcoming.org

This presentation describes how to access Web 2.0 lightweight web services using Java ME devices. It also propose a geo-referenced interface to Upcoming.org

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,650
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
6

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Java ME & Web 2.0 Stefano Sanna gerdavax@tiscali.it - http://www.gerdavax.it Supported by: Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 2. Speaker • Stefano Sanna is... – Mobile Application Architect @ Beeweeb – Technical writer @ DEV, JavaJournal, CP, FSM... – Supporter JMDF, JIA, JUG Sardegna, GULCh... – LEGO constructor (since 1973...) Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 3. Agenda • Introduction: – Web 2.0: who's who – Mobile interfaces for “Web 2.0” services • Java ME in practice: – Upcoming (and geo-query) • Conclusions Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 4. Web 2.0 • The “next generation of Web” • The Web considered as a platform for service providing, not just a communication media • Buzzword which identifies a new class of applications, development tools, services... new opportunities for the ICT market • Enumeration them as technologies or services: – AJAX, Comet, RSS, Atom, REST, JSON... – Gmail, Google Maps, Posticky, del.icio.us, Flickr, Bloglines, Blogger, Technorati... Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 5. Web 2.0: what is? Tim O'Reilly: “What is Web 2.0” http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 6. Web 2.0: some items • New technical approach – fast delivery (perpetual beta!), efficient, smart – open services made accessible with simpler protocols – freedom to compose new services (mashup) • New social approach – first of all: collaboration and open protocols! – custom solutions are welcome – the service lives until users keep using it, putting in their data (!) and... their expectations Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 7. Web 2.0 and service API • The number of services, APIs and mashups is growing! • programmableweb.com reports at 2007-1-26: – 1479 mashups – about 3 new mashups per day – 363 APIs Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 8. Mobile 2.0? • The “2.0” (r)evolution meets mobile computing. Wireless devices are changing the way they enhance user's mobility: mobile browser --> mobile blogger data provisioning --> mobile data provider network-aware --> context-aware stand-alone --> augmented environment yet-another-device --> my constant touch Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 9. Mobile Data Provisioning • How to exchange data: – Server-side pre-processing and data transfer on a proprietary protocol • ... the solution of Flintstone's age web :-) – XML-RPC • it does not allows to define custom datatypes – Web Services (SOAP) + local viewer • high memory and bandwidth consumption; open issues with WS-I compatibility – Lightweigth Web Services (REST-like/JSON) • fast, simple, lightweight (!), slightly coupled with fat standards Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 10. Lightweight WS: REST • REST: Representational State Transfer • Interface oriented to data exchange instead of method invocation • Simple rules: – the object can be referred using a global identifier such an URL • e.g.: http://service.com/catalog/hardware – object's state is transferred using your own XML (no SOAP, no XML-RPC...) • Wikipedia: – http://en.wikipedia.org/wiki/Representational_State_Transfer Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 11. “Famous” REST services • YouTube: – http://www.youtube.com/dev_rest • eBay: – http://developer.ebay.com/developercenter/rest • Upcoming: – http://upcoming.org/services/api/ • Technorati: – http://technorati.com/developers/api/ • Explore to innovate: – http://www.programmableweb.com/apilist Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 12. REST: tailored for Java ME! • Simple to implement, even without a dedicated API • Lightweight protocol for both CPU processing and bandwidth requirements • No need to be WS-I Basic Profile compliant (see JSR 172) • You have lot of REST/RESTful/REST-like to try! Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 13. REST: some issues • Developers rarely get a formal description of XML (DTD or Schema): specification is a simple web page and XML parsers have to be manually designed and implemented • Services may suddenly change interfaces and data formats: both client and server are in “perpetual beta” and have to be continuously update • Not suitable for complex architectures; not designed with security and interoperability Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 14. Let's try it: Upcoming.org • From the website: “Upcoming.org is a social events calendar driven by people just like you!” • Sweet Web 2.0 application, provides widgets to publish personal events on user's homepage • Provides a REST interface to access its services Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 15. Protocol (1) • API is described on developers website: – http://upcoming.org/services/api/ • Developer must obtain an application API Key to access REST services • Application must obtain a token to perform operations on user's data. Token approach guarantees user's privacy and application's trustness Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 16. Protocol (2) • Method invocation is based on HTTP GET/POST. For instance, we can search “Symbian” events: http://www.upcoming.org/services/rest/? api_key=<API_Key>& method=event.search& search_text=Symbian • Response is always an XML document: <rsp stat="ok" version="1.0"> [XML Response, depends on invoked method] </rsp> Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 17. Protocol (3) • Sample response: <rsp stat="ok" version="1.0"> <event id="87442" name="All About Symbian Pub Meet” description="The world&#39;s number one site for Symbian OS smartphones, hosts the annual meeting, and as usual, it&#39;s the night before the Symbian Smartphone Show." start_date="2006-10-16" end_date="" start_time="18:00:00" end_time="" personal="1" selfpromotion="1" metro_id="49" venue_id="5417" user_id="62647" category_id="4" date_posted="2006-06-25 11:37:36" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous=""/> <event id="76389" name="The Smartphone Show" description="Organized by Symbian" start_date="2006-10-17" end_date="2006-10-18" start_time="" end_time="" personal="1" selfpromotion="0" metro_id="49" venue_id="10928" user_id="55142" category_id="6" date_posted="2006-05-08 12:22:55" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous=""/> </rsp> Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 18. Upcoming for Java ME • Java ME provides all features to implement a client MIDlet for Upcoming.org: – HTTP connectivity – Multithreading – Local browser execution (MIDlet.platformRequest()) to load event's web pages Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 19. Java ME: something is missing • Although there are lots of powerful optional APIs (Bluetooth, messaging...), Java ME lacks some importart features on standard library: – Task-oriented multithreading framework – Support for asynchronous HTTP connections (the core of AJAX!) – Basic Authentication and not-chunked-POST • Let's dive into asynchronousness ;-) Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 20. Task-oriented multithreading • Network operations for local and remote connectivity are time-consuming and blocking • Domains: – Networking: GPRS setup, DNS lookup, server response, data transfer... – Bluetooth: discovery, pairing, transfer – SMS: message incapsulation and dispatching • Java ME specification reminds to use threads for managing all I/O operations, to keep them separate from tha main thread Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 21. Implementation • UpcomingConnection: – manages connections to REST service, manages threads and decodes responses – notifies the listener when a response has been decode or an error occurred • ConnectionListener: – receives events of UpcomingConnection Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 22. ConnectionListener public interface ConnectionListener { public void parse(byte[] result); public void failed(Exception e, String message); } The MIDlet is a ConnectionListener: result will be dispatched asynchronously; the request is not blocking the main thread Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 23. UpcomingConnection (1) public class UpcomingConnection { private ConnectionThread connectionThread; private ConnectionListener listener; private String query; public UpcomingConnection() { init(); } private void init() { connectionThread = new ConnectionThread(); connectionThread.start(); } public void setSearch(String query) { this.query = query; connectionThread.connect(); } } Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 24. UpcomingConnection (2) private class ConnectionThread extends Thread { private boolean halt; The new request wakes up the thread and performs new public void run() { asynchronous connection to // see next slide... the Upcoming service } public synchronized void connect() { notify(); } public synchronized void halt() { halt = true; notify(); } } Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 25. UpcomingConnection (3a) Once started, the thread waits for public void run() { queries... HttpConnection connection = null; InputStream input; ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[64]; try { while (! halt) { synchronized (this) { wait(); } try { baos.reset(); connection = (HttpConnection) Connector.open(UpcomingProtocol.URL + "search_text=” + query); input = connection.openInputStream(); // NEXT SLIDE.... } Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 26. UpcomingConnection (3b) if (connection.getResponseCode() == HttpConnection.HTTP_OK) { int read; while ((read = input.read(buffer)) != -1 && !halt) { baos.write(buffer, 0, read); } try { connection.close(); } catch (Exception e) { // nothing to do } finally { connection = null; } listener.parse(baos.toByteArray()); } } catch (Exception e) { listener.failed(e,"Can't connect.");} } We will use the JSR 172 (JAXP) to parse REST invocation result (please refer to JMDF seminars... :-) Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 27. Running on a Nokia E61 Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 28. Geo-Web: position-awareness • Upcoming.org queries may specify a location as city, country or... latitude&longitude. We may use a cheap GPS to submit geo- referenced queries: – the user has just to type keywords – the application automatically associates user's position to the query • Using Java ME it's simple get it working with a few lines of code Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 29. Using a Bluetooth GPS • The JSR 82 (Bluetooth API) is used to connect to RFCOMM serial port to read GPS data: gps = “btspp://0002C71536EA:1;authenticate=false;encrypt=false;master=false"; StreamConnection conn = (StreamConnection) Connector.open(gps); buffer = new BufferedReader(new InputStreamReader(conn.openInputStream())); // leggiamo la riga: String nmea_sentence = buffer.readLine(); • NMEA sentences the information we need: Satellites $GPGGA,164922.982,3859.4108,N,00856.1785,E,1,04,3.4,127.9,M,47 .6,M,0.0,0000*7A Latitude Longitude Altitude Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 30. Geo-query http://www.upcoming.org/services/rest/? api_key=API_KEY &method=event.search &query=Symbian &latitude=LAT&longitude=LON From NMEA to decimal: NMEA: DDMM.mmm MM.mmm / 60 Float: DD + .dddd Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 31. Conclusions • The Web 2.0 as development platform moves the barycenter of the Net towards: – users, actual data producers – Services and theirs compositions, which enable exploitation of data shared by users • Java ME can support seamless integration with this new class of services: – excellent support for local and remote connectivity – rich set of optional API for multimedia, location, security, 2D & 3D... Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 32. About me • Stefano Sanna – Website: http://www.gerdavax.it – Email: gerdavax@tiscali.it • Java Italian Association: – Website: http://www.jia.it • Beeweeb Technologies: – Website: http://www.beeweeb.com Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org
  • 33. Thank you :-) Java ME and Web 2.0 (Versione 1.3) (C) 2006-2007 Stefano Sanna http://www.gerdavax.it - gerdavax@tiscali.it Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation. Please, find a copy of the license at: http://www.gnu.org/copyleft/fdl.html http://www.gnu.org/copyleft/fdl.html • All trademarks are the property of their respective owners. Upcoming.org is described as an example of Web 2.0 service; nobody of Upcoming.org team was involved in making this presentation. Java ME and Web 2.0 – ActionScript.it and JMDF online Meeting, 13-03-2007 - http://www.jmdf.org