Welcome!

Microservices Expo Authors: Yeshim Deniz, Pat Romanski, Todd Matters, Mark Leake, Stefana Muller

Related Topics: Microservices Expo

Microservices Expo: Article

Wireless Web Serviceswith J2MERemote Possibilities

Wireless Web Serviceswith J2MERemote Possibilities

What happens when the hype of Web services meets the increasingly popular and ever-changing world of wireless computing? Most likely, confusion and disillusionment. In this two-part article, we'll explore the uncharted waters of wireless Web services. We'll use the J2ME platform for developing our Web service clients and access remote services on the Internet using standardized industry protocols. In this first article, we'll examine XML-RPC, a simple, lightweight mechanism for invoking remote services with XML. The second article will compare and contrast XML-RPC with SOAP, a more robust, sophisticated, and heavier solution for invoking remote services with XML.

The Wireless World
A Web service is a coarse-grained interface to one or more business services that is invocable across a network. With a wireless network, this invocation process becomes more complicated. Many cellular telephone service providers use analog circuit-switched networks that open a constant connection for the duration of the exchange. More advanced providers are moving to digital packet-switched networks. In packet switching, a stream of digital bits is carved up into bit clusters, called packets, and blasted across the network individually.

Circuit-switched analog networks are more expensive to maintain and offer limited bandwidth. Digital packet-switched networks are cheaper, more efficient, and do not have the same bandwidth limitations. The trade-off with packet-switched networks is that packets are occasionally lost ("dropped") during transmission. Dropped packets must be retransmitted. The larger a transmission is, the greater the likelihood that packets will be dropped, requiring retransmission and degrading performance.

The bottom line is that regardless of the type of network being used by a provider, wireless clients must keep their exchanges as thin as possible to ensure optimum performance. Additionally, mobile devices typically do not have an abundance of resources for processing fat requests or responses, or storing robust data models.

XML-RPC for Wireless Web Services
XML-RPC is a Remote Procedure Calling protocol that invokes remote procedures over a network by sending XML-formatted messages. The XML-RPC specification was developed and is maintained by UserLand Software, Inc.; the full specification can be found at www.xmlrpc.org/spec.

XML-RPC is an extremely lightweight mechanism that can be used as part of a Web services architecture. The key to a Web services architecture is the utilization of XML as a language-agnostic, vendor- and platform-neutral medium for accessing Internet or intranet services. XML-RPC provides the minimum functionality necessary to specify data types, pass parameters, and invoke remote procedures in a neutral way.

What makes XML-RPC so efficient? XML-RPC defines eight data types: six primitive types (int, Boolean, string, double, datetime, and base64) and two complex types (struct and array). These are the only types available, yet they provide all the functionality that is needed about 80% of the time. Although SOAP provides a more robust data-typing mechanism based upon XML Schemas (even allowing the creation of custom data types), this is often overkill in a wireless environment. We'll explore these topics further in our next article; for now, we simply need to understand that XML-RPC is an extremely lightweight mechanism for invoking Web services in a standardized and neutral manner.

The wireless applications that we'll be developing in these articles require the J2ME platform, so we'll take a brief look at J2ME to provide for a basic background for these wireless Web services.

J2ME Primer
The Java 2 Micro Edition is a Java 2 platform for developing applications for devices with limited memory. Specifically, J2ME addresses the need for application development for consumer and embedded devices. Because it is designed for devices with extremely small footprints, many of the features of the J2SE are not included. Some of the notable features not included are floating point data types, serialization (no JavaBeans), thread groups and thread daemons, finalizations, user-defined class loaders, and the JNI. As Figure 1 indicates, the J2ME platform is a layered stack consisting of a virtual machine and the core J2ME class libraries, as well as configuration class libraries and device-specific profiles.

Configurations
Configurations define the run-time environment by specifying the Java features (classes) that are available as well as which virtual machine will be used. A configuration can also be thought of as relating to a category of devices that have common characteristics and memory constraints. For devices that have a total memory from 160 to 512 kB, the Connected Limited Device Configuration (CLDC) for J2ME can be used. CLDC devices usually include cell phones, two-way pagers and low-end PDAs. The CLDC also targets devices with a network connection and processing power of 16 or 32 bits. The CLDC uses the K (k for kilobyte) Virtual Machine or KVM. For devices that have a total memory of 2MB or greater and a 32-bit or 64-bit microprocessor, the Connected Device Configuration (CDC) is used. The CDC uses the CVM and is generally used on set-top TVs, higher-end PDAs, and next generation mobile devices. A configuration (and corresponding virtual machine), combined with a device-specific profile, and the core J2ME libraries, constitutes a complete J2ME environment.

