Invoking WebServices using Axis2 SMS Transport
SMS Transport currently have two SMS implementations
SMPP protocol implementation
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
Invoke a in only Web Service operation using a SMS
Invoke a in out Web service operation and receive a reply
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
Add Runtime Libs to Axis2 to Start with SMS Transport
Configure Axis2
Deploy our Simple service
Start Axis2
invoke service using a SMS.
Adding Runtime libs
add following file to the Axis2-HOME/lib directory
axis2-transport-sms-1.0.0.jar
axis2-transport-base-1.0.0.jar
smslib-3.4.1.jar
mail-1.4.jar
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
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
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.
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
the steps 1,2 on my first post are correct?
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.
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.
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)
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.
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)
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.
[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
Then i change the port 8084 to 8080. then previous errors are generated.
Now two ports 8080 and 8084 are blocked.
http://edn.embarcadero.com/article/31915
Use the installation guide in above article
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
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...
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.
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.
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.
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.
yeah it worked... :) thnx again.
cheers.
keep blogging brother !!!
nice work.
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
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
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
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
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