VoiceObjects Java Connector
Introduction
A Java Connector allows the execution of a Java Bean for back-end integration.
Please see VoiceObjects Back-End Integration in the Knowledgebase and the main article VoiceObjects Back-End Integration - Part I: Overview from Jens Bäcker in the VoiceObjects Developer Blog.
Implementation
Let's work through a simple example. Consider the following Java class, test.MySimpleConnector:
package test;
public class MySimpleConnector {
protected double inputvalue;
protected double resultvalue;
public void setInputvalue(String inputvalue) {
this.inputvalue = Double.parseDouble(inputvalue);
}
public String getResultvalue() {
return Double.toString(resultvalue);
}
public void exp() {
resultvalue = Math.exp(inputvalue);
}
}
It has one input parameter, one output parameter, both of which are internally represented as doubles. Since VoiceObjects represents parameters as Strings, you will find type casts in the getter and setter methods.
The class features a single "business" method, exp, which applies the Math.exp() method to the input value and maps it to the output value.
To use this class from VoiceObjects, you need to compile it into a JAR file and deploy it such that it is accessible from VoiceObjects Server.
The Connector object in VoiceObjects will be configured like this:
- Location
- A Resource Locator object with a URL pointing to the web address where you deployed the JAR file.
- File
- Name of the JAR file.
- Class
- "test.MySimpleConnector" (class name including package(s))
- Method
- "exp" (name of the method to be called)
- First Parameter
- Input data
- Parameter
- Your VoiceObject variable that represents the input value
- Alias
- "inputvalue" (note that this maps to the setInputvalue() method)
- Second Parameter
- Return data
- Parameter
- Your VoiceObject variable that represents the output value
- Alias
- "resultvalue" (note that this maps to the getResultvalue() method)
At call time, VoiceObjects
- loads and instantiates the test.MySimpleConnector
- calls all setter methods that map to parameters aliases (input values)
- calls the business method
- calls all getter methods that map to parameters aliases (output values)
Note that if a class property has both according set and get methods, it will be treated as an in/out parameters.
Also note that the method public static void main(String args[]) is not used at all.