Profiles Overview
Profiles work on top of configurations and focus on a "vertical" market or industry segment of devices. Profiles also allow developers to address more device-specific features such as the life cycle of an application, user interfaces, and networking issues. CDC devices typically use the Foundation profile, which targets devices that require more networking capabilities and no GUIs. CLDC devices typically use the Mobile Information Device Profile (MIDP). For the wireless development that we focus on in this series, we'll be using MIDP.

MIDP
The MIDP consists of APIs for user interface design as well as for database activity. A MIDP application is referred to as a midlet. MIDP even allows multiple midlets to be packaged together as a midlet suite and share information between midlets within the suite. This is generally only useful, however, in the case of midlets that maintain a database. For our purposes, we're interested in MIDP's GUI capabilities. MIDP supports 10 GUI components: Command, Alert, Choice, Choice Group, Form, List, StringItem, TextBox, TextField, and Ticker.

In our sample application, we'll be using the following GUI components:

  • List: Contains a list of choices, typically relies upon a device's "select" or "go" functionality.
  • Command: Presents a choice of action. Contains a label, a type, and a priority.
  • Display: The midlet's canvas upon which UI components are displayed.
  • Alert: Informs the user about an exceptional condition or error. It can also be used to display the results of a query to the user.
To understand how a MIDP user interface is created and how it functions, it's necessary to understand the life cycle of a midlet. This can be seen in four stages, each with a corresponding method defined within the midlet:
  • Initialization: constructor: Every midlet has a default constructor. This is used to initialize a midlet's data members, including GUI components, with their desired property values (size, shape, color, label, text, reference, etc.).
  • Activation: startApp(): Acquires necessary resources, makes display visible to user, and begins to perform requested services.
  • Passivation: pauseApp(): Stops performing services and releases shared resources.
  • Destruction: destroyApp(): Releases shared and local resources and saves any persistent data.
The mobile device will handle the management of a midlet through these life cycle methods via Application Management Software (AMS). AMS frees the developer from directly managing a midlet and its resources.

Writing a MIDP Web Service Client
In this article, we'll create a MIDP client that uses the XML-RPC protocol for invoking remote Web services in a platform- and language-neutral way. To do this, we'll need a J2ME implementation of the XML-RPC protocol. At the time of this writing, the only publicly available client implementation is kXML-RPC, an open-source XML-RPC project for the J2ME platform. kXML-RPC is maintained by the Enhydra organization and can be freely downloaded from their Web site at http://kxmlrpc.enhydra.org. The kXML-RPC library uses Enhydra's kXML parser to handle the low-level XML parsing details. With the addition of the parser, the kxmlrpc jar file reaches a whopping 24kb!

With the kxmlrpc jar file downloaded to your system and placed in your application classpath, you can write the MIDP client. We'll walk through the creation of the midlet and highlight the most interesting lines of code, but the entire source code for the midlet can be seen in Listing 1, and the source for MyMidl et.java can be downloaded from the kXML-RPC Web site (kxmlrpc-samples.zip) located at http://kxmlrpc.enhydra.org/software/downloads/index.html.

The first step, obviously, is to import the necessary packages and declare the MIDP components that will be used in the application. After this, we define the midlet's constructor, initializing all the UI components and adding them to the display as necessary. With that complete, we need to fill in the three other life cycle methods. In the startApp() method, we simply bring the MIDP display into action. Since we don't use any shared resources, the pauseApp() method is blank. Finally, the destroyApp() method releases the local resources that we have allocated for our midlet.

Now we're ready for the interesting part of the code, the commandAction() method. This method is called anytime the user performs a command event (pressing a key, selecting an item from a list, etc.). The Command and Displayable objects are then queried to determine which component has actually been activated/deactivated, and the appropriate actions are performed. Our midlet has three remote XML-RPC Web services displayed in a list (see Figure 2), and a switch statement is performed on the index of that list to determine which item has been selected. In Listing 1, only the first service is given an implementation, but the other two can be seen by downloading the source code.

The Timestamp service is very simple, a parameterless request is sent to the service and a String object representing the current time is returned. To perform this query, a kxmlrpc object is created with the specified URL for the Web service. Then an empty Vector is created and the actual request is performed with the following line:

String serverTime = ( String )
xmlrpc.execute(
"sysTime.getSystemTime", params );

The execute() method accepts two parameters, a String representing the name of the service, and a Vector representing any parameters that should be passed to the service. This particular service returns a String object that is then sent to the screen to display the current time on the server. An example can be seen in Figure 3.

Deploying and Testing a Midlet
For deploying and testing our midlet, we used Sun's J2ME Wireless Toolkit (J2MEWTK) version 1.0.3 beta which can be downloaded from Sun's Web site at http://java.sun.com/products/j2mewtoolkit/. The toolkit is 100% Java, built using the Java 2 Standard Edition, so even though it contains the J2ME APIs and is used for deploying and testing J2ME applications, it requires a J2SE implementation in order to run.

