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

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

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

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

Michael Juntao Yuan

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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



9.4 SMS from the Back End


The WMA enables mobile Java peers to communicate with each other via SMS. SMS is also often used to deliver enterprise information from backend servers to mobile users. For example, a stock price monitoring server could send price alerts to mobile subscribers. In some countries (e.g., China), SMS has become a major micro-payment mechanism for mobile commerce services and small scale Web sites. SMS-based transactions can be traced to individual phones and users. The wireless carriers can act as the middleman to provide user authentication and billing services.

To handle SMS on server computers, we could develop a J2SE/J2EE WMA implementation that uses a modem or TCP/IP connection to interact with a wireless carrier's SMS Center (SMSC). In fact, the "Generic Connection Framework Optional Package for J2SE" (JSR 197) provides a GCF implementation for J2SE and hence allows the WMA to be ported to Java platforms beyond J2ME.

But such an enterprise server-compatible WMA implementation is not available today. The following sections briefly introduce you to two Java SMS tools that are already available for enterprise markets.


9.4.1 The jSMS API


Object XP's jSMS (v1.6) package provides an easy-to-use Java SMS API. It runs on a J2SE computer (a standard PC). In order for the PC to send and receive any SMS message, it has to be connected to a general mobile phone network using one of the two following techniques:


Email SMS Gateways


Some wireless carriers open email interfaces to their SMS services. Each phone number is associated with an email address. If you send a message to that address, it will be delivered to the phone as an SMS message. We can potentially use the JavaMail API to send messages programmatically from the back end. However, the email gateways do not provide a mechanism to receive SMS messages from the back end.

The PC can connect to a GSM phone via a serial port. jSMS passes outgoing SMS messages to the phone, and the phone sends them out. When a new SMS message comes in, the phone sends a signal through the serial port, and a monitoring jSMS server thread receives the message. This mode allows you to quickly incorporate SMS functionality into backend applications.

If you have an account with an SMSC, the jSMS application running on your PC can connect to that SMSC via a modem, an ISDN line, or a TCP/IP connection. This mode is designed to handle large numbers of messages.

Please refer to the jSMS Web site (see "Resources") for developer kit and sample code examples.



9.4.2 The Simplewire Java SMS SDK


Simplewire is a leading wireless messaging solution provider. The Simplewire Wireless Messaging Protocol Server relays messages between your server application and wireless networks. Those servers provide such enterprise features as logging, monitoring, and caching. They are also highly extendible.

You can purchase and run your own messaging protocol servers. But most users can simply use the servers from Simplewire's Wireless Messaging Network, which have access to carriers of over 300 networks in 118 countries. The Wireless Messaging Network charges a usage fee that varies based on SMS message volumes.

Simplewire's client SDK (v2.4) contains the necessary library and interfaces to interact with its messaging protocol servers. The SDK is available on multiple programming platforms, including Java. Please refer to the Simplewire Web site (see "Resources") for more information and code examples.


9.4.3 The Nokia Mobile Server Services SDK


If you are interested in sending and receiving MMS messages from the back end, the Nokia Server Services SDK (v1.2) is the perfect tool. The SDK include the following components.

Nokia Mobile Server Services Emulator: This is a J2EE-based (JBoss, Tomcat and Axis) PC emulator for Nokia mobile servers for wireless carriers. The emulated services are the MMSC Server, Delivery Server, Presence Server and Terminal Management Server. The MMSC server is responsible for MMS messaging. This tool is essential for development since wireless carriers rarely open their live servers to developers.

Nokia Mobile Server Services API and Library: This is a set of Java API libraries to access Nokia mobile servers. For the MMSC server library, it supports both Nokia's External Application InterFace (EAIF) and the 3GPP standard MM7 protocol. The API supports message composition, sending and receiving.

MMS Terminal Emulator Support: This tool emulates MMS handsets on PCs. It allows developers to test MMS applications without the expensive live network.

Nokia Mobile Server Services Documentation: It contains installation instruction, configuration guide and JavaDoc for the emulators and Java API libraries.


Listings 9.6 and 9.7 illustrate how to send and receive MMS messages from a backend Java application.

Listing 9.6. Sending an MMS message using the Nokia Java library



// Retrieve the following from the database
String qid;
String question;
String attachments[] = {
urlPrefix + "png/" + qid + ".png",
urlPrefix + "midi/" + qid + ".mid"
};
// creates engine for sending messages
factory = MMSDriverFactory.getInstance(args[1]);
engine = factory.createEngine();
engine.connect();
// Construct the message
toBeSendMsg = factory.createMMSMessage(attachments);
toBeSendMsg.setContentType(MimePart.CT_MULTIPART_MIXED);
//add the text
ContentPart cp = new ContentPart();
cp.setCharEncoding("UTF-8");
cp.setContent(question, "text/plain");
toBeSendMsg.getMultipart().addPart(cp);
toBeSendMsg.setTO(new MMSAddress("7650/TYPE=PLMN"));
toBeSendMsg.setFROM(new MMSAddress("1234/TYPE=PLMN"));
toBeSendMsg.setSubject("Trivia question");
// sends the message
engine.send(toBeSendMsg);
engine.disconnect ();

Listing 9.7. Receiving an MMS message using the Nokia Java library


// Creates engine for receiving messages
factory = MMSDriverFactory.getInstance(args[2]);
engine = factory.createEngine();
engine.connect();
System.out.println("Waiting for MMS ...");
receivedMsg = engine.receive();
// Print out or do something else with the reply message
System.out.println("FROM: " + receivedMsg.getFROM());
System.out.println("SUBJECT: " + receivedMsg.getSubject());
String submittedAnswer = (String) receivedMsg.getMultipart().
getBodyPart(0).getContent();
System.out.println("BODY: " + submittedAnswer);
engine.disconnect();


9.4.4 Standardize the Serverside Messaging API


The "Server API for Mobile Services: MessagingSAMS: Messaging" (JSR 212) is a community effort led by Nokia to standardize serverside SMS/MMS APIs. Its goal is to develop a high-level, protocol-independent J2SE/J2EE API for mobile messaging. Due to the abstract nature of the API, its implementation must provide a plugin framework (Service Provider Interface, SPI) that allows carriers and vendors to supply their own proprietary protocol and message handlers. The reference implementation of this specification will be provided by Nokia and licensed free of charge. The reference implementation will support common standard SMS/MMS protocols by default. This is definitely an important JSR to watch out for.


/ 204