This is Part 2 of a two-part article that demonstrates how developers with limited programming skills can develop a telecom web application with ease by using REST style APIs exposed by IBM® WebSphere® Telecom Web Services Server, Version 7.1. Compared to the web services method described in Part 1, REST style invocation is much simpler, and there is no need to generate web service clients from the WSDL files. Part 1 covers Scenario 1: Creating a telecom application with web services (click the "View more content in this series link" under the summary of this article to read Part 1).
Scenario 2. Create a telecom web application with Ajax and JSON
The use case
- A retailer wants to send an advertisement to all its customers informing them of a seasonal offer. The retailer also wants to know the delivery status of these SMS messages.
- The retailer outsources this job to a third-party application provider, which needs to send bulk SMS messages, using a Web 2.0 telecom application.
Create the Web 2.0 application
The stringify method used here converts the JSON object into JSON text. A link to it can be found in the Resources section of this article.
The XMLHttpRequest is initialized through the open method. These are the parameters passed to this method:
- HTTP method to be used to send the request
- URL pointing to the REST resource.
Note: The IBM WebSphere Telecom Toolkit does not support a JSON payload. Instead, point the URL to the actual TWSS REST URI to test the same. See TWSS 7.1 documentation, Developing > REST Style Access Using HTTP > Interfaces, for more information on the available REST resources that support JSON. A link to it can be found in the Resources section of this article.
- Boolean value indicating whether the transaction is asynchronous
The sendSMS method sends the JSON object to the server using those parameters.
The onreadystatechange function is triggered every time that the ready state changes. It receives the response JSON object containing the messageId, which is the request identifier that identifies a specific SMS delivery request.
Now this messageId can be used to get the delivery status of the sent SMS.
Listing 1. Java script to call an SMS REST resource
The sample code provided will encounter cross-site scripting restrictions in case the script is hosted on a different server. To overcome this issue, you can choose either of these actions:
- Use a browser that does not restrict cross-site scripting. Caution: This might have security implications.
- Ensure that the script is running on the same server as TWSS.
Scenario 3. Create a telecom application using Java and OneAPI
Scenario 3 demonstrates the same use case as in Scenario 2. However, here, we demonstrate how to develop a telecom application using a simple Java program with the OneAPI REST resources exposed by TWSS v7.1.
TWSS 7.1 supports the OneAPI Version 0.9 spec, The data models supported include XML, JSON and form-url-encoded. Generally, the requests being form-url-encoded and the responses are always XML. See TWSS 7.1: Developing > REST Style Access Using HTTP > Interfaces for details on the services supported in TWSS 7.1, including SMS, TL, and Payment. A link to it can be found in the Resources section of this article.
The code in Listing 3 constructs the sendSMS operation with mandatory and optional parameters. Notice these elements:
- The URL is appended to the arguments to form the resource URL.
- The HTTPClient method’s execution method is invoked with a parameter of HTTPMethod to send the request to the TWSS REST URL.
- The response is received via the HTTPMethod’s getResponseBody method.
- After the sendSMS response is received, the messageID is retrieved from the response and a getDeliveryStatus is queried in a similar manner.
- The Message Delivery Status is displayed at the bottom.
Listing 3. Java code snippet to invoke a sendSMS operation
//initialize HTTPClient object org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient(); //construct the sendSMS request urlString = resourceURL + "?" + strAddressArr + "&message=" + strMessage + "&correlator=" + strCorrel + "¬ifyURL=" + strNotifyURL + "&senderName=" + strSenderName; //initialize PostMethod specifying target URL org.apache.commons.httpclient.methods.PostMethod postMethod = new org.apache.commons.httpclient.methods.PostMethod(urlString); //execute the postmethod and get the status of the HTTP response statusCode = client.executeMethod(postMethod); System.out.println("HTTP status code:"+ statusCode); //Read body of response into a string postResponse = postMethod.getResponseBody(); strResponseAsAString = new String(postResponse); System.out.println("SendSMS Response :" + strResponseAsAString); //Create URL string for getSmsDeliveryStatus. //The getMessageId method retrieves the messageIdentifer from sendSMS response XML urlString = resourceURL +"?messageId=" + getMessageId(strResponseAsAString); //initialize GetMethod specifying target URL org.apache.commons.httpclient.methods.GetMethod getMethod = new org.apache.commons.httpclient.methods.GetMethod(urlString); //execute getmethod and get the status of the HTTP response statusCode = client.executeMethod(getMethod); System.out.println("HTTP status code:"+ statusCode); //Read body of response into a string postResponse = getMethod.getResponseBody(); System.out.println("Message Delivery Status:" + new String(postResponse));
The entire Java code is provided as a Project Interchange in the Downloads section of this article. Make sure that OneAPIJavaClient project’s build path has a reference to the com.ibm.jaxws.thinclient_7.0.0.jar file available in RAD75Home\runtimes\base_v7\runtimes.
Scenario 4. Create a telecom application using sample Dojo widgets
TWSS 7.1 provides GSMA OneAPI specification v0.9-compliant RESTful interfaces in addition to existing web service interfaces. To complement these, REST style sample Dojo widgets have been included in the IBM WebSphere Telecom Toolkit. These sample Dojo widgets can be used within web application to access telecom network features. The sample includes widgets for these purposes:
- Terminal location
- Short Message Service
- Payment services
The widgets are built using the Dojo toolkit available in the Web Services Feature Pack for Rational Application Developer. If the Web Services Feature pack is installed, the Dojo libraries available in the feature pack can be used. If the feature pack is not installed, you can download the Dojo toolkit. A link to it can be found in the Resources section of this article.
Scenario 4 demonstrates the same use case as in Scenario 2. These sample widgets enable web pages to access core network features and make telecom application development really simple. These OneAPI Dojo sample widgets can be tested on the Telecom Web Services Simulator provided in the toolkit. Here is the setup process to install the REST samples:
- Install the IBM WebSphere Telecom Toolkit v7.1 on Rational Application Developer v7.5 or later.
- Launch Rational Application Developer.
- Load the samples into the Rational Application Developer workspace using the Import links from the Telecom Web Services Feature Samples page. You can reach that page by selecting Help > Samples > Samples > Technology Samples > Telecom Web Services Feature > Telecom Web Services Samples > One API Widget Sample.
- Review the prerequisite instructions by clicking the Setup Instructions link.
- Import the sample,
- Import the Dojo toolkit to the WebContent folder in the OneAPISample project.
- To test these samples against the web services simulator, prefix
/ParlayX21Webto the value of the endPoint attribute in the
<div>tag in each of the sample HTML files under the telcoSampleWidgets folder: OneAPISample > WebContent > dojo > telcoSampleWidgets. For example, this should be the endPoint of Short Message Service: /ParlayX21Web/ShortMessageService/services/REST/sms
- Deploy and run the WebSphere Simulator on IBM® WebSphere® Application Server Version 7.0 or later.
Note: These OneAPI sample widgets can be tested on the Web services simulator provided in the toolkit.
- Right-click and select OneAPISamples > Webcontent > dojo > telcoSampleWidgets > sendSmsDemo.html, and select Run As > Run on server.
This opens a web page with the OneAPI sendSmsDemo sample, as shown in Figure 1.
- In the Activity view of the Web Services Simulator, verify whether the SMS messages were delivered
See the IBM Education Assistant for the WebSphere Telecom Toolkit > Version 7.1 Update, which provides detailed steps on how to set up the sample Dojo widgets provided in Rational Application Developer. A link to it can be found in the Resources section of this article. Note: For the sample dojo widgets provided, it is assumed that they are served from the same server as TWSS. If not, cross-site scripting restrictions might apply.
The changing dynamics of the telecom industry and Web 2.0 are creating many interesting possibilities. Availability of telecom network capabilities through the ubiquitous HTTP interface, support for JSON and XML payloads, REST style APIs, and web service interfaces implies that it is easier for a third-party application developer to develop and deliver innovative telecom applications. This low entry barrier for web content providers, in turn, means better services for customers.
Description: Project Interchange with sample code
About the downloads
- The source code for Scenario 3 can be found in the TWSS_Usage_Sample_PI.zip file.
- The source code for Scenario 2 can be found in the groupSMS.zip file.
- Ensure that StartNotificationClient project’s build path has a reference to the com.ibm.ws.webservices.thinclient_7.0.0.jar file that is available in RAD75Home\runtimes\base_v7\runtimes.
- Ensure that OneAPIJavaClient project’s build path has a reference to the com.ibm.jaxws.thinclient_7.0.0.jar file available in RAD75Home\runtimes\base_v7\runtimes.
|Source code for Scenario 3||TWSS_Usage_Sample_PI.zip||115KB|
|Source code for Scenario 2||groupSMS.zip||2KB|
- Citations in this article:
- The stringify method used here converts the JSON object into JSON text.
- TWSS 7.1 documentation Developing > REST Style Access Using HTTP > Interfaces (SMS Interface)
- GSMA OneAPI website
- TWSS 7.1: Developing > REST Style Access Using HTTP > Interfaces
- The Dojo toolkit
- IBM Education Assistant for the WebSphere Telecom Toolkit > Version 7.1 Update
- GSMA OneAPI
- IBM Rational Application Developer Version 7.5 documentation
- IBM WebSphere Telecom Web Services Server Version 7.1 Information Center
- IBM WebSphere Telecom Toolkit, Version 7.1 Education Assistant
- Browse the Rational Application Developer for WebSphere Software page on developerWorks for links to technical articles and many related resources and explore the Information Center.
- Visit the Rational software area on developerWorks for technical resources and best practices for Rational Software Delivery Platform products.
- Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics.
- Attend a free developerWorks Live! briefing to get up-to-speed quickly on IBM products and tools, as well as IT industry trends.
- Watch developerWorks on-demand demos, ranging from product installation and setup demos for beginners to advanced functionality for experienced developers.
- Improve your skills. Check the Rational training and certification catalog, which includes many types of courses on a wide range of topics. You can take some of them anywhere, any time, and many of the "Getting Started" ones are free.
Get products and technologies
- Try Rational Application Developer for WebSphere Software, free.
- Evaluate IBM software in the way that suits you best: Download it for a trial, try it online, use it in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement service-oriented architecture efficiently.
- Join the Development Tools forum to ask questions and participate in discussions.
- Share your knowledge and help others who use Rational software by writing a developerWorks article. You’ll get worldwide exposure, RSS syndication, a byline and a bio, and the benefit of professional editing and production on the developerWorks Rational website.
- Follow Rational software on Facebook and Twitter (@ibmrational), and add your comments and requests.
- Ask and answer questions and increase your expertise when you get involved in the Rational forums, cafés, and wikis.
- Connect with others who share your interests by joining the developerWorks community and responding to the developer-driven blogs.
Dig deeper into Rational software on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Experiment with new directions in software development.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.