To deploy and test your midlet, you need to do four things: create a project for your application, write the midlet's code, place all of the files and resources in their appropriate application directories, and then build and run the application.

With the toolkit properly installed, the first step is to create a project for your application. To do so, follow these steps:

  • Start the KToolbar application
  • Click the "New Project" button. Name your project and name your project's midlet (this will also be the name used for the midlet in the .java source file).
  • Click the "OK" button on the Settings screen that shows keys and values. This screen represents your application's deployment properties. You can specify these properties now or later by clicking the "Settings" button.
Now that you've created a project, the toolkit has created a corresponding directory structure for your project. That project directory structure is located under the apps directory of the J2MEWTK installation directory. We're only interested in three of them: the source code, resource, and library directories.
  • \src: Place your java midlet's source code files in this directory.
  • \res: Place any resource files (images, text files, etc.) in this directory.
  • \lib: Place JAR files and Java class files that your midlet(s) will need in this directory.
After creating a project, writing the midlet code, and placing all the necessary files in the appropriate directories, you're ready to actually test the application. This requires three essential steps:
  • Build the application into an executable midlet by clicking the "Build" button.
  • Resolve any errors or exceptions that are thrown and rebuild the application until a successful build is accomplished.
  • Execute the application by clicking the "Run" button after a successful build has been created.
When you run a midlet from the J2MEWTK, a phone emulator is started and the toolkit attempts to load your midlet into the emulator. You can test your midlet with any of the supplied emulators, or even download additional emulation environments from the Web. With your midlet running, you can navigate through your midlet just as you would on a real J2ME-enabled wireless phone. If your computer is currently connected to the Web, then you should be able to access the services listed in your midlet code.

Deploying into Production
Once your midlet development and testing is complete, you can package your application into an executable format by selecting the "Package" menu item from the "Project" menu. The toolkit will create a .jar and jad file in your project's \bin directory. The .jad file is used for describing and executing your midlet, while the .jar file contains the Java class files, library and resource files used by your midlet. From now on, simply double-clicking the .jad file will run the midlet.

Looking Ahead
In this article we've taken a look into the world of the wireless Web, XML-RPC as a Web service communication protocol, and the J2ME environment with special attention paid to the MID profile, and also looked at a demonstration of an XML-RPC midlet using the kxmlrpc code. XML-RPC provides a very thin, efficient means of invoking remote services in a standard and neutral way. It defines a succinct set of eight data types, providing the means necessary to encode simple and moderately complex data structures in a highly efficient manner. More often than not, XML-RPC will provide you with all the functionality that you need, especially given the natural constraints of wireless devices. For applications that require more functionality, the Simple Object Access Protocol (SOAP) may be in order. In our next article we'll delve into SOAP and provide a detailed analysis of when to choose SOAP over XML-RPC for wireless computing.

More Stories By Kyle Gabhart

