platforms and tools for web services and mobile applications j2me based applications

41
Platforms and tools for Web Services and Mobile Applications J2ME based Applications Bent Thomsen Aalborg University 3rd and 4th of June 2004

Upload: lars

Post on 14-Feb-2016

34 views

Category:

Documents


4 download

DESCRIPTION

Platforms and tools for Web Services and Mobile Applications J2ME based Applications. Bent Thomsen Aalborg University 3rd and 4th of June 2004. Java 2 Platform Architecture. J2ME Configuration Defined. Defines a minimum platform for a horizontal grouping of devices - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Platforms and tools for Web Services and Mobile Applications

J2ME based Applications

Bent ThomsenAalborg University

3rd and 4th of June 2004

Page 2: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Java 2 Platform Architecture

Page 3: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

J2ME Configuration Defined• Defines a minimum platform for a

horizontal grouping of devices– Similar requirements on memory and

processing power– Defines the Java Language and VM features

available on group of devices

Page 4: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Configurations and Profiles

• “A Configuration is a specification that defines a minimum Java Platform functionality for a family of devices. It defines the minimum number of Java libraries, VM capabilities, Security specification, and a Generic Connection Framework.”

• “A Profile is a collection of Java APIs that supplement a Configuration to provide capabilities for a specific device group or market type.”

Page 5: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Available J2MEConfigurations• Connected Device Configuration (CDC)

– Used by devices that are more powerful than the low end devices such as cell phones

– Example set-top boxes, certain PDAs, …• Connected, Limited Device Configuration

(CLDC)– Used for very resource constrained devices– Example, cell phones, two way pagers, …

Page 6: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

CLDC Java Virtual Machine• Sun’s Kilo Virtual Machine (KVM)

– Designed for small resource-constrained devices

– Small memory footprint (60K) for KVM– Minimum total memory 160K– 16/32-bit processors– Processor speed 8 to 32 MHZ

Page 7: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

CLDC Hardware

• Memory size is the only requirement for CLDC– At least 128K non-volatile for the KVM and

CLDC Libraries– At least 32K of volatile for KVM runtime

Page 8: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

J2ME Profiles

• Defines requirements for a specific vertical market family of devices– Extends or is Layered on top of a

configuration– Defines a standard Java platform for a vertical

market device family, to ensure interoperability

– Includes more granular domain specific class libraries that a configuration

Page 9: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Available J2ME Profiles• Mobile Information Device Profile (MIDP)

– delivers an enhanced user interface, multimedia and game functionality, end-to-end security, and greater networked connectivity to mobile phones and entry level PDAs

• Foundation Profile– set of Java APIs that support resource-constrained devices without a

standards-based GUI system • Personal Profile

– Together with CDC and Foundation Profile, Personal Profile provides a complete application environment for the high-end PDA market. Personal Profile contains the full set of AWT APIs, including support for applets and Xlets.

• Personal Basis Profile– provides a J2ME application environment for network-connected

devices supporting a basic level of graphical presentation

Page 10: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

MIDP Hardware

• Memory (added to CLDC memory)– 128K non-volatile for MIDP components– 8K non-volatile for application persistent data– 32K volatile for KVM

• Display– Screen 96x54– Display depth 1-bit– Pixel shape (aspect ratio) 1:1

Page 11: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

MIDP Hardware

• Input (one or more)– One-handed keypad– Two-handed keypad– Touch screen

• Networking– Two-way– Wireless– Possibly intermittent– Limited bandwidth

Page 12: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

MIDP Architecture

Mobile Information Device (MID)

CLDC

MIDP

Native System Software/Host Operating System

MIDPApplications

OEM-SpecificApplications

OEM-SpecificClasses

NativeApplications

Page 13: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Class Libraries • CLDC java.lang java.io java.util javax.microedition.io

• MIDP javax.microedition.lcdui javax.microedition.midlet javax.microedition.rms

Page 14: Platforms and tools for Web Services and Mobile Applications J2ME based Applications
Page 15: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

MIDP Application Model

• MIDlet is the basic application– Similar to the J2SE applet– GUI based

• MIDlet Suites – security for applications that share resources or data

Page 16: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

MIDP Application Lifecycle• MIDP applications are

known as “MIDlets”• MIDlets move from state

to state in the lifecycle, as indicated.– Start – acquire resources and

start executing– Pause – release resources and

become quiescent (wait)– Destroy – release all resources,

destroy threads, and end all activity

Pause

Active

Destroyed

star

tApp

dest

royA

pp

paus

eApp

dest

royA

pp

Page 17: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Typical J2ME Technology Stack

Mobile Information

Device Profile

