Home > SOA Tips > The Web Services Advisor > Web services for mobile clients - Java ME/JSR-172
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

THE WEB SERVICES ADVISOR

Web services for mobile clients - Java ME/JSR-172


Daniel Rubio
05.16.2006
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


As pervasive and ubiquitous as Web services may become in the IT landscape, the universal approach of providing and processing XML type payloads in the same fashion for every possible system will not scale, a statement that proves more than evident in the area of mobile applications. Up next, we will analyze how Java ME(Java Micro Edition) -- Java's answer to mobile development -- tackles the issue of Web services.

Mobile clients form that special group of devices such as personal digital assistants(PDA's) and mobile phones, that even though they serve as on-the-go access points to vital data, they are hindered in areas such as memory, display and high latency networks. A quick glance at earlier technologies targeting these same devices should provide enough evidence as to why Web services require special consideration in this space.

HTML, which to this day still serves to markup pretty much every Internet page, does not have the optimal characteristics to be used by most mobile devices. In its place, markup languages such as WML and HDML have been created to confront many issues facing PDA's and mobile phones, so this should be an indicator that what works for most scenarios does not necessarily fit into the mobile world.

Java ME Web services or JSR-172 tackles two issues in the mobile applications realm: Accessing SOAP/XML Web services from Java-enabled mobile devices and processing the XML messages that compose such service requests. In this sense, JSR-172 is concentrated exclusively on client side consumption of Web services, not on the possibility of publishing services from a mobile device.

If you have previous experience tapping Web services from Java clients, then you should be fairly comfortable working with Java ME Web services, since both XML processing and Web services access are based on the greater superset API's JAXP and JAX-RPC, which are used for the same tasks in full-fledged Java environments.

What is unique about these subset API's for JAXP and JAX-RPC is that their implementation target size is around 35Kb, which is common for a Connected Limited Device Configuration (CLDC) like the one used in Java ME. While the JAX-RPC implementation for Java ME and standard Java are approximately the same kilobytes in size, the underlying classes onto which JAXP plugs into are very different since access to the full suite of XML processing capabilities available in standard Java is not readily available for mobile applications due to platform size restrictions.

Shifting our focus to functionality, in regards to Java ME's JAX-RPC vs. JAX-RPC standard Java implementation, the former lacks support for the following features which are present in the latter :

  • Does not support service endpoints, which is another name for saying a device cannot be a web service producer.
  • Does not offer service discovery (UDDI).
  • Does not support SOAP Messages with Attachments.
  • Does not support SOAP message handlers.

And as hinted earlier, what differentiates Java ME's JAXP implementation from its standard Java parent for processing XML is the following:

  • Does not support the document object model (DOM), as its considered to spacious.
  • Does not support extensible style-sheet language transformations (XSLT)

We will now take a look at Java ME's JAX-RPC API, and see how its used to call a Web service available on the wider Internet. Keep in mind this is only part of a Java ME application built to conform to the Mobile Information Device Profile (MIDP). Like any other software application, a Java ME application has to incorporate business logic classes, a user interface and application state management among other things. Addressing such issues would go beyond the scope of this article since they are more related to Java ME than Web services, so you are advised to consult Java ME's site or the Sun Wireless Toolkit , which is an environment for developing Java ME applications.

The first step in creating a Java ME Web service is to generate a Java stub from the service provider via its WSDL contract, this step is similar to a standard Java Web service that uses a WSDL contract to obtain a language specific interface on which to tap a particular servic. However, in Java ME's case the stub needs to be built around a JSR-172 implementation, for which the Sun Wireless Toolkit provides such a tool.

Once you have this stub, a concrete class needs to be built around it, listing 1.1 illustrates what this class would look like when implementing a Java ME Web service for a weather application.

Listing 1.1 Java ME Midlet/class using web services.
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;

import java.rmi.RemoteException;

// Define web service url and input data
String serviceURL = "www.acmeweather.com/weatherservice";
int zipCode = 91912;

// Generate WeatherService stub
WeatherService_Stub service = new WeatherService_Stub();

// Configure stub
service._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
service._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, new Boolean(true));

/** More code - cut out for brevity */

try {
    // Invoke the WeatherService method getWeatherByZip(zipCode)
    // The web service method takes and integer representing
    // a city zip code
    WeatherOnTheMove weather = service.getWeatherByZip(zipCode);

    // Create a Form to display the weather.
    // Call getCityNameByZip and getWeekendWeather methods
    javax.microedition.lcdui.Form form =
        new Form(weather.getCityNameByZip(zipCode));
    form.append(wrap(weather.getWeekendWeather(zipCode)));

/** More code - cut out for brevity */

    display.setCurrent(form);
  } catch (RemoteException e) {
     // Handle network level exceptions
  } catch (Exception e) {
     // Handle standard exceptions.

}
//End Listing

Notice that we use a series javax.microedition classes which form part of Java ME's core and, with the exception of java.rmi.RemoteException, the bulk of JAX-RPC's usage is tucked away in the stub created from the Web services WSDL contract. Be aware that all these tasks take place at a developer workstation, from obtaining the WSDL contract to packaging the application. The actual involvement of a mobile device should be left only for final deployment, once the mobile Web service has been thoroughly debugged and tested on a workstation emulator.

With this we conclude our overview of Java ME's capabilities for tapping Web services used throughout many organizations. With it, you are now in a capacity of providing your users the same web services data, whether they are next to their PC or on the road with access to only a mobile phone or PDA.

About the author

Daniel Rubio is an independent technology consultant specializing in enterprise and Web-based software, He blogs regularly on these and other software areas at http://www.webforefront.com/


Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
The Web Services Advisor
Erlang and concurrency in service-orientated architectures
Backup to the compute cloud
SPARQL shines as RDF's query language
Testing Web services: Unit testing and monitoring
Web services for Windows CE
Testing Web services and RIAs
The problem with IT project management
Web services with Open and Microsoft Office
REST with Axis, Struts, ColdFusion and WCF
Cross-site XMLHttpRequest: Boon or Pandora's Box

Mobile Web services
From mainframes to iPhones and beyond: IBM preps mobile SOA connection
Web 2.0 at the old ballgame
SOA hot in Asia Pacific, survey finds
Mashing the phone
Sun at JavaOne – the network is 'unstoppable'
Business Objects takes BI mobile with SOA
SOA and SaaS: Where do the twain meet?
Ajax desktop offers apps offline
Google at your own risk
Eclipse unifying enterprise SOA and mobile development

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2001 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts