Monday, January 28, 2013

[WSO2 ESB] Sending SMS Alerts for failures



SMS Notifications has become a popular feature for many services.
Isn't it nice if you can get a SMS Alert for a failure in ESB server?
In this post I am discussing how we can send a SMS Alert for a system failure in WSO2 ESB.

Required materials


* Axis2 SMS Transport binary. (download from here)
The Axis2 SMS Transport enables SMPP protocol support for Axis2. It allows Axis2 to connect to a SMSC and send/receive sms. Apart from that it also has a GSM implementation which we can use to connect to a modem and send/receive sms over it.
Please visit [1] for more information.

* JSMPP 2.1.0 binary (download from here)
JSMPP is a java implementation of SMPP protocol. It provides an API to communicate with a SMSC.
Please visit [2] for more information.

* A SMSC Simulator
SMSC Simulator is an application which can be act like a SMSC. Using a simulator we can test our scenario without having access to a real SMSC. For the real production servers we have to use a real SMSC. A simulator is good enough for us for now. I am going to use logica SMSC Simulator for this tutorial.
Download and setup the Simulator following the instruction given at [3].

Now let's move on to the steps.

Step 1

Copy following libraries to $ESB_HOME/repository/components/lib directory.
axis2-transport-sms-1.0.0.jar
jsmpp-2.1.0.jar

Step 2

Enable SMS Transport by adding following configuration under “Transport Senders” section in axis2.xml.
axis2.xml is located at $ESB_HOME/repository/conf/axis2 directory in WSO2 ESB 4.5.x.

    
    
    esb1
    esb123
    localhost
    2775
    ESB1
    

Please refer to [1] to find more details on above parameters.

Step 3

Goto SMSC Simulator directory. You should have following 3 files at there.
smpp.jar
smscsim.jar
users.txt

Edit the users.txt file and add following name-value pairs to it.

name=esb1
password=esb123
timeout=unlimited

Note that ‘name’ is the ‘systemId’ parameter which we have specified at sms transport sender configuration.

Start SMSC Simulator by executing the following command.
java -cp smpp.jar:smscsim.jar com.logica.smscsim.Simulator

You will see a screen like follows.



Enter 1 for the prompt to start simulation.
Enter 2775 as the port number. Note that it is equal to the port which we specified in sms transport sender configuration.

You will see the “Starting listener... started.” log on the console.

Now leave the SMSC Simulator running and let’s go back to configure the ESB server.

Step 4

Start the ESB server and create a proxy service with the following configuration.

   
      
         
$1

Let me describe the proxy service configuration in brief.

This configuration is very much similar to the ESB sample 150 configuration [4]. The only difference is, this has a fault sequence specified.
Fault sequence is triggered whenever some failure occurs in the mediation flow.
Here at the fault sequence, we are constructing the message which is to be sent as a SMS using the payload factory mediator.
Error message is extracted and set to the sms body from the ERROR_MESSAGE property.
Finally message is sent over sms transport using an Address Endpoint having the following uri.
sms://94777179968"
94777179968 is the phone number which sms has to be sent.

Step 5

Now let’s run and see how this scenario works.

Start the sample Axis2 server and deploy the SimpleStockQuoteService.
Please refer to [5] for find how to do it.

Now let’s execute the stock quote client by requesting for a stock quote on the proxy service as follows:
ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy

Refer to [6] to find more information on sample clients.

You will see the following log get printed on the Simple axis2 server console.
samples.services.SimpleStockQuoteService :: Generating quote for : IBM

And following get printed on the sample client shell.
Stock price = $98.58846106288853

So that is the success case.

Step 6

Now let’s stop the sample Axis2 server and execute the client again.
ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy


Since sample Axis2 server is not running, SimpleStockQuoteService will not be available at this moment. So the Endpoint will get suspended and the fault sequence will get executed.
A sms containing the error message will be sent to SMSC server.

You will see the following log get printed on the SMSC server.

08:35:05 [sys] new connection accepted
08:35:05 [] client request: (bindreq: (pdu: 33 2 0 1) esb1 esb123  52 (addrrang: 0 0 ) )
08:35:05 [esb1] authenticated esb1
08:35:05 [esb1] server response: (bindresp: (pdu: 0 80000002 0 1) Smsc Simulator)
08:35:05 [esb1] client request: (submit: (pdu: 204 4 0 2) (addr: 0 0 ESB1)  (addr: 0 0 94777179968)  (sm: msg: Alert..! Error In StockQuoteProxy, Connection refused or failed for : localhost/127.0.0.1:9000, IO Exception occured : Connection refused)  (opt: ) )
08:35:05 [esb1] putting message into message store
08:35:05 [esb1] server response: (submit_resp: (pdu: 0 80000004 0 2) Smsc2001 )

