Generate vxml file
on-the-fly
The timeofday application requires dynamically generate vxml
file based on the time of the call. Voicent Gateway has
incorporated
Tomcat
as its default web server. The application installed to the
gateway is similar to any Tomcat web application, except the file
format is VXML instead of HTML. If you are new to Java servlet and
JSP technology, please take some time to get yourself familiar
with these technologies.
It is not necessary to use the default web server. Actually you
can use any web server of your choice. However, the discussion is
beyond the scope of this tutorial.
1. Create application jsp file
Rename timeofday.vxml to timeofday.jsp under <tddir>/webapps
and type-in or copy-paste the following to the file:
- <?xml
version="1.0"?>
<vxml version="1.0">
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
- <%
response.setHeader("Cache-Control","no-cache");
Date d = new Date(System.currentTimeMillis());
SimpleDateFormat f = new SimpleDateFormat("hh:mm a");
%>
<form
id="td">
<block>
<audio src="audio/welcome.wav"/>
<%= f.format(d) %>
</block>
</form>
- </vxml>
2. Re-record the audio prompt
Re-record the audio message such that it ends with "... The
current time is".
3. Create web.xml file
Under <tddir>/webapps, create a directory named
WEB-INF. Under WEB-INF, create a file named web.xml
with the following content.
- <?xml
version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>timeofday</servlet-name>
<servlet-class>timeofday</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>timeofday</servlet-name>
<url-pattern>/timeofday.jsp</url-pattern>
</servlet-mapping>
</web-app>
4. Compile the vxml file
The jsp file you created in the previous step is the source
code for time-of-day service. The Tomcat server incorporated in
the gateway only takes compiled jsp files.
To compile the jsp file, you need the jspc compiler
included in the
Tomcat
release. You also need Java SDK (J2SE)
from Sun Microsystems. Please download and install these two
programs before continue.
To compile, use
- <Tomcat
dir>/bin/jspc.bat timeofday.jsp
The jspc compiler should generate a file called
timeofday.java. If the program complains about JASPER_HOME and
JAVA_HOME, please set these environment variables to their
corresponding values. For details, please refer to Tomcat
document.
Create a directory named classes under <tddir>/webapps/WEB-INF.
Now compile it using the javac compiler.
- <JDK
dir>/bin/javac -classpath <Tomcat dir>/lib/jasper-runtime.jar;<Tomcat
dir>/common/lib/servlet.jar -d ./WEB-INF/classes timeofday.java
Now you should have the compiled java class file called
timeofday.class under WEB-INF/classes.
5. Changed the configuration file and re-install the
application
Change the following line in timeofday.conf
- appurl = /td/timeofday.vxml
to
- appurl = /td/timeofday.jsp
Invoke the application setup dialog from Voicent Gateway,
remove the Time of Day application and install it again. The
gateway should restart automatically.
6. Call in to hear the timeofday service
The basic timeofday service is complete. When you call in, you
should hear the current time of the day.
The next section contains some information for you to test
dynamically generated vxml files.
Download the sample code: timeofday_step3.zip. |