Kyle Gabhart is a subject matter expert specializing in strategic planning and tactical delivery of enterprise technology solutions, blending EA, BPM, SOA, Cloud Computing, and other emerging technologies. Kyle currently serves as a director for Web Age Solutions, a premier provider of technology education and mentoring. Since 2001 he has contributed extensively to the IT community as an author, speaker, consultant, and open source contributor.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@MicroservicesExpo Stories
Cloud Expo, Inc. has announced today that Andi Mann and Aruna Ravichandran have been named Co-Chairs of @DevOpsSummit at Cloud Expo Silicon Valley which will take place Oct. 31-Nov. 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. "DevOps is at the intersection of technology and business-optimizing tools, organizations and processes to bring measurable improvements in productivity and profitability," said Aruna Ravichandran, vice president, DevOps product and solutions marketing...
"When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
For most organizations, the move to hybrid cloud is now a question of when, not if. Fully 82% of enterprises plan to have a hybrid cloud strategy this year, according to Infoholic Research. The worldwide hybrid cloud computing market is expected to grow about 34% annually over the next five years, reaching $241.13 billion by 2022. Companies are embracing hybrid cloud because of the many advantages it offers compared to relying on a single provider for all of their cloud needs. Hybrid offers bala...
A common misconception about the cloud is that one size fits all. Companies expecting to run all of their operations using one cloud solution or service must realize that doing so is akin to forcing the totality of their business functionality into a straightjacket. Unlocking the full potential of the cloud means embracing the multi-cloud future where businesses use their own cloud, and/or clouds from different vendors, to support separate functions or product groups. There is no single cloud so...
Containers, microservices and DevOps are all the rage lately. You can read about how great they are and how they’ll change your life and the industry everywhere. So naturally when we started a new company and were deciding how to architect our app, we went with microservices, containers and DevOps. About now you’re expecting a story of how everything went so smoothly, we’re now pushing out code ten times a day, but the reality is quite different.
"We are a monitoring company. We work with Salesforce, BBC, and quite a few other big logos. We basically provide monitoring for them, structure for their cloud services and we fit into the DevOps world" explained David Gildeh, Co-founder and CEO of Outlyer, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
21st International Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Me...
If you cannot explicitly articulate how investing in a new technology, changing the approach or re-engineering the business process will help you achieve your customer-centric vision of the future in direct and measurable ways, you probably shouldn’t be doing it. At Intellyx, we spend a lot of time talking to technology vendors. In our conversations, we explore emerging new technologies that are either disrupting the way enterprise organizations work or that help enable those organizations to ...
In 2014, Amazon announced a new form of compute called Lambda. We didn't know it at the time, but this represented a fundamental shift in what we expect from cloud computing. Now, all of the major cloud computing vendors want to take part in this disruptive technology. In his session at 20th Cloud Expo, Doug Vanderweide, an instructor at Linux Academy, discussed why major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform are all trying to sidestep VMs and containers wit...
The taxi industry never saw Uber coming. Startups are a threat to incumbents like never before, and a major enabler for startups is that they are instantly “cloud ready.” If innovation moves at the pace of IT, then your company is in trouble. Why? Because your data center will not keep up with frenetic pace AWS, Microsoft and Google are rolling out new capabilities. In his session at 20th Cloud Expo, Don Browning, VP of Cloud Architecture at Turner, posited that disruption is inevitable for comp...
For organizations that have amassed large sums of software complexity, taking a microservices approach is the first step toward DevOps and continuous improvement / development. Integrating system-level analysis with microservices makes it easier to change and add functionality to applications at any time without the increase of risk. Before you start big transformation projects or a cloud migration, make sure these changes won’t take down your entire organization.
There's a lot to gain from cloud computing, but success requires a thoughtful and enterprise focused approach. Cloud computing decouples data and information from the infrastructure on which it lies. A process that is a LOT more involved than dragging some folders from your desktop to a shared drive. Cloud computing as a mission transformation activity, not a technological one. As an organization moves from local information hosting to the cloud, one of the most important challenges is addressi...
What's the role of an IT self-service portal when you get to continuous delivery and Infrastructure as Code? This general session showed how to create the continuous delivery culture and eight accelerators for leading the change. Don Demcsak is a DevOps and Cloud Native Modernization Principal for Dell EMC based out of New Jersey. He is a former, long time, Microsoft Most Valuable Professional, specializing in building and architecting Application Delivery Pipelines for hybrid legacy, and cloud ...
Companies have always been concerned that traditional enterprise software is slow and complex to install, often disrupting critical and time-sensitive operations during roll-out. With the growing need to integrate new digital technologies into the enterprise to transform business processes, this concern has become even more pressing. A 2016 Panorama Consulting Solutions study revealed that enterprise resource planning (ERP) projects took an average of 21 months to install, with 57 percent of t...
Microservices are increasingly used in the development world as developers work to create larger, more complex applications that are better developed and managed as a combination of smaller services that work cohesively together for larger, application-wide functionality. Tools such as Service Fabric are rising to meet the need to think about and build apps using a piece-by-piece methodology that is, frankly, less mind-boggling than considering the whole of the application at once. Today, we'll ...
In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
Hybrid IT is today’s reality, and while its implementation may seem daunting at times, more and more organizations are migrating to the cloud. In fact, according to SolarWinds 2017 IT Trends Index: Portrait of a Hybrid IT Organization 95 percent of organizations have migrated crucial applications to the cloud in the past year. As such, it’s in every IT professional’s best interest to know what to expect.
Both SaaS vendors and SaaS buyers are going “all-in” to hyperscale IaaS platforms such as AWS, which is disrupting the SaaS value proposition. Why should the enterprise SaaS consumer pay for the SaaS service if their data is resident in adjacent AWS S3 buckets? If both SaaS sellers and buyers are using the same cloud tools, automation and pay-per-transaction model offered by IaaS platforms, then why not host the “shrink-wrapped” software in the customers’ cloud? Further, serverless computing, cl...
In the decade following his article, cloud computing further cemented Carr’s perspective. Compute, storage, and network resources have become simple utilities, available at the proverbial turn of the faucet. The value they provide is immense, but the cloud playing field is amazingly level. Carr’s quote above presaged the cloud to a T. Today, however, we’re in the digital era. Mark Andreesen’s ‘software is eating the world’ prognostication is coming to pass, as enterprises realize they must be...
Colocation is a central pillar of modern enterprise infrastructure planning because it provides greater control, insight, and performance than managed platforms. In spite of the inexorable rise of the cloud, most businesses with extensive IT hardware requirements choose to host their infrastructure in colocation data centers. According to a recent IDC survey, more than half of the businesses questioned use colocation services, and the number is even higher among established businesses and busin...