KVMCLDC = KVM + J2ME Core

APIs in this

example DSP chip(e.g., ARM)

J2ME core APIs

YourMIDlet Yellow Pages, train

schedules and ticketing, games…UI, HTTP networking...

Threads, no Floats…

32-bit RISC, 256K ROM, 256K Flash, 64K RAM

Page 18: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Tour of CLDC/MIDP • Packages

– Javax.microedition.io– Javax.microedition.lcdui– Javax.microedition.midlet– Javax.microedtion.rms

• Contains user interface widgets– Form, TextField, TextBox, DateField, List, Image, Gauge,

Alert, Canvas, Graphics, Display• Event handling classes – Command and

CommandListener• Two APIs, high and low

– High level for GUI widgets, scrolling, etc.– Low level for graphics and fine-grained UI control

Page 19: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Sample Code import javax.microedition.lcdui.*;import javax.microedition.midlet.*;

public class HiMIDlet extends MIDlet {

private TextBox textbox; public HiMIDlet() { textbox = new TextBox ("", "Hello World!", 20, 0); }

public void startApp() { Display.getDisplay(this).setCurrent(textbox); } public void pauseApp() {} public void destroyApp(boolean unconditional) {}}

Page 20: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

I: Code example: Simpel GUIimport javax.microedition.midlet.*;import javax.microedition.lcdui.*;

public class HelloWorld extends MIDlet implements CommandListener {

private Form mainscreen; private Form detailsscreen; private Display myDisplay; private Command exitCommand; private Command resetCommand; private Command detailsCommand;

Page 21: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

II: Code example: Simpel GUI public HelloWorld(){ myDisplay = Display.getDisplay(this); mainscreen = new Form("Hello World"); detailsCommand = new Command("Details",Command.SCREEN, 1); resetCommand = new Command("Reset",Command.SCREEN,1); exitCommand = new Command("Exit", Command.EXIT, 1); StringItem strItem = new StringItem("Hello", " World"); mainscreen.addCommand(detailsCommand); mainscreen.addCommand(resetCommand); mainscreen.addCommand(exitCommand); mainscreen.append(strItem); mainscreen.setCommandListener(this); }

Page 22: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

III: Code example: Simpel GUI public void startApp() {

myDisplay.setCurrent(mainscreen); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { }

Page 23: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

IV: Code example: Simpel GUIpublic void commandAction(Command c, Displayable s) { if (c == exitCommand) {

destroyApp(false); notifyDestroyed(); } else if (c == detailsCommand) { detailsscreen = new Form("Details"); detailsscreen.addCommand(resetCommand); detailsscreen.setCommandListener(this); myDisplay.setCurrent(detailsscreen); } else if (c == resetCommand) { myDisplay.setCurrent(mainscreen); } }}

Page 24: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Creating J2ME Applications• Identify the devices• Identify the profiles supported by devices• Develop the Application• Using the MID profile, the application will target cell

phones and pagers• Write an application that displays the String “Hello,

Small World!”• Requires the environment; MIDP reference

implementation http://java.sun.com/products/midp/• Will run in the MIDP emulator

Page 25: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Developing J2ME Wireless Applications

• Use ktoolbar to create a project• Configure the Midlet• Build and Run the project• MIDlet class, the application-level class• Abstract, need to define methods

– startApp()– pauseApp()– destryApp(boolean unconditional)

Page 26: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Sun’s J2ME Wireless Toolkit

• To run the toolkit itself, select the KToolbar shortcut. You should see the following screen.

Page 27: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Sun’s J2ME Wireless Toolkit• The J2ME Wireless Toolkit works with projects, where the end result

of each project is one MIDlet suite. The toolkit works with one project at a time. You can change properties of the current project, build the project, and run the project in a device emulator. Several example projects come installed with the toolkit; we'll look at these later.

• Let's jump right in the water by creating a new project. Click on New Project in the button bar. The toolkit prompts you for a project name and the name of a MIDlet class in the project. Fill in HelloSuite and HelloMIDlet as shown below.

Page 28: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Nokia J2ME SDK

Page 29: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Application Loading Process

Web Page

JAMDownloadsApp

UserSelectsApp

AdvertiseApp on Web Page

Network Transfer Java ApplicationManager

(Name,Version,

Size,…)

Jar File

DescriptorFile

Page 30: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Security• J2ME Cannot support full J2SE security model

– J2SE protection domain model is larger than the entire CLDC implementation

So how’s security implemented in J2ME?•Split the security model into two parts

•Low-level-virtual machine security•Guaranteed by the CLDC Two-Phase class file verifier

• Application level security•Sandbox model

Page 31: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Low-level VM Security: Two-Phase Class Verification

• Off-device verification– Pre-verification tool add “stack map” attribute to each method in

Java class file– Pre-verification is performed on server or desktop system

before class file is downloaded to the device – This “stack map” helps to facilitate in-device verification

• Faster verification process• Less VM code and memory consumption

• In-device verification– Environment verification (e.g. memory req. to run app.)– Byte code check – Type check– Proper termination (no unconditional Jump instruction)

Page 32: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Two-Phase Class File Verification Process

Stack map attribute increases the size of a classfile by appro. 5%

Page 33: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Application-level Security: Sandbox model

• Application must run in closed environment in which app can only access those APIs defined by Configuration, Profiles and licensee open classes supported by the device

• More specifically sandbox model means:– Class files have been properly verified and guaranteed to be

valid– Ensures that only the mandated Java APIs are available to

applications as defined by CLDC, Profile and licensee’s extension classes

– Application download occurs at the native code level – JAM– Cannot override class loading mechanism– Set of native functions accessible to the VM is closed

Page 34: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

J2ME to J2EE Overview

• Data persistence possible on the client, server or both– Client MIDP Record Management System (RMS) APIs allows

for data storage that is persistent on the device• HTTP provides the bridge between J2ME (MIDP) and

the J2EE Platform– Both Platforms use HTTP/HTTPS (MIDP 1.0.3)– MIDP supports HTTP 1.1 and APIs for generating GET,

POST, and HEAD requests• Messages may tunnel through different protocols that

are transparent to the client and server• MIDlet can send any Message Format in the body of a

HTTP request– XML, Text, binary, …– Mime-types are used to indicate body format/type

Page 35: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

J2ME to J2EE Overview Continued

Areas to Consider for J2ME to J2EE Communications• Session: Sequence of service requests by single user

using a client to access server• State: Information maintained in the session across

requests. Ex: Contents of Shopping Cart• Personalization data: Information about the user, such

as address, SSN, etc… This information does not normally change from session to session, thus a J2ME application should use it to enhance the user’s experience.

Page 36: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

J2ME to J2EE Overview Continued

Managing Session States for MIDlet to J2EE Communications• HTTP is a stateless protocol. The Java Servlet API provides a

HTTPSession object to work around this limitation • J2EE App Servers use 3 methods to maintain integrity of HTTP

Sessions:– Using Cookies– Using URL Rewriting– Using HTTPS

• MIDP Devices can use all these 3 methodsManaging Personalization Data for MIDlets• Session Management may be transient• Personalization data by nature is Persistent • Major benefit of utilizing Personalization is fewer interaction for the

user

Page 37: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

J2ME Connection Types• HTTP/HTTPS

– Very simple to use• XML over HTTP/HTTPS

– Beginning to be a viable choice due to varying parsers available

• Model– Creates an object representation of a document in memory

(e.g., DOM)• Push

– Parses through an entire document, spitting out events to registered listeners (e.g., SAX)

• Pull– Parses a little at a time, returning a single element or tag

Page 38: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Wireless Web Services APIs (1)• J2ME Web Services (JSR 172)

– Public review• No API available yet

– J2ME Web Services specification goals• Access remote SOAP/XML based web services

– Does not support web service hosting capabilities– JAX-RPC subset

» Must support stub based invocation (stub created using WSDL)» No support yet for Dynamic proxies and Dynamic Invocation Interface (DII)» No asynchronous messaging with attachment support» Not required to support Java beans

• Provides parsing XML data– JAXP subset

» Must support SAX 2.0 (with exceptions)» Must not support DOM

Page 39: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

Wireless Web Services APIs 1 (2)• SOAP and J2ME

– J2ME has only limited string functionalities, a problem for every wireless java XML parser

– J2ME/CLDC lacks support Float datatypes– SOAP parsing requires to read the whole document

• kSOAP & kXML– kSOAP

• API with Small footprint• kSOAP is open source and based on kXML• Adds support for data types not supported by J2ME

– kXML• Non validating XML pull parser

Page 40: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

J2EE Architecture Including J2ME Clients

Page 41: Platforms and tools for Web Services and Mobile Applications J2ME based Applications

MIDlet, J2EE Deployment, and Provisioning to Device

• On the J2EE side, the JSPs, Servlets and any other J2EE components such as EJBs are packaged in a JAR file, which along with any WARs go in an EAR file together with a deployment descriptor

• You can use the many tools that many App Servers provide to accomplish the packaging

• MIDP application (code and any resources)– packaged into a JAR file– a JAD file accompanies the JAR file

• Over The AIR (OTA) Provisioning provides guidelines for deploying the MIDlet on MIDP devices