Payday Loans Payday Loan


Author Archive

Kannel: Compile, Install, and Configure Open Source WAP and SMS Gateway

August 2nd, 2010 2 comments

I have recently worked an application where we needed to send and receive SMS messages. The application will receive a sms message, and return some business values to the client. It will also periodically push message to clients and update the status of their transactions. It become obvious that we need a gateway that could handle sms message between our applications and client’s handheld devices.

The application would be part of platform which includes asterisks(Open source PBX) and other great open source products. We needed to have an open source sms gateway to include the platform and that was one we came across the kannel. Kannel is a compact and very powerful open source WAP and SMS gateway, used widely across the globe both for serving trillions of short messages (SMS), WAP Push service indications and mobile internet connectivity. ”

I am going to layout the steps that I have followed to install, configure, and run some real world scenarios:

Compiling and Installation:

To compile and install the latest version of kannel on ubuntu 10.04 LTS follow these steps:

  $ cd  ~Download
  $ wget
  $ cd ..
  $ mkdir src
  $ tar xfz ../Downloads/gateway-1.4.3.tar.gz 
  //congures kannel to be installed on   /opt/kannel
  $ configure --prefix=/opt/kannel   
  //In my case after running the above command, it complain not finding one of the required library libxml12. 
  //I have downloaded and installed (compiled the src and installed) plus the following command
 // sudo apt-get install libxml2-dev
  $ make 
  $ make install

Like any great server application, for-example apache http, and Asterisk, comping and isntalling is the easy part. In order to use the system in a usefull way you need to tell the system how you want it to work and behave.
In kannel, there are several configuriton files that you need to understand and modify. you can find them /opt/kannel/gw/ (if you have followed my steps). If they are not already there, check “gw” folder with the following files
modems.conf, other_smskannel.conf, other_smskannel.conf, other_smskannel.conf, smskannel-ssl.conf, smskannel-ssl.conf in the compilation directory(~src/gateway-1.4.3/gw) and copy to /opt/kannel/gw

Most of the server softwares that comes with configuration, you can run and the system would run smoothlly but it may not behave as you expected. As you I have said before you need to modify the configuration files with your needs.
I usually runt they system with the default configurations and later tweak with my needs. Kannel comes with a test program which acts like SMSC. It is a fake SMSC. Fake SMSC is a simple protocol to test out Kannel. It is not a real SMS center, and cannot be used to send or receive SMS messages from real phones. So, it is ONLY used for testing purposes.

$ ls  /opt/kanne/sbin/
bearerbox  run_kannel_box  smsbox  wapbox

After you have compiled Kannel and edited configuration file for your taste, you can either run Kannel from command line or use supplied start-stop-daemon and run_kannel_box programs to use it as a daemon service.
Let us just test the system without any modification to the configuration files and use the fake SMSC for sending and receiving messages:

//starting the gateway
/opt/kannel$ sudo ./sbin/bearerbox  gw/smskannel.conf

//after the bearerbox, you can start either smsbox or wapbox
/opt/kannel$ sudo ./sbin/smsbox  gw/smskannel.conf

you need to start the bearer box before the other boxes. After that we can start the fake SMSC (please see the manual for details

test/fakesmsc -i 0.1 -m 100 "100 200 text nop" "100 300 text echo this"

With the above steps completed, you have a working system and sending/receiving messages between bearerbox, smsbox, and fakesmsc.
Let us now modify gw/smskannel.conf and configure the kannel to work with out GSM modem and interact with a web application.

Read more…

Categories: WAP and SMS Tags: , , ,

Model Validation with JSR 303, Spring Webflow and Spring MVC

February 8th, 2010 4 comments

Spring 3.0 supports the new JSR-303 validation. JSR-303 standardizes validation constraint declaration and metadata for the Java platform.  The following model object has its fields annotated with JSR-303 (javax.validation.*).

@Entity(name = "partner")
public class Partner extends NamedEntity implements Serializable {
	@javax.validation.constraints.NotNull(message = "partnerType must not be null.")
	private PartnerType partnerType;

	@javax.validation.NotEmpty(message = "Lanaguage can't be empty")
	private String language;
	@javax.validation.NotEmpty(message = "contact person can't be empty")
	private String contactPerson;


Spring 3.0 reference guide.

explains how to configure and use JSR-303 in Spring 3.0 , but there is no clear way of doing samething in Spring Webflow.

Model validation is needed whenever you want to bind a model with data from a form submitted by a user and with JSR-303, anytime you want to valide an bean class. In this post, I am going to explain how you can configure JSR-303 validator factory in spring context as a bean and use it in both Spring MVC and Spring Webflow.

Add the following bean in your mvc application context.

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

You could also get the default validator factory in controller or validator class.

   private Validator validator= Validation.buildDefaultValidatorFactory().getValidator();
  1. Spring MVC

In mvc, there are several ways that you can use the above validator in your web controller:

Assuming that you using annotation driven mvc/controller.

	<!-- Dispatches requests mapped to POJO @Controllers implementations -->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="webBindingInitializer">
			<bean class="">
				<property name="validator" ref="validator" />

if you are using the new mvc schema namespace.

<mvc:annotation-driven conversion-service="conversionService"  validator="validator"/> 

you can also dependency inject the validator to your controller

	@Autowired private javax.validation.Validator  validator 

To activate the validation in your controller, you can either add @Valid annotion in the respected method as a parameter before the model object. This will atutomaticly validate the model object, and update BindingResult with constraint messages.

	@RequestMapping(value = "/partner/", method = RequestMethod.POST)
	public String createPartner(@ModelAttribute("partner") @Valid Partner partner, BindingResult result) {
		Assert.notNull(partner, "Partner must be provided.");
		if (result.hasErrors())
			return "partner_create";

		return "redirect:/partner/" + partner.getId();

or manually activate the validation against the model.

      @RequestMapping(value = "/partner/", method = RequestMethod.POST)
	public String createPartner(@ModelAttribute("partner") Partner partner, BindingResult result) {
		Assert.notNull(partner, "Partner must be provided.");		
		 for (ConstraintViolation<Partner> constraint : validator.validate(partner)) {
		  result.rejectValue(constraint.getPropertyPath().toString(), "",
		  constraint.getMessage()); }
		if (result.hasErrors())
			return "partner_create";

		return "redirect:/partner/" + partner.getId();

The above finishes what you need to do to utilize the new JSR-303 in spring MVC, next I will show you how to acheive samething in your webflow.
Read more…