Invoking WebServices using Axis2 SMS Transport

In a previous blog I have explained the overview design of the Axis2 SMS Transport. Since Last week Axis2 Transport team announced Axis2 Transport 1.0 release in which SMS transport got released. I think its time to give some examples on how to use the SMS transport.

SMS Transport currently have two SMS implementations

  1. SMPP protocol implementation

  2. GSM implementation

where SMPP protocol implementation allow you to connect the axis2 to a SMSC and get messages form it. And GSM implementation allow you to connect a simple GSM modem to the computer that Axis2 is running and use that to send receive SMS form Axis2( its recommended not to use GSM implementation when your message traffic is higher than 6msgs per min).

SMS Transport allow Axis2 users to do following

  1. Invoke a in only Web Service operation using a SMS

  2. Invoke a in out Web service operation and receive a reply

  3. Use Axis2 client and send messages out as a SMS

In this blog I 'll discuss how to use SMS Transport to invoke a simple a Web Service using a RPC type SMS via GSM implementation

Environment :

OS: Ubuntu 9.04

JDK : 1.6.0

Axis2 Version : 1.5.1

Modem : Huawei E220

Following are the Steps that need to be taken

  1. Add Runtime Libs to Axis2 to Start with SMS Transport

  2. Configure Axis2

  3. Deploy our Simple service

  4. Start Axis2

  5. invoke service using a SMS.

Adding Runtime libs

add following file to the Axis2-HOME/lib directory

Now we need to add Java communication API libs needed for the SMS lib

go to jre home and goto lib/ext/ directory and add following files

  • comm.jar

  • libLinuxSerialParallel.so

  • libLinuxSerialParallel_g.so

Now we are Axis2 two is ready to start with Axis2 .

Configuring Axis2

Goto Axis2-HOME/conf folder where you find the axis2.xml file which is the configuration file used for Axis2 configuration.

Then add following to the Transport section.


SMS Transport Receiver configuration




<transportreceiver name="sms" class="org.apache.axis2.transport.sms.SMSMessageReciever">
<parameter name="smsImplClass">org.apache.axis2.transport.sms.gsm.GSMImplManager</parameter>
<parameter name="com_port">/dev/ttyUSB0</parameter>
<parameter name="gateway_id">modem.ttyUSB0</parameter>
<parameter name="baud_rate">115200</parameter>
<parameter name="manufacturer">HUAWEI</parameter>
<parameter name="model">E220</parameter>
</transportreceiver>

SMS Transport Sender configuration


<transportsender name="sms" class="org.apache.axis2.transport.sms.SMSSender">
<parameter name="smsImplClass">org.apache.axis2.transport.sms.gsm.GSMImplManager</parameter>
<parameter name="com_port">/dev/ttyUSB0</parameter>
<parameter name="gateway_id">modem.ttyUSB0</parameter>
<parameter name="baud_rate">115200</parameter>
<parameter name="manufacturer">HUAWEI</parameter>
<parameter name="model">E220</parameter>
</transportsender>


Now Axis2 is ready. Now lets write a Simple Axis2 Service


Deploy Axis2 Service


Following is the Sample POJO Axis2 Service Class I wrote to demonstrate this



package sample.sms.test;



public class SampleInOutService {


public String sayHello(String name) {

return "Hello " + name;
}


}

Make a service archive of this POJO class and put that in the Axis2-HOME/repository/services directory.

Start Axis2

Then Start Axis2 by going to Axis2-HOME/bin and executing the shell script axis2server.sh.

If every thing goes ok you will see a log like this at the end

[INFO] Version: 3.4.1

[INFO] JRE Version: 1.6.0_06

[INFO] JRE Impl Version: 10.0-b22

[INFO] O/S: Linux / i386 / 2.6.28-14-generic

[INFO] GTW: modem.ttyUSB0: Starting gateway, using Generic AT Handler.

[INFO] GTW: modem.ttyUSB0: Opening: /dev/ttyUSB0 @115200

[INFO] GTW: modem.ttyUSB0: GSM: Registered to home network.

[INFO] GTW: modem.ttyUSB0: MEM: Storage Locations Found: SM

[INFO] GTW: modem.ttyUSB0: Gateway started.

[Axis2] Started in Port :/dev/ttyUSB0

[INFO] [SimpleAxisServer] Started


Now we are done now we can invoke the sayHello operation by sending a SMS message to the modem

following is the SMS

SampleInOutService:sayHello:name=charith

send that SMS to the modems phone number and you will get a SMS saying Hello charith

You can use SMS Transport Mixing implementations. ex : send messages using SMPP and recive via GSM modem.

This Transport will be useful when your going to implement your EDA (Event driven architecture) since users will be able to generate events and/or get notifications of events via SMSs

More details of SMS Transport can be found at SMS Transport documentation

Comments

