Enterprise J2ME Developing Mobile Java Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Enterprise J2ME Developing Mobile Java Applications [Electronic resources] - نسخه متنی

Michael Juntao Yuan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



9.5 Beyond SMS: The IM Convergence


SMS by itself is a great text messaging system. However, a key problem that hinders SMS's adoption in the enterprise world is the lack of interoper-ability with other popular, TCP/IP-based IM systems. IM has become one of the killer applications of our age. Millions of users use IM applications from America Online, Yahoo!, and Microsoft every day, and their ISPs use the ownership of those IM networks as the basis for their premier monthly subscription fees. In the corporate world, IM applications have also become increasingly important: As of this writing, IBM and Microsoft have 230,000 and 50,000 corporate IM users respectively. Unified messaging brings obvious values to convenience-motivated mobile users. The ability to receive and process all communications in a single application on a single device is appealing. Converged messaging is the idea behind the new generation of devices like PDA phones.

However, communications providers are reluctant to work with competitors. For example, wireless carriers make a large portion of their profits from SMS usages. They are reluctant to provide interoperability with Internet IM services that could allow users to bypass expensive SMS services. It took major efforts to make U.S. wireless phone carriers make their SMS compatible with each other. Major Internet IM providers still block each other out of their networks. So, the convergence of mobile messaging is not likely to happen in the infrastructure level any time soon.

Fortunately, there are workarounds on a smaller application scale. For example, for enterprise applications that are used within controlled environments, we can actually control and converge all messaging functionalities. In the next several sections, we discuss how to do that.


9.5.1 Introducing Jabber


Before the grand-scale convergence can take place, we first have to invent a simple way to access all the incompatible Internet IMs. One way to do it is through the Open Source, standards-based Jabber Instant Messaging systems.

Jeremie Miller invented Jabber so that he could correspond with friends on different IM systems using a single GUI client. Jabber employs a really flexible and powerful set of messaging protocols. With the strong expressing power behind it, Jabber messages and administrative commands can be easily translated to interoperate with other IM systems. Jabber messaging servers are designed to be extendible. With proper plugins, they can interface with any other IM servers. Another important feature of Jabber is that it does not have a central server. Jabber servers can form P2P networks themselves. Each peer can talk with all other peers as if they were on the same network, creating a distributed but federated domain of Jabber networks. This approach has some important advantages:

There is no single point of failure. Any server failure only affects the client it serves. Even then, the client can be free to join other Sun networks and use another server. This makes the infrastructure much more reliable and scalable.

Identity management is conducted locally, which eliminates the feature of a controlling monopoly. An example is a closed IM system in a company: The company needs to have full control of the security yet still wants to allow its employees to access certain outside IM networks.


Today, Jabber goes far beyond its original goal of "scratching an itch." It becomes one of the most successful Open Source projects and is a widely used IM system in both consumer and enterprise sectors. The Jabber community itself has grown to more than 2 million strong. Jabber's underlying protocol, the Extensible Messaging and Presence Protocol (XMPP), has recently become an IETF standard.


Presence


A core feature of any advanced IM system is presence. Each user should be able to broadcast her status and availability to an authorized group of peers. Accurate and up-to-date information greatly improves the messaging efficiency. It adds value to the IM systems and opens doors to brand new applications. For example, in an IM-based customer support application, the customer can find out the currently available representatives and send requests only to them.


9.5.2 The Jabber Protocol: XMPP


XMPP describes XML streams over TCP/IP sockets. Unlike protocols such as HTTP, where there are headers, bodies, and attachments, conversations among Jabber clients and servers are completely expressed as XML documents. Key XML building blocks in the Jabber protocol include the message element, the presence element, and the iq (info/query) element.

The message element describes the messages to be exchanged.

The presence element is used to announce a peer's availability.

The iq element is to allow structured conversation. It can be used to pass administrative messages such as user registration, authentication, and roster query.


A simple Jabber session might look like the following (Listing 9.8).

Listing 9.8. A simple Jabber session



SEND: <iq type='set'>
<query xmlns='jabber:iq:auth'>
<username>mjy</username>
<password>secret</password>
<resource>phone</resource>
</query>
</iq>
RECV: <iq type='result' id='sessionid' />
NOTE: Now we have the session
SEND: <presence>
<status>Online</status>
</presence>
NOTE: ... as time passes ...
RECV: <message id='1' to='juntao@ut/home' from='ju@ut' type='chat'>
<thread>12345ABCDE</thread>
<body>What's up</body>
</message>
NOTE: send/receive more messages ...

Of course, the complete Jabber specification is much more than those simple elements. There are many optional attributes for each element. Complete Jabber coverage is beyond the scope of this book. Please see the "Resources" section for more information on this subject. Now, we need to check out Jabber client libraries that run on the J2ME platform.


9.5.3 The KVMJab Jabber Library


Al Sutton's KVMJab (v1.0) is a Jabber library that runs on MIDP v1.0 and above. It is an Open Source project but requires a $1,000 donation and 1 percent of after-tax profits if you include the library in a commercial product.

In the KVMJab library, the JabberStream class represents a permanent TCP/IP connection from device to a Jabber server. It is instantiated with a connector object.


JabberStream stream = new JabberStream(
new meConnector(ServerName, ServerPort) );

Note

The KVMJab library also works in J2SE environments. However, since J2SE does not support the J2ME GCF, a new connector object is required. You can just replace the meConnector class to seConnector.

The stream object can be used to send messages or presence documents. Examples are illustrated below.


// How to compose and send a presence
Presence presence = new Presence();
JabberDataBlock bloc = new JabberDataBlock("status", null, null);
bloc.addText("available");
presence.addChild(bloc);
stream.send(presence);
// How to compose and send a message
Message mesg = new Message("juntao@ut/home", "hello");
stream.send(mesg);

Since a Jabber client reacts to incoming messages, it makes sense that the stream uses a listener object to handle event-triggered callback functions. Any listener object must implement the JabberListener interface and register itself with the stream object using the setJabberListener() method. The JabberListener interface declares three methods.

The beginConversation() method describes what to do when the stream first connects. It often performs login.


public void beginConversation() {
try {
Login login = new Login("user name", "password", "resource");
stream.send(login);
} catch (Exception e) {
// handles exception
}
}

The connectionTerminated() method describes what to do when a connection is dropped.

The blockArrived() method holds the core business logic. The stream caller passes the incoming XML document as a JabberDataBlock object to this method. It needs to figure the nature of the document (is it an Iq or a Message document?) and send responses through the stream object.


Please refer to the examples in the KVMJab library for more advanced features.


9.5.4 Other Commercial Jabber Clients


In addition to Al Sutton's KVMJab, there are a number of commercial J2ME Jabber libraries or clients. Most of them use proprietary protocols, and some of them require proprietary mobile messaging servers. None of them makes the source available to the public.

The Antepo J2ME Jabber library connects directly to Jabber servers. Source code SDK license is available, but only binary redistribution is allowed.

The TipicME wireless proxy supports its proprietary J2ME-based Jabber clients. Source code SDKs are not yet commercially available.

The uppli J2ME Jabber client is available for co-branding with other vendors. The SDK is not available to developers.

Streampath provides a J2ME Jabber client, but no SDK is available.



What about the JXTA Network?


The JXTA project develops a generic P2P system that goes beyond simple messaging. JXTA peers can advertise themselves, discover others, and provide services to each other. The JXME project develops J2ME clients in the general JXTA networks through special proxy peers. For more information about the JXME architecture and APIs, please refer to its Web site (see "Resources").


/ 204