After updating asterisk-java with the changes I sent yesterday, the
aformentioned port was
straight forward as seen below.
import java.util.*;
import net.sf.asterisk.fastagi.*;
import net.sf.asterisk.fastagi.command.*;
import net.sf.asterisk.fastagi.reply.*;
/*
* Created on Apr 7, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author drach
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class TestFastAGI extends AbstractAGIScript {
private int tests, pass, fail;
private int s, p;
private void print(String s) {
System.err.print(s);
}
private void checkResult(AGIReply reply) {
tests++;
if (reply.getStatus() == 200) {
if (reply.getResult() == null) {
print("FAIL (" + reply.getFirstLine() + ")\n");
fail++;
} else {
print("PASS (" + reply.getResult() + ")\n");
pass++;
}
} else {
print("FAIL (unexpected result '" + reply.getFirstLine() +
"')\n");
fail++;
}
}
public void service(AGIRequest request, AGIChannel channel)
throws AGIException
{
Map values;
Iterator i;
SortedSet keys = new TreeSet();
keys.addAll((values = request.getRequest()).keySet());
print("AGI Environment Dump from --\n");
i = keys.iterator();
while (i.hasNext()) {
String key;
key = (String)i.next();
print(" -- " + key + " = " + (String)values.get(key) +
"\n");
}
print("1. Testing 'sendfile'...");
checkResult(channel.sendCommand(new StreamFileCommand("beep")));
print("2. Testing 'sendtext'...");
checkResult(channel.sendCommand(new SendTextCommand("hello
world")));
print("3. Testing 'sendimage'...");
checkResult(channel.sendCommand(new
SendImageCommand("asterisk-image")));
print("4. Testing 'saynumber'...");
checkResult(channel.sendCommand(new
SayNumberCommand("192837465")));
print("5. Testing 'waitdtmf'...");
checkResult(channel.sendCommand(new WaitForDigitCommand(1000)));
print("6. Testing 'record'...");
checkResult(channel.sendCommand(new
RecordFileCommand("testagi", "gsm", "1234", 3000)));
print("6a. Testing 'record' playback...");
checkResult(channel.sendCommand(new
StreamFileCommand("testagi")));
print("================== Complete ======================\n");
print(tests + " tests completed, " + pass + " passed, " + fail
+ " failed\n");
print("==================================================\n");
}
}
|