Mahbubur Rahman said…
sir, i read ur blog on" Invoking WebServices using Axis2 SMS Transport". In this blog u gave a sample example which for ububtu.But i want to do this in windows. After reading ur blog, i do the following.
1. in the apache-tomcat-6.0.18_base\webapps\axis2\WEB-INF\lib, i have added axis2-transport-sms-1.0.0.jar, axis2-transport-base-1.0.0.jar, smslib-3.4.1.jar, mail-1.4.jar

2. in the C:\Program Files\Java\jre6\lib\ext, i have added comm.jar, win32com.dll, javax.com.properties.

3. in axix2\web-inf\conf\axis2.xml, i add the configuration as you discussed in the blog.

4. create simple axis2 web service and deploy
But in the "http://localhost:8084/axis2/services/listServices" there are no service lists, it displays "internal server error"

So dear sir, if u see the problem i will be very greatful to u

Thanks
Mahbubur Rahman
Charith said…
Hi Mahbubur,
What is the port you have configured in the axis2.xml s servlet transport section?It should be 8084 which is the http port that tomcat is listening on.
Mahbubur Rahman said…
i changed
8084


port 8080 to 8084. but still m facing the error.

when i removed the followings from axis2.xml the error removed but if i added these agian the error occured.


org.apache.axis2.transport.sms.gsm.GSMImpIManager
modem.COM3
COM3
115200
SAGEM
my700x





org.apache.axis2.transport.sms.gsm.GSMImpIManager
modem.COM3
COM3
115200
SAGEM
my700x

please help ...
thanks
mahbub
Mahbubur Rahman said…
hello CharithWiki
the steps 1,2 on my first post are correct?
Charith said…
I was able to re generate your issue.After removing some libs.This looks like due to a missing lib in the class path.Can you sent the logs of the tomcat startup so that i can figure out which libs are missing.
Charith said…
Hi,

I think your issue is adding 3rd party libs needed for the SMS Transport.

http://smslib.org/download/
using above link you can download the SUN JavaComm v2 (Win32) libs. Download and extract it.in the ReadMe file in the extracted directory you will find the installation guides for windows.

I was able to run this in Windows with out a problem.
Mahbubur Rahman said…
hi
I have followed your instruction. As per readme file in the comm api, i have done, but the error same, "internal server error." i also set the class path

C:\>set CLASSPATH=C:\Program Files\Java\jdk1.6.0_18\lib\comm.jar;%classpath%

then

C:\>set CLASSPATH=C:\Documents and Settings\Mahbubur Rahman\.netbeans\6.5\apache-tomcat-6.0.18_base\webapps\axis2\WEB-INF\lib\smslib-3.4.5.jar;%CLASSPATH%

and then start the tomcat, but m facing the error.
Mahbubur Rahman said…
(part 2)

Mar 21, 2010 8:24:06 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /axis2 threw load() exception
java.lang.ClassNotFoundException: org.jsmpp.session.MessageReceiverListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.apache.axis2.transport.sms.SMSManager.basicInit(SMSManager.java:140)
at org.apache.axis2.transport.sms.SMSManager.init(SMSManager.java:66)
at org.apache.axis2.transport.sms.SMSMessageReciever.init(SMSMessageReciever.java:40)
at org.apache.axis2.engine.ListenerManager.init(ListenerManager.java:74)
at org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:449)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Charith said…
i think now see the problem. Look at the SMS transport configuration in axis2.xml

check the parameter name = "smsImplClass" is set correctly. here you should use the exact name i have given (Capital letters must be capital).

this goes same for all other parameters as well.
Mahbubur Rahman said…
i add java smpp api in the axis2\WEB-INF\lib

then the errors both in log and axis2/services/listServices has been solved.

It runs ok. But in apache,

[INFO] A transport-OUT initialization error: sms

this occurs and the following error

[INFO] System Id not set
org.apache.axis2.AxisFault: System Id not set
at org.apache.axis2.transport.sms.smpp.SMPPImplManager.setTransportInDetails(SMPPImplManager.java:115)
at org.apache.axis2.transport.sms.SMSManager.init(SMSManager.java:82)
at org.apache.axis2.transport.sms.SMSMessageReciever.init(SMSMessageReciever.java:40)
at org.apache.axis2.engine.ListenerManager.init(ListenerManager.java:74)
at org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:449)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Charith said…
Let me explain. SMS transport have two SMS implementations.SMPP implementaion that allows you to connect to a SMSC and sent recieve messages. and GSMImplementation that allows you to sent/resv messages using a GSM modem connected.

SMPP implementation is the default implementation.If you does not specify using "smsImplClass" parameter. Transport will think that you are using the SMPP implementation.

That's why you get that error asking jsmpp class.

Since you want the GSM implmentation to use. you need to correctly specify the parameter "smsImplClass"

Transport is looking for that name and load the implementation using that.If not it will try to load the SMPP implimentaiton.that's where you get the error.(you don't need to add jsmpp libs to use GSM implementation)

