Have you ever heard about VoiceXML? It's a W3C standard that allows you to build web pages that are accessed by voice! It can be used for services like travel tickets selling, hotel reservation, bank account information and so on. In this post, I'll give you a general view of how to make a basic hotel reservation application with VoiceXML and how to run it using Glassfish and MySQL.
First of all, for VoiceXML applications, we need a voice gateway. I used Voxeo, it's free and provides you with phone numbers that you can call for free using Skype. All you need to do is create a free account in Voxeo and register your application by informing it's URL. After registering you'll receive the unique phone number for your application.
I'll assume you already know the basics of VoiceXML syntax for the rest of this post. If you are completely new to VoiceXML, I recommend you to check it out first.
The user may use his phone to call to the voice gateway. The voice gateway will interact as a voice browser, saying the output of the VoiceXML application and waiting for user inputs. It'll use the internet to access the VoiceXML application, that is deployed in a Glassfish V2 UR2 application server for the dynamic content generation. The database used to store user information and hotel reservation is a MySQl 5.1 Community edition.
The Glassfish server receives the voice gateway HTTP requests, query the MySQL database and returns a web page with the requested information in VoiceXML syntax. Normally it'll be a form with some input fields that must be filed by the user. The voice gateway then asks for user input and, once it's finished, the information is sent back to the Glassfish server as an HTTP GET or POST.
Another option for the user is to access it right from the web. In my hotel reservation example, only the query for hotel reservations is allowed.
In the Glassfish side, I used the Java Server Pages technology with the Spring framework and iBATIS as the Data Mapper framework. From Spring, we used Spring MVC for the MVC design pattern, Spring ORM for Spring Dao pattern and the dependency injection pattern.
This allowed me to easily create the application with all the functionality I needed. Note that the MVC pattern was applied in the voice application and the acronym still valid. Instead of View, we have Voice. For the database modeling, MySQL Workbench was used, a great free tool for this task.
The database ended looking up like this:
another MySQL Workbench screenshot, showing the VoiceHotel Database Model
Once the database is created, you just need to generate the SQL script from MySQL Workbench and execute it with MySQL. The CLI command to do this is:
mysql -u user -p < script_file.sql
user is the database user and
-p will ask you for the password.
Other options are using your IDE for doing this or MySQL Workbench. The main Java IDEs are NetBeans and Eclipse. Both IDEs allows the connection with MySQL and the automatic deployment in Glassfish. Using Eclipse the deployment can be done coding a deploy task in one Ant build file or using another mechanism like Maven. This makes the application development even faster.
With MySQL Workbench we have a set of nice and useful features like Import Reverse Engineer MySQL create a script for importing a database from script, allowing us to edit this new database, and save these modifications. The databases can be exported using a feature called Forward Engineer SQL CREATE/ALTER script. Another nice thing is the visual insert editor, making a lot easier pre-populate the database with data.
With the Java and the VoiceXML code ready, we need to put it online. With Glassfish, all you need to do is either, use
your IDE to deploy it with one click or put the
.war file in the autodeploy folder.
Another possibility is to make use of Glassfish Admin Console. With one Glassfish "fresh installation" this can be done
http://localhost:4848/. Default administrator username is
admin and default password for admin user is
After logging in, all you need to do is access Web Applications section, click on the deploy button, select your war file and that's it.
VoiceXML applications are a great way to give more than one access possibility to a service and using Glassfish and MySQL for developing this kind of application is incredibly easy. You barely take notice of them :)
You can access the voice hotel application by calling
+990009369996079911 from Skype and visualize the data by accessing
the backoffice admin panel.