Web21C SDK: do less achieve more

Please see our important announcement.

Setting up an SMS Status Event Listener - Java example

Note: This is only one example of how to set up a messaging event listener. There are many other ways to achieve the same thing, using Java or any other programming language.

1. Set up your application server

In this example, the messaging event listener is a Java Servlet, which requires a Web Container or Application Server. This example will use Apache Tomcat, but you are free to use any Application Server.

Make a note of the port that your application server is listening on (Tomcat will prompt for the port number during installation). This example will use port 7070.

2. Look at source code and build WAR file

We'll now look at the example listener code. Find attached a zip file containing the Example Event Listener source code.

Unzip this onto your machine.

If you look under Eventing/src/com/bt/sdk/messaging/event you will see an EventServlet.java file. This is a simple example serlvet listener to help you get started. You can adapt this code later to suit your individual needs but for the time being we will leave this untouched. The default example code accepts messaging events and simply echoes them back in a response. (This will be useful to test it has deployed correctly later on).

To build the WAR file, you will need Apache Ant installed.

Navigate to the top level eventing directory where ever you have unzipped the directory structure and open a command prompt here. Then type in "ant"

eg: C:\Eventing>ant

ant command screenshot (click image to see full size)

This will now open the already written build.xml and run this to turn your java code into a deployable WAR file. The WAR file should be called BTSDKMessagingEventSample.war and found in Eventing/dist directory.

3. Deploy your generated WAR file

To deploy your WAR file you will need Tomcat started. Open up your web browser and enter http://localhost:<port number noted in step 2>

eg. http://localhost:7070

This should display a Tomcat front page as seen below:

tomcat frontpage screenshot (click image to see full size)

Now navigate to the "Tomcat Manager" link (found on the left-hand navigation bar). You may have to enter the username and password you set up. Now click the "Browse" button at the bottom of the loaded page where the caption reads "WAR file to deploy".

tomcat deploy screenshot (click image to see full size)

Navigate to the dist directory under Eventing/Dist where the WAR was created in step 2. Then click the deploy button. This will deploy the WAR in the tomcat web container automatically for you.

4. Manually Test the Listener

You can test the deployment by opening a web browser and typing in a sample event to the query string.

  eg: http://localhost:7070/BTSDKMessagingEventSample/EventServlet?message_id=1&message_recipient=me&message_state=Sent

You should get back a short response in the browser echoing what you sent in. It should look something like:

event browser screenshot (click image to see full size)

Your listening URL is made up of http://<host>:<port>/<war_name>/EventServlet/

In the example above when calling the sdk sendMessage operation with a URL you would enter: http://youripaddress:7070/BTSDKMessagingEventSample/EventServlet/

5. Manipulate your Event Listener

Ok - you now have a simple listener deployed which accepts event requests. Now you need to decide what you would like to do with the events you get. For example: you could populate a database with the new states, and then access them via a web site. You could write them out to a textfile. To do these things you simply edit the java file and repeat step 3 to step 5.

6. Extra Security

You can increase security by using secure HTTP (HTTPS) see How to Configure Tomcat to Allow SSL Requests. You can also make the service even more secure by adding your own unique key in the URL that you used to register for inbound events

eg: http://youripaddress:7070/BTSDKMessagingEventSample/EventServlet?someParam=myUn1queParam

This parameter will be sent back to you in the body of each HTTP POST event that BT sends to you. Your application can check this parameter to confirm it came from us.