[Asterisk-java-users] Help about agi server
Brought to you by:
srt
From: dovb <do...@te...> - 2005-07-14 02:30:12
|
Hi, I have the following simple code: After printing "cc1" (after I dial 123) the AGIServer prints 13/07/2005 23:28:05 net.sf.asterisk.util.impl.JavaLoggingLog error SEVERE: AGIException while handling request: Unable to read reply from Asterisk: Connectio n reset and stops running. Where am I going wrong??? Thank you! Dov public class TrataAGI extends AbstractAGIScript { public void service(AGIRequest request, AGIChannel channel) throws AGIException { // Answer the channel... answer(channel); // ...say hello... String result = getNumber(channel); SayDigitsCommand sc = new SayDigitsCommand(result); System.out.println("aa" + result); AGIReply rep = channel.sendCommand(sc); System.out.println("bb" + result); if (result.substring(0, result.length() - 1).equals("123")) { System.out.println("cc0"); SayNumberCommand cmd = new SayNumberCommand(new Integer("123").toString()); System.out.println("cc1"); rep = channel.sendCommand(cmd); System.out.println("cc2"); } if (result.substring(0, result.length() - 1).equals("456")) { System.out.println("dd0"); SayNumberCommand cmd = new SayNumberCommand(new Integer("456").toString()); System.out.println("dd1"); rep = channel.sendCommand(cmd); System.out.println("dd2"); SayNumberCommand snc = new SayNumberCommand("11"); System.out.println("dd3"); rep = channel.sendCommand(snc); System.out.println("dd4"); } // ...and hangup. hangup(channel); } private String getNumber(AGIChannel channel) { String lido = ""; AGIReply reply = null; StringBuffer result = new StringBuffer(); while (!lido.equals("#")) { WaitForDigitCommand wc = new WaitForDigitCommand(); try { reply = channel.sendCommand(wc); } catch (AGIException e) { e.printStackTrace(); System.exit(0); } String resp = (String) reply.getResult(); int number = new Integer(resp).intValue(); char c = (char) number; lido = new Character(c).toString(); result.append(lido); } return (result.toString()); } |