HTTP Action
(Advanced software integration
topic. Require web programming knowledge) An
http action is an action to submit an http request, usually
to a web server. Specifically, an HTTP action does an HTTP post
using the URL and parameters defined in the action.
Create an HTTP
Action Actions can be created from the action
properties of an element. Right click on any element, select
Properties from the popup menu, select the action
tab, then click the New button. From the Choose Action
Type dialog window, select HTTP action. The following is an HTTP
action from the 24-Hour Information Hotline sample.
This action, when executed, submits an HTTP request to the
following URL: http://localhost:8155/ivrstudio_test, with
one parameter - action, of which the value is 'info24'.
HTTP Response
An HTTP action expects the HTTP POST request returns the content
in the following format:
name1=value 1
name2=value 2
...
For example, one possible return might be:
lastUpdated = Sept. 1, 2007 12:00 PM
content = today's mortgage rate is 2% for 30 year fixes
The dot notation is used to access a particular name value pair.
For example, get_info_24.lastUpdated is used to access the
lastUpdated field, where get_info_24 is the name of the
action. The return name value pairs are called
action return variable.
You can use action return variables in prompts and other actions.
Sample HTTP Post
Handler
The URL: http://localhost:8155/ivrstudio_test refers to a
Java Servlet on Voicent Gateway. (Voicent Gateway contains a
webserver called TOMCAT). It handles HTTP requests for this URL.
The following are partial listings of the file:
public class IvrstudioTestServlet extends HttpServlet
{
private void handleRequest(HttpServletRequest request, HttpServletResponse response,
ServletOutputStream sos)
throws ServletException, IOException
{
String action = request.getParameter("action"); ...
File f = new File("info24.txt");
...
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(f));
}
catch (IOException e) {
}
String content = "";
String lastModified = "";
if (br != null) {
String line;
while ((line = br.readLine()) != null)
content += line;
Calendar cal = Calendar.getInstance();
Date d = new Date(f.lastModified());
SimpleDateFormat df = new SimpleDateFormat("MMMMM.dd");
lastModified = df.format(d);
br.close();
}
if ("info24".equals(action)) {
Properties props = new Properties();
props.setProperty("content", content);
props.setProperty("lastUpdated", lastModified);
props.store(sos, "");
}
else { ...
}
return;
}
}
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException
{ ServletContext context = getServletContext();
try {
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache");
ServletOutputStream sos = response.getOutputStream();
handleRequest(request, response, sos);
sos.flush();
}
catch (Throwable e) {
context.log("ivrstudio_test", e);
}
}
}
One handy class for the action handler servlet is
java.util.Properties. You can use setProperty() to set
the name value pairs, and use store() to write the name
value pairs to a stream.
|