Re: [Asterisk-java-users] Problems with CommandAction
Brought to you by:
srt
From: Stefan R. <ste...@re...> - 2008-02-02 14:04:41
|
Bruno, sorry I didn't pay enough attention to your first email. In 0.3 we had similar code to what you suggested and used the Java readLine() method to read from Asterisk. readLine() does not make a difference between "\r\n" and "\n" which turned out to make things harder than they must be. The convention in Asterisk is that "\r\n" is the delimiter for the manager "lines" while "\n" may appear within a line. You can try "sip show peers" this will work just fine as it uses "\n" in its output. For trunk I have reworked the handling of the CommandAction to make use of this convention which makes the code much simpler. My impression is that "show dialplan" does not adhere to this convention. Additionally when I run wireshark and look at the data it seems the dialplan is truncated anyway: action: Command actionid: 2131238190_2# command: dialplan show Response: Follows Privilege: Command ActionID: 2131238190_2# [ Context 'from-voipgate' created by 'pbx_config' ] <snip> [ Context 'app_dial_gosub_virtual_context' created by 'app_dial--END COMMAND-- It would be interesting if there are many commands that behave this way or if its specific to "show dialplan". If there are more we might revert to using the old code (which I would really like to prevent). =3DStefan Bruno KONIK wrote: > Stefan, >=20 > thanks. > I think I am using it the right way : >=20 > commandAction =3D new CommandAction("dialplan show"); > response =3D managerConnection.sendAction(commandAction= ); > if (response instanceof CommandResponse) { > Iterator<String> i =3D ((CommandResponse) > response).getResult().iterator(); > while (i.hasNext()) { > String item =3D i.next(); > } > } >=20 > and yes I am using the 1.0.0 snapshot from last thursday. >=20 > Bruno >=20 > 2008/2/1, Stefan Reuter <ste...@re... > <mailto:ste...@re...>>: >=20 > Do you use this correctly? > Example: > response =3D sendAction(new CommandAction(command)); > if (!(response instanceof CommandResponse)) > { > throw new ManagerCommunicationException( > "Response to CommandAction(\"" + command > + "\") was not a CommandResponse but " = + > response, > null); > } >=20 > // use ((CommandResponse) response).getResult(); >=20 > getResult() returns a List of Strings - one per line. >=20 > Besides, the implementation has been completly reworked in svn trun= k to > use \r\n as delimiter so that newlines in the responses do work wit= hout > additonal hacks. > Would you mind to check svn trunk or the latest 1.0.0 snapshot? >=20 > =3DStefan >=20 >=20 >=20 > Bruno Konik wrote: > > Hello, > > > > Asterisk 1.4.17, > > Asterisk-java 0.3.1 > > > > I am trying to use the CommandAction with 'diaplan show' but the > response gives only the last line of the response. It seems that > > the Reader doesn't allow to give such responses splitted over > several lines. > > > > If you accept a modification to treat it I suggest the following > code in the ManagerReaderImpl.java : > > > > StringBuilder commandResponseResult =3D null; // the buffer= to > be used for multi lines command response > > while ((line =3D socket.readLine()) !=3D null && !this.die)= > > { > > ... > > > > // your code was : > > // Special handling for "Response: Follows" (CommandResponse) > > // if ("Follows".equals(buffer.get("response")) &&= > line.endsWith("--END COMMAND--")) > > // { > > // buffer.put("result", line); > > // continue; > > // } > > > > // I suggest : > > // special handling for "Response: Follows" (CommandResponse) to > treat several lines > > // START > > if ("Follows".equals(buffer.get("response")) && > line.length() > 0 && buffer.containsKey("actionid")) > > { > > if (commandResponseResult =3D=3D null) { > > if (line.endsWith("--END COMMAND--")) { > > buffer.put("result", line); > > } else { > > commandResponseResult =3D new StringBuilder= (line); > > } > > } else { > > commandResponseResult.append(line); > > if (line.endsWith("--END COMMAND--")) { > > buffer.put("result", > commandResponseResult.toString()); > > commandResponseResult =3D null; > > } > > } > > continue; > > } > > // END > > ... > > > > Thanks for letting me know if you are ok with that and thanks for= > your help, > > > > Bruno Konik > > > >> -----Message d'origine----- > >> De : ast...@li... > <mailto:ast...@li...> > >> [mailto:ast...@li... > <mailto:ast...@li...>] De > >> la part de Stefan Reuter > >> Envoy=E9 : mardi 2 octobre 2007 02:44 > >> =C0 : ast...@li... > <mailto:ast...@li...> > >> Objet : Re: [Asterisk-java-users] asterisk java and astmanproxy > >> > >> Ga=EBtan Minet wrote: > >>> Here is a link > >>> > >>> http://dev.mcit.be/various/astmanproxy-asterisk-java.html > >> Thanks. You'll find the link on the A-J homepage. I've also > >> added it to the AstManProxy page on voip-info.org > <http://voip-info.org>. > >> > >> Support for the server property is now in SVN. > >> > >> =3DStefan |