Thread: [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()); } |
From: Stefan R. <sr...@re...> - 2005-07-14 12:52:51
|
Hi Dov, what version of Asterisk do you use? can you post the relevant section of your asterisk console (use set verbose 9 to enable full output)? When I run your AGI script and press '123#' the channel is hung up at SayDigitsCommand sc =3D new SayDigitsCommand(result); because: -- Playing 'digits/1' (language 'en') -- Playing 'digits/2' (language 'en') -- Playing 'digits/3' (language 'en') Jul 14 20:47:43 WARNING[801]: file.c:475 ast_openstream: File digits/# does not exist in any format Jul 14 20:47:43 WARNING[801]: file.c:779 ast_streamfile: Unable to open digits/# (format alaw): No such file or directory so I had to change that to new SayDigitsCommand(result.substring(0, result.length() - 1)); after that everything went fine. =3DStefan > 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 =3D getNumber(channel); > SayDigitsCommand sc =3D new SayDigitsCommand(result); > System.out.println("aa" + result); > AGIReply rep =3D channel.sendCommand(sc); > System.out.println("bb" + result); > > if (result.substring(0, result.length() - 1).equals("123")) > { > System.out.println("cc0"); > SayNumberCommand cmd =3D new SayNumberCommand(new > Integer("123").toString()); > System.out.println("cc1"); > rep =3D channel.sendCommand(cmd); > System.out.println("cc2"); > } > > if (result.substring(0, result.length() - 1).equals("456")) > { > System.out.println("dd0"); > SayNumberCommand cmd =3D new SayNumberCommand(new > Integer("456").toString()); > System.out.println("dd1"); > rep =3D channel.sendCommand(cmd); > System.out.println("dd2"); > SayNumberCommand snc =3D new SayNumberCommand("11"); > System.out.println("dd3"); > rep =3D channel.sendCommand(snc); > System.out.println("dd4"); > } > > // ...and hangup. > hangup(channel); > } > > private String getNumber(AGIChannel channel) > { > String lido =3D ""; > AGIReply reply =3D null; > StringBuffer result =3D new StringBuffer(); > while (!lido.equals("#")) > { > WaitForDigitCommand wc =3D new WaitForDigitCommand(); > try > { > reply =3D channel.sendCommand(wc); > } > catch (AGIException e) > { > e.printStackTrace(); > System.exit(0); > } > > String resp =3D (String) reply.getResult(); > int number =3D new Integer(resp).intValue(); > char c =3D (char) number; > lido =3D new Character(c).toString(); > result.append(lido); > } > return (result.toString()); > } > |