Have you ever heard about VoiceXML? It’s a W3C standart that allows you to build web pages that are accessed by voice! It’s very used for services like travel tickets selling, hotel reservation, bank account information and so on. In this post, we’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. We used the 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.
We’ll assume you already know the basics of VoiceXML syntax for the rest of this post. If you are completely new to VoiceXML, we recomend you to visit some of these sites:
How it Works
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 dynamic content generation. The database used to store user information and hotel reservation is a MySQl 5.1 Community edition.
The Glassfish server recieves 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 a HTTP GET or POST.
Other option for the user is to access it right from the web. In our hotel reservation example, we allow only the query for hotel reservations.
Building the Application
In the Glassfish side, we used the Java Server Pages technology with the Spring framework and iBATIS as the Data Mapper framework. From Spring, we used SpringMVC for the MVC design pattern, SpringORM for Spring Dao pattern and the dependency injection pattern.
This allowed us to easily create the application with all the functionality we 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
where user is the database user and -p will ask you for the password.
Other options is use 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 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.
Deploying the Application
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 make use of Glassfish Admin Console. With one Glassfish “fresh installation” this can be done accessing http://localhost:4848/. Default administrator user name is ‘admin’ and default password for admin user is ‘adminadmin’.
After logging in, all you need to do is access Web Applications section, click on 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 applications is incredibly easy. You barely take notice of them :)
You can access our voice hotel application by calling +990009369996079911 from Skype and visualize the data by accessing http://inf.unisc.br/tmuller/viewDatabaseTableData.voice.
The project is located at http://voicehotel.dev.java.net and you can download all it’s source codes. More info is located at https://voicehotel.dev.java.net/source/browse/voicehotel/trunk/artifacts/documentation/.