Skip to content

SMPP Connector Example

SMPP (Short Message Peer-to-Peer Protocol) Connector allows you to send an SMS through the WSO2 EI. It uses the jsmpp API to communicate with an SMSC (Short Message Service Center), which is used to store, forward, convert, and deliver Short Message Service (SMS) messages. jsmpp is a Java implementation of the SMPP protocol.

What you'll build

Given below is a sample scenario that demonstrates how to work with the WSO2 EI SMPP Connector and send SMS messages via the SMPP protocol.

The SMPP server in SMSC have all the ESME (External Short Messaging Entity) addresses. This is an external application that connects to a SMSC and the active connection. When you send an SMS to a destination, it comes to the SMSC. Then one of the modules in SMSC checks if the destination address is available or not. If it is available, it creates a connection object that is responsible for sending the SMS message. There are many SMPP gateways available in the world and now almost all the message centers support SMPP. It is not practical always to connect with real SMSC. However, in this scenario we will try it with SMSC simulator. Please refer the Setting up the SMPP Connector documentation.

The following sendSMSoperation is exposed via an API. The API with the context /send has one resource.

  • /send : Used to send SMS Message to the Short Message Service Center.

The following diagram shows the overall solution. There is an HTTP API that you can invoke with an HTTP call with JSON. The API is able to send a SMS for the request number in a JSON request with the message in JSON.

smpp connector example

If you do not want to configure this yourself, you can simply get the project and run it.

Configure the connector in WSO2 Integration Studio

Connectors can be added to integration flows in WSO2 Integration Studio, which is the tooling component of WSO2 EI. Once added, the operations of the connector can be dragged onto your canvas and added to your resources.

Import the connector

Follow these steps to set up the ESB Solution Project and the Connector Exporter Project.

  1. Open WSO2 Integration Studio and create an Integration Project. Creating a new Integration Project

  2. Right click on the project that you created and click on Add or Remove Connector -> Add Connector. You will get directed to the WSO2 Connector Store.

  3. Search for the specific connector required for your integration scenario and download it to the workspace.
    Search Connector in the Connector Store

  4. Click Finish, and your Integration Project is ready. The downloaded connector is displayed on the side palette with its operations.

  5. You can drag and drop the operations to the design canvas and build your integration logic. Drag connector operations

Add integration logic

First create an API, which will be where we configure the integration logic. Right click on the created Integration Project and select, New -> Rest API to create the REST API. Specify the API name as SmppTestApi and API context as /send.

Adding a Rest API

Configuring the API

Create a resource to send an SMS to the Short Message Service Center.

  1. Initialize the connector.

    1. Navigate into the Palette pane and select the graphical operations icons listed under SMPP Connector section. Then drag and drop the init operation into the Design pane.

      Drag and drop init operation

    2. Add the property values into the init operation as shown below. Replace the host, port, systemId, password with your values.

      • host : IP address of the SMSC.
      • port : Port to access the SMSC.
      • systemId : username to access the SMSC.
      • password : password to access the SMSC.
      • systemType [Optional] : It is used to categorize the type of ESME that is binding to the SMSC. Examples include “CP” (Content providers), “VMS” (voice mail system) and “OTA” (over-the-air activation system).
      • addressTon [Optional] : Indicates Type of Number of the ESME address.
      • addressNpi [Optional] : Numbering Plan Indicator for ESME address.

      Add values to the init operation

  2. Set up the sendSMS operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under SMPP Connector section. Then drag and drop the sendSMS operation into the Design pane.

      Drag and drop send operation

    2. In this operation we are going to send a SMS messages peer to peer using SMPP protocol. It provides a flexible data communications interface for transfer of short message data between a Message Centers, such as a Short Message Service Centre (SMSC), GSM Unstructured Supplementary Services Data (USSD) Server or other type of Message Center and a SMS application system, such as a WAP Proxy Server, EMail Gateway or other Messaging Gateway. Please find the send operation parameters listed here.

      • sourceAddress : Source address of the SMS message.
      • destinationAddress : Destination address of the SMS message.
      • message : Content of the SMS message.

      While invoking the API, the above three parameters values come as a user input.

      Drag and drop send operation

    3. To get the input values in to the API we can use the property mediator. Navigate into the Palette pane and select the graphical mediators icons listed under Mediators section. Then drag and drop the Property mediators into the Design pane as shown bellow.

      Add property mediators

      The parameters available for configuring the Property mediator are as follows:

      Note: That the properties should be add to the pallet before create the operation.

    4. Add the property mediator to capture the sourceAddress value. The sourceAddress contains Source address of the SMS message.

      • name : sourceAddress
      • expression : json-eval($.sourceAddress)

      Add property mediators sourceAddress

    5. Add the property mediator to capture the message values. The message contains content of the SMS message.

      • name : message
      • expression : json-eval($.message)

      Add values to capture message

    6. Add the property mediator to capture the distinationAddress values. The message contains content of the SMS message.

      • name : distinationAddress
      • expression : json-eval($.distinationAddress)

      Add values to capture distinationAddress

  3. Get a response from the user.

    When you are invoking the created API, the request of the message is going through the /send resource. Finally, it is passed to the Respond mediator. The Respond Mediator stops the processing on the current message and sends the message back to the client as a response.

    1. Drag and drop respond mediator to the Design view.

      Add Respond mediator

    2. Once you have setup the sequences and API, you can see the salesforcerest API as shown below.

      API Design view

    Note: The properties should be added to the pallet before creating the operation.

  4. Now you can switch into the Source view and check the XML configuration files of the created API and sequences.

    SmppTestApi.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <api context="/send" name="SmppTestApi" xmlns="http://ws.apache.org/ns/synapse">
        <resource methods="POST">
            <inSequence>
                <property expression="json-eval($.distinationAddress)" name="distinationAddress" scope="default" type="STRING"/>
                <property expression="json-eval($.message)" name="message" scope="default" type="STRING"/>
                <property expression="json-eval($.sourceAddress)" name="sourceAddress" scope="default" type="STRING"/>
                <SMPP.init>
                    <host>localhost</host>
                    <port>10003</port>
                    <systemId>kasun</systemId>
                    <password>kasun</password>
                    <systemType>SMS1009</systemType>
                    <addressTon>INTERNATIONAL</addressTon>
                    <addressNpi>ISDN</addressNpi>
                </SMPP.init>
                <SMPP.sendSMS>
                    <sourceAddress>{$ctx:sourceAddress}</sourceAddress>
                    <distinationAddress>{$ctx:distinationAddress}</distinationAddress>
                    <message>{$ctx:message}</message>
                </SMPP.sendSMS>
                <log level="full">
                    <property name="Message delivered sucessfully" value="Message delivered sucessfully"/>
                </log>
                <respond/>
            </inSequence>
            <outSequence/>
            <faultSequence/>
        </resource>
    </api>

    Get the project

