270 likes | 371 Views
Java for Mobile Devices and mod_perl Gunther Birznieks www.eXtropia.com O’Reilly Open Source Convention July 22-26, 2002. Overview. Open Discussion Feel Free to Ask Questions Anytime… Java for Mobile Devices Of course, we’re not here to hype it…
E N D
Java for Mobile Devicesand mod_perlGunther Birzniekswww.eXtropia.comO’Reilly Open Source ConventionJuly 22-26, 2002
Overview • Open Discussion • Feel Free to Ask Questions Anytime… • Java for Mobile Devices • Of course, we’re not here to hype it… • But to show how useful different technologies working together can be… • J2ME (Java Micro Edition) • J2MEHttpBridge vs JavaCGIBridge • Mod_perl (for middleware)
Background Motivation • Mobile Phone apps for Asia-Pacific • Singapore • Financial Industry • Multiple data channels
Java for Mobile Devices • J2ME (as opposed to J2EE) • State: bleeding edge… • But with a great deal of potential • Potential lies in 2 key items • Ability to display rich data • Ability to take advantage of rich data on servers (JavaCGIBridge) • MIDlets Definition
J2MEHttpBridge • O’Reilly Conference - August 1997 • JavaCGIBridge • O’Reilly Conference – August 1999 • Perl in Financial Community • Example of JavaCGIBridge • Perl-based Equities Trading System (Barclays Capital)
Problems with WAP/SMS Alone • WML Forms have a minimal interface • not interactive (WMLScript does not solve the whole problem) • cannot be extended natively • Hard to maintain state between forms • Redundant data frequently needs to be re-retrieved between WML forms-- need to create fresh interface each time
Problems with MIDlets Alone • Bloated Midlet Problem • Placing all application code on the Midlet makes for a huge download • Time is of the essence for OTA Downloads • Space is an issue on mobile devices • J2ME can be difficult to code! • Browser/Phone incompatibilities
Problems with MIDlets Alone • J2ME VM restricts what MIDlets can do. • cannot open sockets to non-originating server (RDBMS problem) • So we look at solution…
J2ME with Application Back-end Java MIDlet GUI J2MEHttpBridge mod_perl CGI/Perl Servlet Flat File on Web Server Database Server
J2MEHttpBridge Solution • Advantages to deferring logic to middleware (eg mod_perl) • Mod_perl/CGI/Servlets can provide database connectivity more easily • Application related “business-rules” are centrally maintained and executed in mod_perl/CGI/Servlet apps
J2MEHttpBridge Solution • More advantages of deferring server-side access • Browsers that don’t support Java can still use the application (HTML and WML) • For CGI/Perl can more readily leverage existing “legacy” code • Many ISPs only allow CGI/Perl access (no daemons)
J2MEHttpBridge Solution • Minimizing Java Front-end advantages • Java MIDlet becomes a truly thin client -- only requires GUI code and GUI logic (JavaCGIBridge class adds ~5k overhead) • Less need to learn browser specific issues if you have less code on the front-end • But how do we use it…
Nuts and Bolts • Modify Server programs to return parsed data • Add J2MEHttpBridge class to Java MIDlet implementation
Nuts and Bolts (Server Side) • Data to be returned should be identified • Top separator (<!--start of data-->) • Bottom Separator (<!--end of data-->) • Pipe delimited fields • (Optional) Set up form variable to tell script to send data using separators defined above (javacgibridge=on)
Sample CGI/Perl Code • The code on the next slide shows how a CGI/Perl application would be modified to return sample data for the Java applet if the form variable “javacgibridge” is set to “on”.
Sample CGI/Perl Code (Continued) # If j2mehttpbridge is “on”, send data specially formatted for # java midlet, otherwise send regular HTML data to the user’s browser If ($form_data{“javacgibridge”} eq “on”) { print “<!--start of data-->”; # Loop through data here while (@row_of_data = &getRowOfData()) { printf(“%s|%s|\n”,@row_of_data); } print “<!--end of data-->”; } else { print “<TABLE><TR><TH>Last Name</TH><TH>First Name</TH></TR>”; # Loop through data here while (@row_of_data = &getRowOfData()) { printf(“<TR><TD>%s</TD><TD>%s</TD></TR>\n”, @row_of_data); } print “</TABLE>”; }
Nuts and Bolts (Java MIDlet) • Instantiate J2MEHttpBridge class • Set up form variable, form value pairs inside Hashtable • Set up URL by instantiating URL class • Get parsed data back using the URL and form variable Hashtable as a Vector of Vectors (otherwise known as an array of arrays in Perl) • NOTE: No ArrayList/Map in CDLC VM
Sample Java Code • The code on the next slide calls Address Book search script setting “firstname” and “javacgibridge” HTML form variables. The records will be returned as a Vector containing all the fields in each record as a Vector of Strings. • Uses javax.microedition.lcdui package
Sample Java Code (Continued) URL u = new URL("http://www.yourdomain.com/cgi-bin/address_query.cgi"); J2MEHttpBridge jhBridge = new J2MEHttpBridge(); // firstNameTextField is a text field on a Java MIDlet that the user fills // in to query. jhBridge.addFormValue(formVars,"firstname",firstNameTextField.getString()); jhBridge.addFormValue(formVars,"javacgibridge", "on"); Vector addressBookResults = jhBridge.getParsedData(u,formVars);
J2ME Application Delivery • Primary problems to solve: • Virii/Malicious Code • Commercial Aspect – How many times has app been delivered • In case paying per app?
Where mod_perl comes in… • Intelligent Proxy code • Check for registered apps • Run app through intermediate Java virus checker (eventually) • Check phone type for appropriate app and version delivery • Fast Back-ends • Application layer logic
Intelligent Proxy Code • Over The Air (OTA) Delivery of apps • Usually through a gateway system • WAP-based • Obtain mobile phone • Verify delivery • Also track payments of each app
Intelligent Proxy Source Code • Pseudo-code for Verification • Use MD5 Hash in database to see if download has been accomplished before • If so, Reverse Proxy the code • Source Code is on www.eXtropia.com • We’ll look at it here (show example)
Mod_perl Fast Back-ends • Similarly, mod_perl applications can be used as fast back-ends to provide data • J2ME apps would mostly be straight request/response to get data
Technology Summary • J2ME on front-end • Mod_perl back-ends • Not just apps, the power is in dynamic verification • More information can be found by going to http://www.eXtropia.com/ • Acknowledgements: Lim Swee Tat, Philippe Chiasson, Ning Jiang, Ray Hsieh
Open Discussion Questions?