So look at your axis2 configuration file again for mistakes.
Mahbubur Rahman said…
Thanks i correct my configure file and after that when i run tomcat. the followings come and server gives a error msg that "starting tomcat is failed".

[INFO] SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported gateways.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
[INFO] Version: 3.4.5
[INFO] JRE Version: 1.6.0_18
[INFO] JRE Impl Version: 16.0-b13
[INFO] O/S: Windows XP / x86 / 5.1
[INFO] GTW: modem.COM3: Starting gateway, using Generic AT Handler.
[INFO] GTW: modem.COM3: Opening: COM3 @115200
Exception in thread "Thread-7" java.lang.ExceptionInInitializerError
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:68)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:111)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:186)
at org.smslib.Service$1Starter.run(Service.java:257)
Caused by: java.lang.RuntimeException: CommPortIdentifier class not found
at org.smslib.helper.CommPortIdentifier.(CommPortIdentifier.java:76)
... 4 more
Mahbubur Rahman said…
hello brother, the 8084 port have been blocked, when i want to start tomcat again the error msg is "Starting tomcat failed, the server port 8084 is already in use".

Then i change the port 8084 to 8080. then previous errors are generated.

Now two ports 8080 and 8084 are blocked.
Charith said…
That is because you have not installed javacomm in your system correctly.

http://edn.embarcadero.com/article/31915

Use the installation guide in above article
Charith said…
For your second question about blocking ports.

Look at the server.xml in tomcat configuration directory and make sure HTTP port that is configured to listen on is same as the Servlet transports port.

make sure ports you are using are not being use by the system
Mahbubur Rahman said…
hello
Thanks a lot.
it ok now, server is connected to gsm modem of the mobile phone. Then i send sms as following format:

SMSTest:hello:name=test

But the sms is received by the modem and marked as read msg, but the modem doesn't sent any reply.

pls help...
Charith said…
1st make sure that your connection allows you to sent SMS out or you have credit to send messages out.

Turn off any other applications that access the Modem. (ex: application that you use to view the inbox).

then start the axis2 and re try.If again it fails sent the console logs.
Mahbubur Rahman said…
same problem, i checked every thing, no error in server log, sms received but not delivered.
Charith said…
how do you know message is delivered?Do u use a software to view the inbox?

if yes exit it before starting Axis2

and still the issue is there try putting a System out in side the Service method to see that message is delivered to the Axis2 engine.

So we can figure out what is the cause of this behaviour.
Anonymous said…
hi charith,

i hv done allthe thing according to u said. i can invoke the service and i am getting the reply as well. but the problem is its return hello null; the argument i sent from the 4n not get in the service. if u have any idea that will be very helpful

udayanga.
Charith said…
Try using this SMS

SimpleSmsService:SayHello:args0=udaya

Looks like your service is not compiled in debug mode. so the argument nm will be reflected as args0. You can view the WSDL and see the the parameter name you should use.
Udayanga said…
thnx a lot for quick reply...

yeah it worked... :) thnx again.

cheers.

keep blogging brother !!!
nice work.
OrionPax said…
First at all Thanks.
your article was so instructive, please can you tell how to set a configuration for a SMPP for communicate to the SMSC setting the web service for listening waiting for a sms.
thnaks again in advance
PS. Sorry but English is not may mother tongue
Anonymous said…
Hi ,

I'm planing to write a blog on SMPP support and how to use this transport with WSO2ESB this week.Will update you once i'm done.

Its basically simple and same as using a GSM modem. Only thing is dependencies you have to put will be deferent.

you can refer to
http://ws.apache.org/commons/transport/sms.html
find the needed parameters.

and you need to put the jsmpp 2.0.1 jar and its run time dependencies to the AXIS2-HOME/lib
Charith said…
Hi ,

I'm planing to write a blog on SMPP support and how to use this transport with WSO2ESB THIS WEEK.Will update you once I'm done.

Its basically simple and same as using a GSM modem. Only thing is dependencies you have to put will be deferent.

you can refer to
http://ws.apache.org/commons/transport/sms.html
find the needed parameters.

and you need to put the jsmpp 2.0.1 jar and its run time dependencies to the AXIS2-HOME/lib
Udayanga said…
hi ayya,

is there a way to get the sender's phone number(i mean web service invoker's phone no) in side the web service ?

thanks.
udayanga
Charith said…
Hi Udayanga ,

You can get the senders Phone number and destination phone number from MessageContext Properties :

sms_sender and sms_destination

You can access the Current messageContext using MessageContext.getCurrentMessageContext() method.

Hope this helps

thanks,
Charith
Charith said…
Nice blog on using SMPP implementation of Axis2 SMS transport. http://mytecheye.blogspot.com/2013/01/wso2-esb-sending-sms-alerts-for-failures.html

Popular posts from this blog

WSO2 Enterprise Service Bus 4.0.0 Released!

Executing maven test with the ant run plugin--A Real experiance.

How to install OpenMPI-Java