Byron Kiourtzoglou

About Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.

Java API for Kannel SMS/WAP gateway

We are proud to present Java API for Kannel. You can use the API to :

  1. Send SMS to a single recipient
  2. Send SMS to multiple recipients (bulk SMS)
  3. Send SMS with priority
  4. Send WAP Push message to a single recipient
  5. Configure send rate (SMS/Second)

Below is an example use of the API

public static void main(String[] args) {

 SMSManager smsManager = SMSManager.getInstance();

 // We can change the prefetch size of the background worker thread
 smsManager.setSmsMessagesPrefetchSize(30);

 // We can change the send SMS rate
 smsManager.setSmsMessagesSendRate(65);

 try {

  // Send SMS to a single destination
  smsManager.sendSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", "receiver_mobile_number", "the_message");

  // Send SMS to a single destination with a specific priority and
  // send rate
  smsManager.sendSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", "receiver_mobile_number", "the_message", SMSManager.MESSAGE_PRIORITY_3);

  // Send SMS to multiple recipients
  List<string> recipientsGroupA = new ArrayList<string>();

  recipientsGroupA.add("receiver_mobile_number_1");
  recipientsGroupA.add("receiver_mobile_number_2");
  recipientsGroupA.add("receiver_mobile_number_3");
  recipientsGroupA.add("receiver_mobile_number_4");
  recipientsGroupA.add("receiver_mobile_number_5");

  smsManager.sendSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", recipientsGroupA, "the_message");

  // Send SMS to multiple recipients with a specific priority and
  // send rate
  List<string> recipientsGroupB = new ArrayList<string>();

  recipientsGroupB.add("receiver_mobile_number_1");
  recipientsGroupB.add("receiver_mobile_number_2");
  recipientsGroupB.add("receiver_mobile_number_3");
  recipientsGroupB.add("receiver_mobile_number_4");
  recipientsGroupB.add("receiver_mobile_number_5");

  smsManager.sendBulkSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", recipientsGroupB, "the_message", SMSManager.MESSAGE_PRIORITY_7);

  // Send a WAP Push request to a single mobile recipient
  smsManager.sendWAPPush("localhost", "8080", "receiver_mobile_number", SMSManager.WAP_PUSH_RECEIVER_TYPE_MOBILE, "the_message", "http://localhost", 3);

 } catch (Exception ex) {
   ex.printStackTrace();
 }

 // Stops the background worker
 // smsManager.stopSMSManagerWorker()

}

The API is hosted on Sourceforge. You can download it from here

Any comments are most welcome!

Have Fun!

Justin

Related articles :

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

6 Responses to "Java API for Kannel SMS/WAP gateway"

  1. biruk says:

    hey i had recently used ur api and it worked fine. my Q is does ur api receive msgs from kannel

  2. dhinesh says:

    Hi,
    i have tried this example didn’t work,..
    in port which number have to give… and from number is message center number or mobile no

  3. Ven says:

    this code is giving the below error… please help me…

    java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:357)
    at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:128)
    at sms.SMS.main(SMS.java:22)

  4. raj says:

    Hi Byron,

    im newbie in kannel, can you send me instruction on how you setup kannel and your configuration. or you just run on the default configuration.

    Thanks

Leave a Reply


1 × = five



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close