You can download the ZIP file and extract the contents to get the project code.

Download ZIP

Tip

You may need to update the simulator details and make other such changes before deploying and running this project.

Deployment

Follow these steps to deploy the exported CApp in the Enterprise Integrator Runtime.

Deploying on WSO2 Enterprise Integrator 7

You can copy the composite application to the /repository/deployment/server/carbonapps folder and start the server. Micro Integrator will be started and the composite application will be deployed. You can further refer to the application deployed through the CLI tool. You can download the CLI tool from here from the Other Resources section. Make sure you first export the PATH as below.

  $ export PATH=/path/to/mi/cli/directory/bin:$PATH
  1. Log in to Micro Integrator using the following command.

    ./mi remote login
  2. Provide default credentials admin for both username and password.

  3. In order to view the APIs deployed, execute the following command.

    ./mi api show
Click here for instructions on deploying on WSO2 Enterprise Integrator 6
  1. You can copy the composite application to the /repository/deployment/server/carbonapps folder and start the server.

  2. WSO2 EI server starts and you can login to the Management Console https://localhost:9443/carbon/ URL. Provide login credentials. The default credentials will be admin/admin.

  3. You can see that the API is deployed under the API section.

Testing

Invoke the API as shown below using the curl command. Curl Application can be downloaded from [here] (https://curl.haxx.se/download.html).

Sample request

curl -v POST -d '{"sourceAddress":"16111", "message":"Hi! This is the first test SMS message.","distinationAddress":"071XXXXXXX"}' "http://172.17.0.1:8290/send" -H "Content-Type:application/json"
You will receive the messageId as expected response

{"messageId":"Smsc2001"}
Expected Response in SMSC simulator console

06:33:09 [sys] new connection accepted
06:33:09 [] client request: (bindreq: (pdu: 40 2 0 1) kasun kasun SMS1009 52 (addrrang: 1 1 ) ) 
06:33:09 [kasun] authenticated kasun
06:33:09 [kasun] server response: (bindresp: (pdu: 0 80000002 0 1) Smsc Simulator) 
06:33:09 [kasun] client request: (submit: (pdu: 106 4 0 2) (addr: 1 1 16111)  (addr: 1 1 071XXXXXXX)  (sm: msg: Hi! This is the first test SMS message.)  (opt: ) ) 
06:33:09 [kasun] putting message into message store
06:33:09 [kasun] server response: (submit_resp: (pdu: 0 80000004 0 2) Smsc2001 ) 
06:33:59 [kasun] client request: (enquirelink: (pdu: 16 15 0 3) ) 
06:33:59 [kasun] server response: (enquirelink_resp: (pdu: 0 80000015 0 3) ) 
06:34:49 [kasun] client request: (enquirelink: (pdu: 16 15 0 4) ) 
06:34:49 [kasun] server response: (enquirelink_resp: (pdu: 0 80000015 0 4) )

What's next

Top