In the SMSC command prompt enter 5 to view list of messages.
You will see the sms sent from the ESB server as follows.



For this post I have used the SMPP implementation of Axis2 SMS Transport. You can use the GSM implementation of it also to test this. Please refer to blog post[7] written by Charith to find how to use GSM implementation. And also he has written a comprehensive post [8] on Axis2 SMS transport.

[1] http://ws.apache.org/commons/transport/sms.html
[2] http://code.google.com/p/jsmpp/
[3] http://opensmpp.logica.com/CommonPart/Introduction/Introduction.htm#simulator
[4] http://wso2.org/project/esb/java/4.0.3/docs/samples/proxy_samples.html#Sample150
[5] http://wso2.org/project/esb/java/4.0.3/docs/samples_setup_guide.html#Starting
[6] http://wso2.org/project/esb/java/4.0.3/docs/samples_setup_guide.html#Using
[7] http://charithwiki.blogspot.com/2009/12/invoking-webservices-using-axis2-sms.html
[8] http://charithwiki.blogspot.com/2009/06/axis2-sms-transport.html

Thursday, April 28, 2011

GSOC 2011 and Eclipse ECF Salvo



I got selected for the Google Summer of code this year. We have 27 students from University of Moratuwa. 23 out of those 27 are from the Department of Computer Science and Engineering. I submitted three proposals for three mentoring organizations (The Eclipse Foundation, Universal Subtitles and Creative Commons). I am very happy that all three proposals got accepted by the respective organizations. I gave my preference to the Eclipse Foundation. “ECF Salvo, UI Integration in the workbench” is the title of the project.



ECF: Salvo, the Eclipse NNTP/Newsreader Project
UI Integration in the workbench




The Salvo Project
The Salvo project can be used to communicate through newsgroups. It provides an underlying decoupled API to access news servers and provide offline storage of newsgroup articles.
 
Salvo can be used for accessing newsgroups and posting and reading articles. Several enhancements, not found in traditional newsreader programs have been implemented in Salvo such as subject highlighting for easy recognition of thread participation and offline reading.

UI Integration in the workbench
Currently Salvo is available as a RCP application. The main goal of this project is to provide the salvo functionality within the eclipse workbench.
Following are the key features in UI integration to eclipse workbench.

1. Let the user ask a question right from the workbench
Users can ask questions from experts directly from the eclipse workbench rather than going outside (to a web browser) the eclipse IDE. This is a value added feature for the Eclipse IDE.

2. Provide a pop up and a status bar notification when a reply is received.
This feature will allows the eclipse user to more focus on their work with the eclipse IDE reducing the overhead of going outside the IDE and check for replies.

3. Provide a view which displays digests of all the articles that are of the interest of user.
This view contains,
All the recent articles
Replies to threads that the user participates in

4. Provide a perspective for Salvo in eclipse workbench.
Whenever user wants to browse through articles he/she can simply switch to that perspective. And users can switch back to their working environment by simply changing the perspective.

5. Enable a way for people to create an eclipse user id within the workbench.
 This feature makes it very easy for the eclipse user to get a userid and a password for accessing the newsgroups and bugzilla.

6. Provide a way for other projects to hook their newsgroups into Salvo.
This will allows other projects to hook their newsgroup into the Salvo by using the exposed extension point. The extension point would make it possible for other projects to connect the projects namespace to the projects newsgroup.
 When a view or an editor of a particular project is active and if the user selects the “Ask a question” option from the workbench, salvo automatically figures out the newsgroup to post the question.

More information of this project is available at http://wiki.eclipse.org/Newsreader/Salvo_UI_Integration_in_the_workbench

Sunday, April 17, 2011

Make your favorite add-on compatible with Firefox 4

Last month Mozilla released the version 4 of their Firefox web browser. Even though it has many exciting features, one of the key issues that the users has to face in upgrading to this new version is most of their favorite add-ons are not compatible with the new version. Some users hesitate to use this new version simply because of this reason. So I decided to write this post to address the people who are having that issue.

Follow the following steps to make your add-on compatible with FF4.

1. Download the extension file (.xpi file)





2. Open the downloaded .xpi file using an archiving tool.



3. In the archive locate the install.rdf file and open it using a text editor.
4. Locate the maxVersion tag. In the example image it is shown in red color.



5. Change the maxVersion to 4.0.* or to a higher version.

6. Save the file and update the archive.

7. Now we are ready to go.
Drag and drop the modified .xpi file to Firefox window and install it.