We are proud to present Java API for Kannel. You can use the API to :
- Send SMS to a single recipient
- Send SMS to multiple recipients (bulk SMS)
- Send SMS with priority
- Send WAP Push message to a single recipient
- Configure send rate (SMS/Second)
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 :
getting following exception..I used same host,port,username and password as shown above...Any help?
ReplyDeletejava.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.SocksSocketImpl.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 com.a.Sms.main(Sms.java:15)
Hello Rohan,
ReplyDeletePlease check that you have configured and launched Kannel properly (including the WAP gateway configuration). You can find relevant information of the Kannel web site (www.kannel.org). It seams that you cannot connect (you do not have the appropriate rights) on port 8080 of your local server. Check if the server (kannel) is running and the port is accessible from the system account that runs your Java kannel API library.
BRs
I have received this error message:
ReplyDeletecom.javacodegeeks.kannel.api.SMSPushRequestException:Unknown command `/cgi-bin/sendsms'.Possible commands are
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:369)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:128)
at com.kannel.KannelSample.main(KannelSample.java:21)
@JAVA EXAMPLE
ReplyDeletePlease check that your Kannel Gateway server is up and running properly!
Please I need help...
ReplyDeletemy code is...
smsManager.sendSMS("192.168.109.128", "13003", "useruser", "userpass", "666", "123456789", "hello_world");
My kannel is running ok....
http://192.168.109.128:13000/status
Kannel bearerbox version `1.4.3'. Build `Apr 6 2010 13:54:50', compiler `4.4.3'. System Linux, release 2.6.32-28-generic, version #55-Ubuntu SMP Mon Jan 10 23:42:43 UTC 2011, machine x86_64. Hostname ubuntu.localdomain, IP 127.0.1.1. Libxml version 2.7.6. Using OpenSSL 0.9.8k 25 Mar 2009. Compiled with MySQL 5.1.41, using MySQL 5.1.41. Using native malloc.
Status: running, uptime 0d 0h 0m 47s
WDP: received 0 (0 queued), sent 0 (0 queued)
SMS: received 0 (0 queued), sent 0 (0 queued), store size 0
SMS: inbound (0.00,0.00,0.00) msg/sec, outbound (0.00,0.00,0.00) msg/sec
DLR: 0 queued, using internal storage
No boxes connected
SMSC connections:
SMPPSim SMPP:192.168.88.30:2775/2775:smppclient:VMA (online 47s, rcvd 0, sent 0, failed 0, queued 0 msgs)
My SMPPSim is running at 192.168.88.30:88 (I need this???)
But, the exception is the same...
java.net.ConnectException: Connection refused: connect
May be the configuration of the kannel??
group = core
admin-port = 13000
admin-password = coreadmin
smsbox-port = 13001
group = smsc
smsc = smpp
smsc-id = SMPPSim
host = 192.168.8830
port = 2775
receive-port = 2775
smsc-username = smppclient
smsc-password = password
system-type = VMA
group = smsbox
bearerbox-host = 127.0.0.1
sendsms-port = 13003
group = sendsms-user
username = useruser
password = userpass
default-smsc = SMPPSim
Hello Lizeth,
ReplyDeleteThere seems that no SMS box is connected to your Bearer box. Please check the "No boxes connected" statement returned by your status command. Prior using the Java API try using the HTTP API provided by Kannel gateway itself. If you can send SMS using it then the Java API should have no issues whatsoever. All in all it seems to me that you have not set up Kannel correctly. Please follow the instructions provided at Kannel site, check with the HTTP API that your configuration is correct and then use our Java API.
BRs
Hello, Justin.
ReplyDeleteThe SMS is sent via GET or POST (I need send in POST method)?
How can I send binary SMS?
Thank you!
Hi Justin!
ReplyDeleteGood to found your java api. I downloaded the jar(1.0.2) file and tried to run the jar using #java -jar kaneel_**** .I am getting error some thing like unable to find main class in MANIFEST.MF . When i checked there is no Main-Class entry . Can you please guide me to locate the classes and run the jar file .
Thank you!
Hello newbie,
ReplyDeleteYou cannot run the jar file. You can use the API as described in the relevant posts.
BRs
Hi,
ReplyDeleteI have sent a sms to kannel containing '@' char.
For example I sent "@ Test" but phone received something
like "i Test".
Is this kannel bug? If so, does anybody have a patch for it?