Using core telecom network features to develop web applications: Part 2: Using REST style APIs

Traditionally, building telecom applications implied dealing with telecom network complexities and having technical skills on telecom protocols such as SMPP, MLP, and Parlay. This two-part article describes how a third-party application developer can build value-added services that leverage core telecom features that are available in the service provider’s network, without having those programming skills. This article, Part 2, discusses different ways of developing telecom applications with ease by using REST style APIs that are exposed by IBM® WebSphere® Telecom Web Services Server (TWSS).

Share:

Raghunath Nair (raghunath.nair@in.ibm.com), Principal Software Engineer, I.B.M.

author photoRaghunath E. Nair is a principal software engineer in the IBM India Software Lab, in Bangalore. He joined IBM in 2006. His most recent role has been in design, development, and support of software for telecom for IBM WebSphere software, including IBM WebSphere TWSS and IBM WebSphere IMS Connector. His areas of expertise are middleware integration, SOA, web services, and telecom. He co-authored Using WebSphere Message Broker as an ESB with WebSphere Process Server in the IBM Redbooks series and has a Bachelor of Technology degree in Electronics and Communications from the University of Calicut.



Chandrashekar Naik (chandrashekar@in.ibm.com), Staff Software Engineer, I.B.M.

author photoChandrashekar B. Naik is a staff software engineer in the IBM India Software Lab. He joined IBM in 2004 and has experience in software design, development, and testing. His areas of expertise include Java, J2EE, and web services programming, including WebSphere Application Server, Telecom Web Services Server, Mobile Portal Accelerator, pervasive computing, and WebSphere software for telecom. He currently focuses on development, support, and testing of WebSphere Telecom Web Services Server. Chandrashekar is also a Sun-Certified Programmer and has a Bachelor of Engineering degree in Computer Science from Visveswaraiah Technological University, Belgaum.



29 March 2011

Also available in Russian Vietnamese

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

This scenario demonstrates how to develop a telecom web application by using the Ajax design approach, JavaScript Object Notation (JSON) data format, and REST style APIs exposed by the Telecom Web Services Server.

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

In this section, we demonstrate how to develop the application using Ajax technology for GUI, REST style APIs for accessing the telecom resources, and JSON data format for carrying the payload. The sample HTML page that is attached (see Downloads) demonstrates how to make an Ajax call to the REST resources, using JSON data object to TWSS. The part of the JavaScript that makes the call is discussed here (see the code in Listing 1).

In the JavaScript function, a handle to the browser-specific XMLHttpRequest object is obtained. A JSON message is formed by using the senderName, addresses, and message parameters obtained from the HTML page (only the addresses and message are mandatory parameters).

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
<script type="text/javascript">
function sendSMS()
{
	var xmlHttp= null;
	var url = "http://localhost:9089/ShortMessageService/services/JSON/sms";
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlHttp = new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }

	var senderName = document.getElementById('senderName').value;
	var address = document.getElementById('addresses').value;
	var message = document.getElementById('message').value;

	var addressArr = new Array();
	var addresses = address.split(/,/);
	for ( var i = 0; i < addresses.length; i++) {
		addressArr.push(addresses[i]);
	}

	//Create the JSON Object
	var jsObject = {"addresses": addressArr ,"senderName": "" 
			+ senderName + "","message": "" + message + ""};
	var jsSON = JSON.stringify(jsObject);
	
	xmlHttp.open("POST", "" + url + "", true);
	
	xmlHttp.onreadystatechange = function () {
		
  	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
       	my_JSON_object = JSON.parse(xmlHttp.responseText);
       
		if (my_JSON_object.messageId!=undefined) {
			alert("Response from Server:"+ my_JSON_object.messageId);
			document.getElementById("requestIdentifier").value = "";
			document.getElementById("dStat").innerHTML="";
		} 
		else if (my_JSON_object.result!=undefined) {
       	    document.getElementById("requestIdentifier").value = my_JSON_object.result;
    	   	my_JSON_object = JSON.parse(xmlHttp.responseText);
    	   	document.getElementById("dStat").innerHTML="";
		}
  	} 
	};
	
	xmlHttp.send(jsSON);
}
</script>

The code in Listing 2 shows the JavaScript function that demonstrates how to get the delivery status of the SMS sent.

Listing 2. JavaScript to call a getDeliveryStatus operation
<script type="text/javascript">
function getDeliveryStatus()
{
      var xmlHttp= null;
      var url = 
      "http://localhost:9089/ShortMessageService/services/JSON/smsDeliveryStatus";
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
                 xmlHttp=new XMLHttpRequest();
          }
      else
          {// code for IE6, IE5
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }

      var reqId = document.getElementById('requestIdentifier').value;
      xmlHttp.open("POST", ""+ url +"", true);

      var jsObject = {"requestIdentifier": + reqId +""};
	
      var jsSON = JSON.stringify(jsObject);
      xmlHttp.open("POST", ""+ url +"", true);
	
      xmlHttp.onreadystatechange = function () {
                  if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
                          xmlNode = JSON.parse(xmlHttp.responseText);

                          if (xmlNode.messageId!=undefined) {
                          alert("Response from Server:"+ xmlNode.messageId);
                          document.getElementById("dStat").innerHTML="";
                        } 
                        else
                                {

               var innerHTML = '<table border=\'2\' >' +
               '<tr> <th> address </th> <th> Delivery Status</th> </tr>' ;
               for (var i = 0 ; i < xmlNode.result.length ; i++) {
                                var item = xmlNode[i];
                                innerHTML += '<tr>' +
                                '<td> ' + xmlNode.result[i].address + '</td>' +
                                '<td> ' + xmlNode.result[i].deliveryStatus + ' </td>' +
                                '</tr>';
               }
               innerHTML += "</table>";
               document.getElementById("dStat").innerHTML = innerHTML;
               }
               }
               };
               xmlHttp.send(jsSON);
}
</script>

Note:
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

About OneAPI

"The GSMA OneAPI initiative defines a commonly supported set of lightweight and web friendly APIs to allow mobile and other network operators to expose useful network information and capabilities to web application developers. It aims to reduce the effort and time needed to create applications and content that is portable across mobile operators."
Source: GSMA OneAPI website. A link to it can be found in the Resources section of this article.

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 + "&notifyURL=" + 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));

Note:
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:

  1. Install the IBM WebSphere Telecom Toolkit v7.1 on Rational Application Developer v7.5 or later.
  2. Launch Rational Application Developer.
  3. 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.
  4. Review the prerequisite instructions by clicking the Setup Instructions link.
  5. Import the sample,
  6. Import the Dojo toolkit to the WebContent folder in the OneAPISample project.
  7. To test these samples against the web services simulator, prefix /ParlayX21Web to 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
  8. 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.
  9. 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.

OneAPI sample page with sendSmsDemo widget
  1. In the Activity view of the Web Services Simulator, verify whether the SMS messages were delivered
Shows date, time, beginning of content

Larger view of Figure 2.

Tip:
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.


Summary

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.

Downloads information

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.

Downloads

DescriptionNameSize
Source code for Scenario 3TWSS_Usage_Sample_PI.zip115KB
Source code for Scenario 2groupSMS.zip2KB

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational, Industries, DevOps
ArticleID=643356
ArticleTitle=Using core telecom network features to develop web applications: Part 2: Using REST style APIs
publish-date=03292011