asterisk-java-cvs Mailing List for Asterisk-Java Library (Page 93)
Brought to you by:
srt
You can subscribe to this list here.
| 2005 |
Jan
(4) |
Feb
(75) |
Mar
(211) |
Apr
(70) |
May
(12) |
Jun
(7) |
Jul
(96) |
Aug
(90) |
Sep
(11) |
Oct
(42) |
Nov
(45) |
Dec
(4) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(20) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(32) |
Aug
|
Sep
(4) |
Oct
(2) |
Nov
(10) |
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
(3) |
Aug
(73) |
Sep
(13) |
Oct
(4) |
Nov
(1) |
Dec
(7) |
| 2009 |
Jan
(1) |
Feb
(2) |
Mar
(48) |
Apr
(21) |
May
(14) |
Jun
(11) |
Jul
(9) |
Aug
(2) |
Sep
(11) |
Oct
(14) |
Nov
(6) |
Dec
(4) |
| 2010 |
Jan
(3) |
Feb
(2) |
Mar
|
Apr
|
May
(3) |
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
(9) |
Nov
|
Dec
(12) |
| 2011 |
Jan
(1) |
Feb
(5) |
Mar
(7) |
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(10) |
Sep
|
Oct
(5) |
Nov
|
Dec
|
| 2012 |
Jan
(3) |
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
(2) |
Dec
(2) |
| 2013 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
(2) |
Nov
|
Dec
(1) |
| 2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(5) |
| 2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
(25) |
May
(10) |
Jun
(4) |
Jul
(7) |
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
(3) |
Dec
(1) |
| 2016 |
Jan
|
Feb
(42) |
Mar
(6) |
Apr
(15) |
May
(3) |
Jun
(1) |
Jul
(11) |
Aug
|
Sep
|
Oct
(17) |
Nov
(2) |
Dec
|
| 2017 |
Jan
|
Feb
(4) |
Mar
(1) |
Apr
(3) |
May
(2) |
Jun
(3) |
Jul
(7) |
Aug
(11) |
Sep
(5) |
Oct
(7) |
Nov
(4) |
Dec
(4) |
| 2018 |
Jan
(11) |
Feb
(11) |
Mar
(3) |
Apr
|
May
(9) |
Jun
(6) |
Jul
(17) |
Aug
(9) |
Sep
(2) |
Oct
(4) |
Nov
(3) |
Dec
(3) |
| 2019 |
Jan
(13) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(5) |
Jun
|
Jul
(1) |
Aug
(6) |
Sep
|
Oct
|
Nov
(3) |
Dec
|
| 2020 |
Jan
(2) |
Feb
(72) |
Mar
(8) |
Apr
(11) |
May
(12) |
Jun
(3) |
Jul
(12) |
Aug
(3) |
Sep
(5) |
Oct
(4) |
Nov
|
Dec
(9) |
| 2021 |
Jan
|
Feb
(31) |
Mar
(6) |
Apr
(3) |
May
|
Jun
(2) |
Jul
|
Aug
(2) |
Sep
|
Oct
(9) |
Nov
|
Dec
(32) |
| 2022 |
Jan
(5) |
Feb
(7) |
Mar
(2) |
Apr
(3) |
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
(2) |
Oct
(111) |
Nov
(105) |
Dec
(26) |
| 2023 |
Jan
(25) |
Feb
(6) |
Mar
(10) |
Apr
(54) |
May
(41) |
Jun
(24) |
Jul
(6) |
Aug
(11) |
Sep
(9) |
Oct
(8) |
Nov
(55) |
Dec
(34) |
| 2024 |
Jan
(6) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(89) |
Sep
(48) |
Oct
(31) |
Nov
(9) |
Dec
(19) |
| 2025 |
Jan
(12) |
Feb
(18) |
Mar
(9) |
Apr
(7) |
May
|
Jun
(7) |
Jul
(7) |
Aug
(3) |
Sep
(22) |
Oct
(23) |
Nov
(7) |
Dec
(55) |
|
From: Stefan R. <sr...@us...> - 2005-03-12 09:57:43
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2340/src/java/net/sf/asterisk Added Files: Main.java Log Message: Added --- NEW FILE: Main.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk; import net.sf.asterisk.fastagi.AGIServer; import net.sf.asterisk.fastagi.DefaultAGIServer; /** * Starts the DefaultAGIServer. * * @author srt * @version $Id: Main.java,v 1.1 2005/03/12 09:57:32 srt Exp $ */ public class Main { public static void main(String[] args) throws Exception { AGIServer agiServer; agiServer = new DefaultAGIServer(); agiServer.startup(); } } |
|
From: Stefan R. <sr...@us...> - 2005-03-12 09:57:01
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2210/src/java/net/sf/asterisk/fastagi Modified Files: AbstractAGIScript.java Log Message: Added some more convinience methods Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- AbstractAGIScript.java 11 Mar 2005 16:18:13 -0000 1.7 +++ AbstractAGIScript.java 12 Mar 2005 09:56:50 -0000 1.8 @@ -17,10 +17,20 @@ package net.sf.asterisk.fastagi; import net.sf.asterisk.fastagi.command.AnswerCommand; +import net.sf.asterisk.fastagi.command.ChannelStatusCommand; +import net.sf.asterisk.fastagi.command.ExecCommand; import net.sf.asterisk.fastagi.command.GetVariableCommand; import net.sf.asterisk.fastagi.command.HangupCommand; +import net.sf.asterisk.fastagi.command.SayDigitsCommand; +import net.sf.asterisk.fastagi.command.SayNumberCommand; +import net.sf.asterisk.fastagi.command.SayPhoneticCommand; +import net.sf.asterisk.fastagi.command.SayTimeCommand; +import net.sf.asterisk.fastagi.command.SetAutoHangupCommand; +import net.sf.asterisk.fastagi.command.SetCallerIdCommand; import net.sf.asterisk.fastagi.command.SetContextCommand; import net.sf.asterisk.fastagi.command.SetExtensionCommand; +import net.sf.asterisk.fastagi.command.SetMusicOffCommand; +import net.sf.asterisk.fastagi.command.SetMusicOnCommand; import net.sf.asterisk.fastagi.command.SetPriorityCommand; import net.sf.asterisk.fastagi.command.SetVariableCommand; import net.sf.asterisk.fastagi.command.StreamFileCommand; @@ -28,7 +38,8 @@ import net.sf.asterisk.fastagi.reply.AGI /** * The AbstractAGIScript provides some convinience methods to make it easier to - * write custom AGIScripts. + * write custom AGIScripts.<br> + * Just extend it by your own AGIScripts. * * @author srt * @version $Id$ @@ -51,18 +62,148 @@ public abstract class AbstractAGIScript channel.sendCommand(new HangupCommand()); } + /** + * Cause the channel to automatically hangup at the given number of seconds + * in the future. + * + * @param time the number of seconds before this channel is automatically + * hung up.<br> + * 0 disables the autohangup feature. + */ + protected void setAutoHangup(AGIChannel channel, int time) + throws AGIException + { + channel.sendCommand(new SetAutoHangupCommand(time)); + } + + /** + * Sets the caller id on the current channel. + * + * @param callerId the raw caller id to set, for example "John Doe<1234>". + */ + protected void setCallerId(AGIChannel channel, String callerId) + throws AGIException + { + channel.sendCommand(new SetCallerIdCommand(callerId)); + } + + /** + * Plays music on hold from the default music on hold class. + */ + protected void playMusicOnHold(AGIChannel channel) throws AGIException + { + channel.sendCommand(new SetMusicOnCommand()); + } + + /** + * Plays music on hold from the given music on hold class. + * + * @param musicOnHoldClass the music on hold class to play music from as + * configures in Asterisk's <code><musiconhold.conf/code>. + */ + protected void playMusicOnHold(AGIChannel channel, String musicOnHoldClass) + throws AGIException + { + channel.sendCommand(new SetMusicOnCommand(musicOnHoldClass)); + } + + /** + * Stops playing music on hold. + */ + protected void stopMusicOnHold(AGIChannel channel) throws AGIException + { + channel.sendCommand(new SetMusicOffCommand()); + } + + /** + * Returns the status of the channel.<br> + * Return values: + * <ul> + * <li>0 Channel is down and available + * <li>1 Channel is down, but reserved + * <li>2 Channel is off hook + * <li>3 Digits (or equivalent) have been dialed + * <li>4 Line is ringing + * <li>5 Remote end is ringing + * <li>6 Line is up + * <li>7 Line is busy + * </ul> + * + * @return the status of the channel. + */ + protected int getChannelStatus(AGIChannel channel) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new ChannelStatusCommand()); + return reply.getResultCode(); + } + + /** + * Executes the given command. + * + * @param application the name of the application to execute, for example + * "Dial". + * @return the return code of the application of -2 if the application was + * not found. + */ + protected int execCommand(AGIChannel channel, String application) + throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new ExecCommand(application)); + return reply.getResultCode(); + } + + /** + * Executes the given command. + * + * @param application the name of the application to execute, for example + * "Dial". + * @param options the parameters to pass to the application, for example + * "SIP/123". + * @return the return code of the application of -2 if the application was + * not found. + */ + protected int execCommand(AGIChannel channel, String application, + String options) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new ExecCommand(application, options)); + return reply.getResultCode(); + } + + /** + * Sets the context for continuation upon exiting the application. + * + * @param context the context for continuation upon exiting the application. + */ protected void setContext(AGIChannel channel, String context) throws AGIException { channel.sendCommand(new SetContextCommand(context)); } + /** + * Sets the extension for continuation upon exiting the application. + * + * @param extension the extension for continuation upon exiting the + * application. + */ protected void setExtension(AGIChannel channel, String extension) throws AGIException { channel.sendCommand(new SetExtensionCommand(extension)); } + /** + * Sets the priority for continuation upon exiting the application. + * + * @param priority the priority for continuation upon exiting the + * application. + */ protected void setPriority(AGIChannel channel, int priority) throws AGIException { @@ -85,9 +226,9 @@ public abstract class AbstractAGIScript * given digit. * * @param file name of the file to play. - * @param escapeDigits a String containing the dtmf digits that allow the + * @param escapeDigits a String containing the DTMF digits that allow the * user to escape. - * @return the dtmf digit pressed or 0x0 if none was pressed. + * @return the DTMF digit pressed or 0x0 if none was pressed. */ protected char streamFile(AGIChannel channel, String file, String escapeDigits) throws AGIException @@ -99,6 +240,122 @@ public abstract class AbstractAGIScript } /** + * Says the given digit string. + * + * @param digits the digit string to say. + */ + protected void sayDigits(AGIChannel channel, String digits) + throws AGIException + { + channel.sendCommand(new SayDigitsCommand(digits)); + } + + /** + * Says the given number, returning early if any of the given DTMF number + * are received on the channel. + * + * @param digits the digit string to say. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + */ + protected char sayDigits(AGIChannel channel, String digits, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayDigitsCommand(digits)); + return reply.getResultCodeAsChar(); + } + + /** + * Says the given number. + * + * @param number the number to say. + */ + protected void sayNumber(AGIChannel channel, String number) + throws AGIException + { + channel.sendCommand(new SayNumberCommand(number)); + } + + /** + * Says the given number, returning early if any of the given DTMF number + * are received on the channel. + * + * @param number the number to say. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + */ + protected char sayNumber(AGIChannel channel, String number, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayNumberCommand(number)); + return reply.getResultCodeAsChar(); + } + + /** + * Says the given character string with phonetics. + * + * @param text the text to say. + */ + protected void sayPhonetic(AGIChannel channel, String text) + throws AGIException + { + channel.sendCommand(new SayPhoneticCommand(text)); + } + + /** + * Says the given character string with phonetics, returning early if any of + * the given DTMF number are received on the channel. + * + * @param text the text to say. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + */ + protected char sayPhonetic(AGIChannel channel, String text, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayPhoneticCommand(text)); + return reply.getResultCodeAsChar(); + } + + /** + * Says the given character string with phonetics. + * + * @param time the time to say in seconds since 00:00:00 on January 1, 1970. + */ + protected void sayTime(AGIChannel channel, long time) + throws AGIException + { + channel.sendCommand(new SayTimeCommand(time)); + } + + /** + * Says the given character string with phonetics, returning early if any of + * the given DTMF number are received on the channel. + * + * @param time the time to say in seconds since 00:00:00 on January 1, 1970. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + */ + protected char sayTime(AGIChannel channel, long time, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayTimeCommand(time)); + return reply.getResultCodeAsChar(); + } + + /** * Returns the value of the given channel variable. * * @param name the name of the variable to retrieve. |
|
From: Stefan R. <sr...@us...> - 2005-03-12 09:56:29
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2094/src/java/net/sf/asterisk/fastagi Modified Files: AGIConnectionHandler.java Log Message: Added logging of missing mapping via VerboseCommand() Index: AGIConnectionHandler.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIConnectionHandler.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -p -r1.8 -r1.9 --- AGIConnectionHandler.java 11 Mar 2005 20:15:15 -0000 1.8 +++ AGIConnectionHandler.java 12 Mar 2005 09:56:17 -0000 1.9 @@ -18,6 +18,7 @@ package net.sf.asterisk.fastagi; import java.io.IOException; +import net.sf.asterisk.fastagi.command.VerboseCommand; import net.sf.asterisk.fastagi.impl.AGIChannelImpl; import net.sf.asterisk.fastagi.impl.AGIReaderImpl; import net.sf.asterisk.fastagi.impl.AGIWriterImpl; @@ -38,12 +39,12 @@ import org.apache.commons.logging.LogFac public class AGIConnectionHandler implements Runnable { private final Log logger = LogFactory.getLog(getClass()); - + /** * The socket connection. */ private SocketConnectionFacade socket; - + /** * The strategy to use to determine which script to run. */ @@ -93,22 +94,28 @@ public class AGIConnectionHandler implem script = mappingStrategy.determineScript(request); threadName = Thread.currentThread().getName(); - + if (script != null) { - logger.info("Begin AGIScript " + script.getClass().getName() + " on " + threadName); + logger.info("Begin AGIScript " + script.getClass().getName() + + " on " + threadName); script.service(request, channel); - logger.info("End AGIScript " + script.getClass().getName() + " on " + threadName); + logger.info("End AGIScript " + script.getClass().getName() + + " on " + threadName); } else { - logger.error("Unable to determine which script to run for " - + request.getRequestURL()); + String error; + + error = "No script configured for " + request.getRequestURL(); + channel.sendCommand(new VerboseCommand(error, 1)); + logger.error(error); } } catch (AGIException e) { - logger.error("AGIException while handling request: " + e.getMessage()); + logger.error("AGIException while handling request: " + + e.getMessage()); } catch (Exception e) { |
|
From: Stefan R. <sr...@us...> - 2005-03-12 09:55:21
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1883/src/java/net/sf/asterisk/fastagi Modified Files: DefaultAGIServer.java Log Message: Changed logging on startup Index: DefaultAGIServer.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/DefaultAGIServer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- DefaultAGIServer.java 10 Mar 2005 23:42:35 -0000 1.4 +++ DefaultAGIServer.java 12 Mar 2005 09:55:10 -0000 1.5 @@ -186,7 +186,7 @@ public class DefaultAGIServer implements try { serverSocket = createServerSocket(); - logger.info("Waiting for new connections."); + logger.info("Listening on *:" + bindPort + "."); while ((socket = serverSocket.accept()) != null) { |
|
From: Stefan R. <sr...@us...> - 2005-03-11 23:39:43
|
Update of /cvsroot/asterisk-java/asterisk-java/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23186/xdocs Modified Files: index.xml Log Message: Added information on FastAGI support and licenses of referenced projects Index: index.xml =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/xdocs/index.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- index.xml 11 Mar 2005 13:41:51 -0000 1.6 +++ index.xml 11 Mar 2005 23:39:29 -0000 1.7 @@ -27,13 +27,17 @@ <section name="Asterisk Java"> <subsection name="What is asterisk-java?"> <p>The asterisk-java package consists of a set of Java classes - that allow you to connect to an <a - href="http://www.asterisk.org/">Asterisk PBX Server</a> via - <a - href="http://www.voip-info.org/wiki-Asterisk+manager+API">Asterisk's - Manager API</a> from any Java application.</p> - <p>It supports receiving events from the Asterisk server (e.g. - call progess, registered peers, channel state) and sending + that allow you to easily build Java application that interact with an <a + href="http://www.asterisk.org/">Asterisk PBX Server</a>. Asterisk-java + supports both interfaces that Asterisk provides for this scenario: + The <a href="http://www.voip-info.org/wiki-Asterisk+AGI">FastAGI</a> + protocol and the <a + href="http://www.voip-info.org/wiki-Asterisk+manager+API">Manager API</a>.</p> + <p>The FastAGI implementation supports all <a + href="apidocs/net/sf/asterisk/fastagi/command/package-summary.html">commands</a> + currently available from Asterisk.</p> + <p>The Manager API implementation supports receiving events from the Asterisk + server (e.g. call progess, registered peers, channel state) and sending actions to Asterisk (e.g. originate call, agent login/logoff, start/stop voice recording).</p> <p>A complete list of the available <a @@ -49,24 +53,22 @@ License, Version 2.0</a>.</p> </subsection> <subsection name="Status"> - <p>Currently asterisk-java supports the actions and events - provided by the standard installation of Asterisk but you can - easily extend them by your own events and actions.</p> + <p>I am currently preparing the first release of asterisk-java. It will probably + be available by the end of april. Meanwhile you can try it out by accessing + the code base in cvs (see below).</p> <p>Ideas for the future include a stateful higher level API that supports operations like "get list of currently active calls" or "place call" with objects like "Call" or "Channel" that are transparently updated as the state of the corresponding object within the asterisk server changes.</p> - <p>There is also some work on an implementation of the FastAGI protocol - as the currently available java implementations (see below) are both - subject to the strict terms of the GPL.</p> </subsection> <subsection name="Download"> <p>Asterisk-java is currently available via cvs only.</p> -<source><![CDATA[cvs -d:pserver:ano...@cv...:/cvsroot/asterisk-java login -cvs -z3 -d:pserver:ano...@cv...:/cvsroot/asterisk-java co asterisk-java]]> - </source> +<source><![CDATA[ +cvs -d:pserver:ano...@cv...:/cvsroot/asterisk-java login +cvs -z3 -d:pserver:ano...@cv...:/cvsroot/asterisk-java co asterisk-java +]]></source> <p>When prompted for a password for <i>anonymous</i>, simply press the Enter key.</p> <p>More information is available on the <a @@ -74,24 +76,19 @@ cvs -z3 -d:pserver:ano...@cv... project page</a>.</p> </subsection> <subsection name="Related Projects"> - <p>_dw has developed a similar kind of software for Python - called <a - href="http://www.botanicus.net/dw/py-asterisk.php">py-Asterisk</a>. - </p> - <p><a href="http://sourceforge.net/projects/jasterisk/">JAsterisk</a> - is a set of JNI classes providing direct access to Asterisk - PBX functionality from Java. It is not a socket-level - interface into the Asterisk manager app (like - asterisk-java) but a true Java-Asterisk integration at the - Thread level.</p> + <p><a href="http://tanesha.net/Wiki/JastAgi.html">Jast Agi</a> + is another toolkit for writing Java applications that connect to + Asterisk using the FastAGI protocol. Available under Apache License.</p> <p><a href="http://www.voip-info.org/wiki-JAGIServer">JAGIServer</a> is a 100% Pure Java application server for Asterisk using the FastAGI protocol, which is a TCP/IP wrapper around the Asterisk Gateway Interface AGI protocol for call handling - and processing caller input.</p> - <p><a href="http://tanesha.net/Wiki/JastAgi.html">Jast Agi</a> - is another toolkit for writing Java applications that connect to - Asterisk using the FastAGI protocol.</p> + and processing caller input. Available under GNU General Public License.</p> + <p><a href="http://sourceforge.net/projects/jasterisk/">JAsterisk</a> + is a set of JNI classes providing direct access to Asterisk + PBX functionality from Java. It is not a socket-level + interface to Asterisk (like asterisk-java) but a true Java-Asterisk + integration at the Thread level. Available under GNU General Public License.</p> </subsection> <subsection name="Contact"> <p>You can reach me at <code>srt</code> at <code>reucon</code> dot <code>net</code></p>. </subsection> |
|
From: Stefan R. <sr...@us...> - 2005-03-11 23:17:58
|
Update of /cvsroot/asterisk-java/asterisk-java/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17522/xdocs Modified Files: navigation.xml Added Files: tutorial.xml Removed Files: samples.xml Log Message: Added tutorial covering basic FastAGI usage --- NEW FILE: tutorial.xml --- <?xml version="1.0"?> <!-- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ --> <document> <properties> <author email="srt at users.sourceforge.net">Stefan Reuter</author> <title>Samples</title> </properties> <meta name="keywords" content="Asterisk,asterisk,Java,java,Manager API,FastAGI,AGI,tutorial,example"/> <body> <section name="The FastAGI Protocol"> <p>The easiest way to interact with Asterisk from Java applications is via the FastAGI protocol.</p> <p>The AGI (Asterisk Gateway Interface) facility allows you to launch scripts, from the Asterisk dial plan. Traditionally communication between the scripts and Asterisk was via standard input and standard output and scripts had to run on the same machine as Asterisk. Due to the large amount of time a Java Virtual Machine needs for startup and the discomfort of having to install a Java environment on the PBX box(es) Java has not been the language of choice for writing AGI scripts.</p> <p>These drawbacks have been addressed by the addition of FastAGI to Asterisk. FastAGI is basically AGI over TCP/IP socket connections instead of using standard input and standard output as communication medium.</p> <p>Using FastAGI you can run a Java application (on the same machine that runs Asterisk or on a seperate machine) that is only started once and serves AGI scripts until it is shut down. Combined with Java's multithreading support you can build pretty fast AGI scripts using this protocol.</p> <p>Asterisk-java helps you with running your Java based AGI scripts by providing a container that recives connections from the Asterisk server, parses the request and calls your scripts mapped to the called URL.</p> <subsection name="Hello AGI!"> <p>To write your own AGI scripts you must implement the AGIScript interface. You can do so by simply extending AbstractAGIScript that provides some convenience methods that further simplify that task.</p> <p>A simple AGIScript might look as follows:</p> <source><![CDATA[ import net.sf.asterisk.fastagi.AGIChannel; import net.sf.asterisk.fastagi.AGIException; import net.sf.asterisk.fastagi.AGIRequest; import net.sf.asterisk.fastagi.AbstractAGIScript; public class HelloAGIScript extends AbstractAGIScript { public void service(AGIRequest request, AGIChannel channel) throws AGIException { // Answer the channel... answer(channel); // ...say hello... streamFile(channel, "welcome"); // ...and hangup. hangup(channel); } } ]]></source> <p>Put this Java source file into a directory of your choice, add the <code>asterisk-java.jar</code> and <code>commons-logging.jar</code> and compile it:</p> <source><![CDATA[ $ javac -cp asterisk-java.jar:commons-logging.jar HelloAGIScript.java $ ]]></source> <p>Next you have to add a call to your script to your dialplan in Asterisk.</p> <p>You might want to add an extension 1300 to the default section of your <code>extensions.conf</code>:</p> <source><![CDATA[ [default] ... exten => 1300,1,Agi(agi://localhost/hello.agi) ]]></source> <p>Replace localhost with the hostname of the machine that runs Asterisk-java.</p> <p>Be sure to reload Asterisk for this change to take effect. You can do so by executing <code>extensions reload</code> on the Asterisk CLI.</p> <p>Now you must map the script name <code>hello.agi</code> to the HelloAGIScript we just created. By default this is done in a properties file called <code>fastagi-mapping.properties</code> that must be on the classpath when we start the AGIServer. In this case it looks like:</p> <source><![CDATA[ hello.agi = HelloAGIScript ]]></source> <p>Your directory should now contain the following files:</p> <source><![CDATA[ $ ls -l -rw-r--r-- 1 srt srt 163689 2005-03-11 22:07 asterisk-java.jar -rw-r--r-- 1 srt srt 26388 2005-03-11 22:06 commons-logging.jar -rw-r--r-- 1 srt srt 26 2005-03-11 20:50 fastagi-mapping.properties -rw-r--r-- 1 srt srt 624 2005-03-11 22:07 HelloAGIScript.class -rw-r--r-- 1 srt srt 438 2005-03-11 20:50 HelloAGIScript.java ]]></source> <p>Finally we start the AGIServer:</p> <source><![CDATA[ $ java -cp commons-logging.jar:asterisk-java.jar:. net.sf.asterisk.fastagi.DefaultAGIServer ]]></source> <p>You should see some logging output indicating that the AGIServer has been successfully started and is listening for incoming connections:</p> <source><![CDATA[ Mar 11, 2005 10:20:12 PM net.sf.asterisk.fastagi.DefaultAGIServer run INFO: Thread pool started. Mar 11, 2005 10:20:12 PM net.sf.asterisk.fastagi.DefaultAGIServer run INFO: Listening on *:4573. ]]></source> <p>When you call extension 1300 you will see the AGI script being launched:</p> <source><![CDATA[ Mar 11, 2005 10:22:47 PM net.sf.asterisk.fastagi.DefaultAGIServer run INFO: Received connection. Mar 11, 2005 10:22:47 PM net.sf.asterisk.fastagi.AGIConnectionHandler run INFO: Begin AGIScript HelloAGIScript on AGIServer-TaskThread-0 Mar 11, 2005 10:22:48 PM net.sf.asterisk.fastagi.AGIConnectionHandler run INFO: End AGIScript HelloAGIScript on AGIServer-TaskThread-0 ]]></source> </subsection> <subsection name="Configuration"> <p>You can tune the DefaultAGIServer by setting two properties: The bindPort and the poolSize.</p> <p>The bindPort determines the TCP port the server will listen on. By default this is the FastAGI port 4573. If you change it make sure to include the new port in your URLs used in <code>extensions.conf</code>. When using bindPort 1234 your <code>extensions.conf</code> will look like:</p> <source><![CDATA[ exten => 1300,1,Agi(agi://localhost:1234/hello.agi) ]]></source> <p>To understand the poolSize property you need to know that the DefaultAGIServer uses a fixed size thread pool to serve your AGIScripts. The poolSize determines how many threads are spawned at startup and thus limits the number of AGIScripts that can run at the same time. So you should set the poolSize to at least the number of concurrent calls your AGIServer should be able to handle. The default value is 10.</p> <p>These configuration properties can be set by providing a <code>fastagi.properties</code> file on the classpath.</p> <p>This might look like:</p> <source><![CDATA[ bindPort = 1234 poolSize = 20 ]]></source> </subsection> </section> </body> </document> Index: navigation.xml =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/xdocs/navigation.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- navigation.xml 24 Feb 2005 23:05:18 -0000 1.2 +++ navigation.xml 11 Mar 2005 23:17:46 -0000 1.3 @@ -29,7 +29,7 @@ <item name="Mailing Lists" href="mail-lists.html"/> </menu> <menu name="Documentation"> - <item name="Samples" href="samples.html"/> + <item name="Tutorial" href="tutorial.html"/> </menu> <search/> <menu type="footer"> --- samples.xml DELETED --- |
|
From: Stefan R. <sr...@us...> - 2005-03-11 23:15:49
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17071/src/java/net/sf/asterisk/fastagi/command Modified Files: GetDataCommand.java Log Message: Added Constructor with file and timeout Index: GetDataCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/GetDataCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- GetDataCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ GetDataCommand.java 11 Mar 2005 23:15:39 -0000 1.3 @@ -64,7 +64,23 @@ public class GetDataCommand extends AGIC } /** - * Creates a new GetDataCommand. + * Creates a new GetDataCommand with the given timeout and maxDigits set to + * 1024. + * + * @param file the name of the file to stream, must not include extension. + * @param timeout the timeout to wait for data.<br> + * 0 means standard timeout value, -1 means "ludicrous time" + * (essentially never times out). + */ + public GetDataCommand(String file, int timeout) + { + this.file = file; + this.timeout = timeout; + this.maxDigits = 1024; + } + + /** + * Creates a new GetDataCommand with the given timeout and maxDigits. * * @param file the name of the file to stream, must not include extension. * @param timeout the timeout to wait for data.<br> |
|
From: Stefan R. <sr...@us...> - 2005-03-11 22:30:05
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5191/src/java/net/sf/asterisk/manager Modified Files: DefaultManagerConnection.java Log Message: Replaced @see references to impl classes by references to the appropriate interface Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -p -r1.11 -r1.12 --- DefaultManagerConnection.java 11 Mar 2005 15:27:22 -0000 1.11 +++ DefaultManagerConnection.java 11 Mar 2005 22:29:54 -0000 1.12 @@ -513,7 +513,7 @@ public class DefaultManagerConnection im * * @param response the resonse received by the reader * - * @see ManagerReaderImpl + * @see ManagerReader */ public void dispatchResponse(ManagerResponse response) { @@ -581,7 +581,7 @@ public class DefaultManagerConnection im * * @see #addEventHandler(ManagerEventHandler) * @see #removeEventHandler(ManagerEventHandler) - * @see ManagerReaderImpl + * @see ManagerReader */ public void dispatchEvent(ManagerEvent event) { |
|
From: Stefan R. <sr...@us...> - 2005-03-11 22:28:02
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4693/src/java/net/sf/asterisk/manager Modified Files: ManagerReader.java Log Message: Fixed parameter javadoc Index: ManagerReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerReader.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -p -r1.10 -r1.11 --- ManagerReader.java 11 Mar 2005 15:27:22 -0000 1.10 +++ ManagerReader.java 11 Mar 2005 22:27:49 -0000 1.11 @@ -49,7 +49,7 @@ public interface ManagerReader extends R * @see EventBuilder * @see ManagerEvent * - * @param eventClass class of the event to register. + * @param event class of the event to register. */ void registerEventClass(Class event); |
|
From: Stefan R. <sr...@us...> - 2005-03-11 22:28:01
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4693/src/java/net/sf/asterisk/fastagi/command Modified Files: SayDigitsCommand.java Log Message: Fixed parameter javadoc Index: SayDigitsCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SayDigitsCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- SayDigitsCommand.java 11 Mar 2005 19:32:11 -0000 1.4 +++ SayDigitsCommand.java 11 Mar 2005 22:27:49 -0000 1.5 @@ -48,9 +48,9 @@ public class SayDigitsCommand extends AG * * @param digits the digits to say. */ - public SayDigitsCommand(String number) + public SayDigitsCommand(String digits) { - this.digits = number; + this.digits = digits; this.escapeDigits = null; } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 20:15:28
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1009/src/java/net/sf/asterisk/fastagi Modified Files: AGIConnectionHandler.java Log Message: Added begin and end logging for AGIScript execution Index: AGIConnectionHandler.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIConnectionHandler.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- AGIConnectionHandler.java 11 Mar 2005 15:20:49 -0000 1.7 +++ AGIConnectionHandler.java 11 Mar 2005 20:15:15 -0000 1.8 @@ -82,6 +82,7 @@ public class AGIConnectionHandler implem AGIRequest request; AGIChannel channel; AGIScript script; + String threadName; reader = createReader(); writer = createWriter(); @@ -91,10 +92,13 @@ public class AGIConnectionHandler implem script = mappingStrategy.determineScript(request); + threadName = Thread.currentThread().getName(); + if (script != null) { - logger.info("Running AGIScript " + script.getClass().getName()); + logger.info("Begin AGIScript " + script.getClass().getName() + " on " + threadName); script.service(request, channel); + logger.info("End AGIScript " + script.getClass().getName() + " on " + threadName); } else { @@ -118,6 +122,7 @@ public class AGIConnectionHandler implem } catch (IOException e) { + // swallow } } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 19:50:52
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27145/src/java/net/sf/asterisk/fastagi/command Modified Files: SetMusicOnCommand.java Log Message: Added constructor with musicOnHoldClass parameter Index: SetMusicOnCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SetMusicOnCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SetMusicOnCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ SetMusicOnCommand.java 11 Mar 2005 19:50:35 -0000 1.3 @@ -45,6 +45,17 @@ public class SetMusicOnCommand extends A } /** + * Creates a new SetMusicOnCommand playing music from the default music on + * hold class. + * + * @param musicOnHoldClass the music on hold class to play music from. + */ + public SetMusicOnCommand(String musicOnHoldClass) + { + this.musicOnHoldClass = musicOnHoldClass; + } + + /** * Returns the music on hold class to play music from. * * @return the music on hold class to play music from or <code>null</code> |
|
From: Stefan R. <sr...@us...> - 2005-03-11 19:43:59
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25377/src/java/net/sf/asterisk/fastagi/impl Modified Files: AGIChannelImpl.java Log Message: Added command to message of InvalidOrUnknownCommandException Index: AGIChannelImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl/AGIChannelImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- AGIChannelImpl.java 11 Mar 2005 19:34:55 -0000 1.2 +++ AGIChannelImpl.java 11 Mar 2005 19:43:48 -0000 1.3 @@ -61,7 +61,7 @@ public class AGIChannelImpl implements A if (reply.getStatus() == AGIReply.SC_INVALID_OR_UNKNOWN_COMMAND) { - throw new InvalidOrUnknownCommandException(); + throw new InvalidOrUnknownCommandException(command.buildCommand()); } if (reply.getStatus() == AGIReply.SC_INVALID_COMMAND_SYNTAX) { |
|
From: Stefan R. <sr...@us...> - 2005-03-11 19:43:59
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25377/src/java/net/sf/asterisk/fastagi Modified Files: InvalidOrUnknownCommandException.java Log Message: Added command to message of InvalidOrUnknownCommandException Index: InvalidOrUnknownCommandException.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/InvalidOrUnknownCommandException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- InvalidOrUnknownCommandException.java 11 Mar 2005 19:34:55 -0000 1.1 +++ InvalidOrUnknownCommandException.java 11 Mar 2005 19:43:48 -0000 1.2 @@ -33,11 +33,10 @@ public class InvalidOrUnknownCommandExce /** * Creates a new InvalidOrUnknownCommandException. * - * @param synopsis the synopsis of the command. - * @param usage the usage of the command. + * @param command the invalid or unknown command. */ - public InvalidOrUnknownCommandException() + public InvalidOrUnknownCommandException(String command) { - super("Invalid or unknown command."); + super("Invalid or unknown command: " + command); } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 19:35:08
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23072/src/java/net/sf/asterisk/fastagi/impl Modified Files: AGIChannelImpl.java Log Message: Fixed InvalidCommandSyntaxException and InvalidOrUnknownCommandException Index: AGIChannelImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl/AGIChannelImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIChannelImpl.java 11 Mar 2005 15:20:50 -0000 1.1 +++ AGIChannelImpl.java 11 Mar 2005 19:34:55 -0000 1.2 @@ -20,6 +20,8 @@ import net.sf.asterisk.fastagi.AGIChanne import net.sf.asterisk.fastagi.AGIException; import net.sf.asterisk.fastagi.AGIReader; import net.sf.asterisk.fastagi.AGIWriter; +import net.sf.asterisk.fastagi.InvalidCommandSyntaxException; +import net.sf.asterisk.fastagi.InvalidOrUnknownCommandException; import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; @@ -35,27 +37,38 @@ public class AGIChannelImpl implements A private AGIWriter agiWriter; private AGIReader agiReader; private SocketConnectionFacade socket; - + public AGIChannelImpl(SocketConnectionFacade socket) { this.socket = socket; this.agiWriter = new AGIWriterImpl(socket); this.agiReader = new AGIReaderImpl(socket); } - + public AGIChannelImpl(AGIWriter agiWriter, AGIReader agiReader) { this.agiWriter = agiWriter; this.agiReader = agiReader; } - - public synchronized AGIReply sendCommand(AGICommand command) throws AGIException + + public synchronized AGIReply sendCommand(AGICommand command) + throws AGIException { AGIReply reply; - + agiWriter.sendCommand(command); reply = agiReader.readReply(); - + + if (reply.getStatus() == AGIReply.SC_INVALID_OR_UNKNOWN_COMMAND) + { + throw new InvalidOrUnknownCommandException(); + } + if (reply.getStatus() == AGIReply.SC_INVALID_COMMAND_SYNTAX) + { + throw new InvalidCommandSyntaxException(reply.getSynopsis(), reply + .getUsage()); + } + return reply; } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 19:35:06
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23072/src/java/net/sf/asterisk/fastagi Added Files: InvalidOrUnknownCommandException.java InvalidCommandSyntaxException.java Log Message: Fixed InvalidCommandSyntaxException and InvalidOrUnknownCommandException --- NEW FILE: InvalidOrUnknownCommandException.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; /** * An InvalidOrUnknownCommandException is thrown when the reader receives a reply * with status code 510. * * @author srt * @version $Id: InvalidOrUnknownCommandException.java,v 1.1 2005/03/11 19:34:55 srt Exp $ */ public class InvalidOrUnknownCommandException extends AGIException { /** * Serial version identifier. */ private static final long serialVersionUID = 3257002168165807929L; /** * Creates a new InvalidOrUnknownCommandException. * * @param synopsis the synopsis of the command. * @param usage the usage of the command. */ public InvalidOrUnknownCommandException() { super("Invalid or unknown command."); } } --- NEW FILE: InvalidCommandSyntaxException.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; /** * An InvalidCommandSyntaxException is thrown when the reader receives a reply * with status code 520. * * @author srt * @version $Id: InvalidCommandSyntaxException.java,v 1.1 2005/03/11 19:34:55 srt Exp $ */ public class InvalidCommandSyntaxException extends AGIException { /** * Serial version identifier. */ private static final long serialVersionUID = 3257002168165807929L; private String synopsis; private String usage; /** * Creates a new InvalidCommandSyntaxException with the given synopsis and * usage. * * @param synopsis the synopsis of the command. * @param usage the usage of the command. */ public InvalidCommandSyntaxException(String synopsis, String usage) { super("Invalid command syntax: " + synopsis); this.synopsis = synopsis; this.usage = usage; } /** * Returns the synopsis of the command that was called with invalid syntax. * * @return the synopsis of the command that was called with invalid syntax. */ public String getSynopsis() { return synopsis; } /** * Returns a description of the command that was called with invalid syntax. * * @return a description of the command that was called with invalid syntax. */ public String getUsage() { return usage; } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 19:32:22
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22316/src/java/net/sf/asterisk/fastagi/command Modified Files: SayDigitsCommand.java Log Message: Fixed buildCommand (SAY DIGITS instead of STREAM DIGITS) Index: SayDigitsCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SayDigitsCommand.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- SayDigitsCommand.java 10 Mar 2005 21:48:11 -0000 1.3 +++ SayDigitsCommand.java 11 Mar 2005 19:32:11 -0000 1.4 @@ -2,7 +2,7 @@ * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this number except in compliance with the License. + * you may not use this digits except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 @@ -17,7 +17,7 @@ package net.sf.asterisk.fastagi.command; /** - * Say a given digit string, returning early if any of the given DTMF number are + * Say a given digit string, returning early if any of the given DTMF digits are * received on the channel.<br> * Returns 0 if playback completes without a digit being pressed, or the ASCII * numerical value of the digit if one was pressed or -1 on error/hangup. @@ -33,12 +33,12 @@ public class SayDigitsCommand extends AG private static final long serialVersionUID = 3907207173934101552L; /** - * The number to say. + * The digits string to say. */ - private String number; + private String digits; /** - * When one of these digits is pressed while saying the number the command + * When one of these digits is pressed while saying the digits the command * returns. */ private String escapeDigits; @@ -46,45 +46,45 @@ public class SayDigitsCommand extends AG /** * Creates a new SayDigitsCommand. * - * @param number the number to say. + * @param digits the digits to say. */ public SayDigitsCommand(String number) { - this.number = number; + this.digits = number; this.escapeDigits = null; } /** * Creates a new SayDigitsCommand. * - * @param number the number to say. + * @param digits the digits to say. * @param escapeDigits the digits that allow the user to interrupt this * command. */ - public SayDigitsCommand(String number, String escapeDigits) + public SayDigitsCommand(String digits, String escapeDigits) { - this.number = number; + this.digits = digits; this.escapeDigits = escapeDigits; } /** - * Returns the number to say. + * Returns the digits string to say. * - * @return the number to say. + * @return the digits string to say. */ - public String getNumber() + public String getDigits() { - return number; + return digits; } /** - * Sets the number to say. + * Sets the digits to say. * - * @param number the number to say. + * @param digits the digits string to say. */ - public void setNumber(String number) + public void setDigits(String digits) { - this.number = number; + this.digits = digits; } /** @@ -110,7 +110,7 @@ public class SayDigitsCommand extends AG public String buildCommand() { - return "STREAM DIGITS " + escapeAndQuote(number) + " " + return "SAY DIGITS " + escapeAndQuote(digits) + " " + escapeAndQuote(escapeDigits); } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 19:01:14
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13889/src/java/net/sf/asterisk/fastagi/command Modified Files: SayNumberCommand.java Log Message: Renamed interruptDigits to escapeDigits Index: SayNumberCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SayNumberCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SayNumberCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ SayNumberCommand.java 11 Mar 2005 19:01:02 -0000 1.3 @@ -40,7 +40,7 @@ public class SayNumberCommand extends AG /** * When one of these number is pressed while streaming the command returns. */ - private String interruptDigits; + private String escapeDigits; /** * Creates a new SayNumberCommand. @@ -50,20 +50,20 @@ public class SayNumberCommand extends AG public SayNumberCommand(String number) { this.number = number; - this.interruptDigits = null; + this.escapeDigits = null; } /** * Creates a new SayNumberCommand. * * @param number the number to say. - * @param interruptDigits contains the number that allow the user to + * @param escapeDigits contains the number that allow the user to * interrupt this command. */ - public SayNumberCommand(String number, String interruptDigits) + public SayNumberCommand(String number, String escapeDigits) { this.number = number; - this.interruptDigits = interruptDigits; + this.escapeDigits = escapeDigits; } /** @@ -91,25 +91,25 @@ public class SayNumberCommand extends AG * * @return the number that allow the user to interrupt this command. */ - public String getInterruptDigits() + public String getEscapeDigits() { - return interruptDigits; + return escapeDigits; } /** * Sets the number that allow the user to interrupt this command. * - * @param interruptDigits the number that allow the user to interrupt this + * @param escapeDigits the number that allow the user to interrupt this * command or <code>null</code> for none. */ - public void setInterruptDigits(String interruptDigits) + public void setEscapeDigits(String escapeDigits) { - this.interruptDigits = interruptDigits; + this.escapeDigits = escapeDigits; } public String buildCommand() { return "SAY NUMBER " + escapeAndQuote(number) + " " - + escapeAndQuote(interruptDigits); + + escapeAndQuote(escapeDigits); } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 16:18:24
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3378/src/java/net/sf/asterisk/fastagi Modified Files: AbstractAGIScript.java Log Message: Added streamFile() methods Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- AbstractAGIScript.java 11 Mar 2005 14:15:35 -0000 1.6 +++ AbstractAGIScript.java 11 Mar 2005 16:18:13 -0000 1.7 @@ -23,6 +23,7 @@ import net.sf.asterisk.fastagi.command.S import net.sf.asterisk.fastagi.command.SetExtensionCommand; import net.sf.asterisk.fastagi.command.SetPriorityCommand; import net.sf.asterisk.fastagi.command.SetVariableCommand; +import net.sf.asterisk.fastagi.command.StreamFileCommand; import net.sf.asterisk.fastagi.reply.AGIReply; /** @@ -69,6 +70,35 @@ public abstract class AbstractAGIScript } /** + * Plays the given file. + * + * @param file name of the file to play. + */ + protected void streamFile(AGIChannel channel, String file) + throws AGIException + { + channel.sendCommand(new StreamFileCommand(file)); + } + + /** + * Plays the given file and allows the user to escape by pressing one of the + * given digit. + * + * @param file name of the file to play. + * @param escapeDigits a String containing the dtmf digits that allow the + * user to escape. + * @return the dtmf digit pressed or 0x0 if none was pressed. + */ + protected char streamFile(AGIChannel channel, String file, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new StreamFileCommand(file, escapeDigits)); + return reply.getResultCodeAsChar(); + } + + /** * Returns the value of the given channel variable. * * @param name the name of the variable to retrieve. |
|
From: Stefan R. <sr...@us...> - 2005-03-11 15:32:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24116/src/java/net/sf/asterisk/manager/impl Modified Files: ManagerReaderImpl.java Log Message: Moved DateUtil to net.sf.asterisk.util Index: ManagerReaderImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/impl/ManagerReaderImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ManagerReaderImpl.java 11 Mar 2005 15:27:23 -0000 1.1 +++ ManagerReaderImpl.java 11 Mar 2005 15:31:48 -0000 1.2 @@ -34,7 +34,7 @@ import net.sf.asterisk.manager.event.Dis import net.sf.asterisk.manager.event.ManagerEvent; import net.sf.asterisk.manager.response.CommandResponse; import net.sf.asterisk.manager.response.ManagerResponse; -import net.sf.asterisk.manager.util.DateUtil; +import net.sf.asterisk.util.DateUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; |
|
From: Stefan R. <sr...@us...> - 2005-03-11 15:32:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24116/src/test/net/sf/asterisk/manager/impl Modified Files: ManagerReaderImplTest.java Log Message: Moved DateUtil to net.sf.asterisk.util Index: ManagerReaderImplTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/impl/ManagerReaderImplTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ManagerReaderImplTest.java 11 Mar 2005 15:27:24 -0000 1.1 +++ ManagerReaderImplTest.java 11 Mar 2005 15:31:47 -0000 1.2 @@ -32,7 +32,7 @@ import net.sf.asterisk.manager.event.Dis import net.sf.asterisk.manager.event.StatusCompleteEvent; import net.sf.asterisk.manager.response.CommandResponse; import net.sf.asterisk.manager.response.ManagerResponse; -import net.sf.asterisk.manager.util.DateUtil; +import net.sf.asterisk.util.DateUtil; import org.easymock.MockControl; |
|
From: Stefan R. <sr...@us...> - 2005-03-11 15:32:03
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24116/src/java/net/sf/asterisk/util Added Files: DateUtil.java Log Message: Moved DateUtil to net.sf.asterisk.util --- NEW FILE: DateUtil.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.util; import java.util.Date; /** * Utility class to obtain the current date and allows to override with a fixed value for testing. * * @author srt * @version $Id: DateUtil.java,v 1.1 2005/03/11 15:31:47 srt Exp $ */ public class DateUtil { private static Date currentDate; private DateUtil() { } /** * If set to a non null value uses the date given as current date on calls to getDate(). Set to * null to restore the normal behavior. * * @param currentDate the date to return on calls to getDate() or <code>null</code> to return * the real current date. */ public static void overrideCurrentDate(Date currentDate) { DateUtil.currentDate = currentDate; } /** * Returns the real current date or the date set with overrideCurrentDate(). * * @return the real current date or the date set with overrideCurrentDate(). */ public static Date getDate() { if (currentDate != null) { return currentDate; } else { return new Date(); } } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 15:32:00
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24116/src/java/net/sf/asterisk/manager/util Removed Files: DateUtil.java Log Message: Moved DateUtil to net.sf.asterisk.util --- DateUtil.java DELETED --- |
|
From: Stefan R. <sr...@us...> - 2005-03-11 15:27:37
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22772/src/test/net/sf/asterisk/manager/impl Added Files: ResponseBuilderImplTest.java ManagerReaderImplTest.java EventBuilderImplTest.java ManagerWriterImplTest.java ActionBuilderImplTest.java Log Message: Refactored private implementation classes into impl subpackage --- NEW FILE: ResponseBuilderImplTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.manager.impl; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import net.sf.asterisk.manager.ResponseBuilder; import net.sf.asterisk.manager.response.ChallengeResponse; import net.sf.asterisk.manager.response.ExtensionStateResponse; import net.sf.asterisk.manager.response.MailboxCountResponse; import net.sf.asterisk.manager.response.MailboxStatusResponse; import net.sf.asterisk.manager.response.ManagerError; import net.sf.asterisk.manager.response.ManagerResponse; public class ResponseBuilderImplTest extends TestCase { private ResponseBuilder responseBuilder; private Map attributes; public void setUp() { this.responseBuilder = new ResponseBuilderImpl(); this.attributes = new HashMap(); } public void testBuildResponse() { ManagerResponse response; attributes.put("response", "Success"); response = responseBuilder.buildResponse(attributes); assertEquals("Response of wrong type", ManagerResponse.class, response.getClass()); assertEquals("Response not set correctly", "Success", response.getResponse()); } public void testBuildError() { ManagerResponse response; attributes.put("response", "Error"); attributes.put("message", "Missing action in request"); response = responseBuilder.buildResponse(attributes); assertEquals("Response of wrong type", ManagerError.class, response.getClass()); assertEquals("Message not set correctly", "Missing action in request", response.getMessage()); } public void testBuildErrorWithActionId() { ManagerResponse response; attributes.put("response", "Error"); attributes.put("actionid", "1234"); attributes.put("message", "Missing action in request"); response = responseBuilder.buildResponse(attributes); assertEquals("ActionId not set correctly", "1234", response.getActionId()); } public void testBuildChallengeResponse() { ManagerResponse response; attributes.put("response", "Success"); attributes.put("challenge", "131494410"); response = responseBuilder.buildResponse(attributes); assertEquals("Response of wrong type", ChallengeResponse.class, response.getClass()); assertEquals("Challenge not set correctly", "131494410", ((ChallengeResponse) response).getChallenge()); } public void testBuildMailboxStatusResponse() { ManagerResponse response; attributes.put("response", "Success"); attributes.put("message", "Mailbox Status"); attributes.put("mailbox", "123"); attributes.put("waiting", "1"); response = responseBuilder.buildResponse(attributes); assertEquals("Response of wrong type", MailboxStatusResponse.class, response.getClass()); MailboxStatusResponse mailboxStatusResponse = (MailboxStatusResponse) response; assertEquals("Mailbox not set correctly", "123", mailboxStatusResponse.getMailbox()); assertEquals("Waiting not set correctly", Boolean.TRUE, mailboxStatusResponse.getWaiting()); } public void testBuildMailboxStatusResponseWithNoWaiting() { ManagerResponse response; attributes.put("response", "Success"); attributes.put("message", "Mailbox Status"); attributes.put("mailbox", "123,user2"); attributes.put("waiting", "0"); response = responseBuilder.buildResponse(attributes); assertEquals("Response of wrong type", MailboxStatusResponse.class, response.getClass()); MailboxStatusResponse mailboxStatusResponse = (MailboxStatusResponse) response; assertEquals("Mailbox not set correctly", "123,user2", mailboxStatusResponse.getMailbox()); assertEquals("Waiting not set correctly", Boolean.FALSE, mailboxStatusResponse.getWaiting()); } public void testBuildMailboxCountResponse() { ManagerResponse response; attributes.put("response", "Success"); attributes.put("message", "Mailbox Message Count"); attributes.put("mailbox", "123@myctx"); attributes.put("newmessages", "2"); attributes.put("oldmessages", "5"); response = responseBuilder.buildResponse(attributes); assertEquals("Response of wrong type", MailboxCountResponse.class, response.getClass()); MailboxCountResponse mailboxCountResponse = (MailboxCountResponse) response; assertEquals("Mailbox not set correctly", "123@myctx", mailboxCountResponse.getMailbox()); assertEquals("New messages not set correctly", new Integer(2), mailboxCountResponse.getNewMessages()); assertEquals("Old messages set correctly", new Integer(5), mailboxCountResponse.getOldMessages()); } public void testBuildExtensionStateResponse() { ManagerResponse response; attributes.put("response", "Success"); attributes.put("message", "Extension Status"); attributes.put("exten", "1"); attributes.put("context", "default"); attributes.put("hint", ""); attributes.put("status", "-1"); response = responseBuilder.buildResponse(attributes); assertEquals("Response of wrong type", ExtensionStateResponse.class, response.getClass()); ExtensionStateResponse extensionStateResponse = (ExtensionStateResponse) response; assertEquals("Exten not set correctly", "1", extensionStateResponse.getExten()); assertEquals("Context not set correctly", "default", extensionStateResponse.getContext()); assertEquals("Hint not set correctly", "", extensionStateResponse.getHint()); assertEquals("Status not set correctly", new Integer(-1), extensionStateResponse.getStatus()); } } --- NEW FILE: ManagerReaderImplTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.manager.impl; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import junit.framework.TestCase; import net.sf.asterisk.io.SocketConnectionFacade; import net.sf.asterisk.manager.AsteriskServer; import net.sf.asterisk.manager.Dispatcher; import net.sf.asterisk.manager.ManagerReader; import net.sf.asterisk.manager.MyUserEvent; import net.sf.asterisk.manager.event.ConnectEvent; import net.sf.asterisk.manager.event.DisconnectEvent; import net.sf.asterisk.manager.event.StatusCompleteEvent; import net.sf.asterisk.manager.response.CommandResponse; import net.sf.asterisk.manager.response.ManagerResponse; import net.sf.asterisk.manager.util.DateUtil; import org.easymock.MockControl; public class ManagerReaderImplTest extends TestCase { private Date now; private MockControl dispatcherMC; private Dispatcher dispatcher; private MockControl socketConnectionFacadeMC; private SocketConnectionFacade socketConnectionFacade; private AsteriskServer asteriskServer; private ManagerReader managerReader; protected void setUp() { now = new Date(); DateUtil.overrideCurrentDate(now); asteriskServer = new AsteriskServer(); dispatcherMC = MockControl.createControl(Dispatcher.class); dispatcher = (Dispatcher) dispatcherMC.getMock(); managerReader = new ManagerReaderImpl(dispatcher, asteriskServer); socketConnectionFacadeMC = MockControl.createControl(SocketConnectionFacade.class); socketConnectionFacade = (SocketConnectionFacade) socketConnectionFacadeMC.getMock(); } protected void tearDown() { DateUtil.overrideCurrentDate(null); } public void testRunWithoutSocket() throws Exception { try { managerReader.run(); fail("Must throw IllegalStateException"); } catch (IllegalStateException e) { assertTrue("Exception must be of type IllegalStateException", e instanceof IllegalStateException); } } public void testRunReceivingProtocolIdentifier() throws Exception { ConnectEvent connectEvent; DisconnectEvent disconnectEvent; socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Asterisk Call Manager/1.0"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(null); connectEvent = new ConnectEvent(asteriskServer); connectEvent.setProtocolIdentifier("Asterisk Call Manager/1.0"); connectEvent.setDateReceived(now); dispatcher.dispatchEvent(connectEvent); disconnectEvent = new DisconnectEvent(asteriskServer); disconnectEvent.setDateReceived(now); dispatcher.dispatchEvent(disconnectEvent); socketConnectionFacadeMC.replay(); dispatcherMC.replay(); managerReader.setSocket(socketConnectionFacade); managerReader.run(); socketConnectionFacadeMC.verify(); dispatcherMC.verify(); } public void testRunReceivingEvent() throws Exception { DisconnectEvent disconnectEvent; StatusCompleteEvent statusCompleteEvent; socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Event: StatusComplete"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(""); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(null); statusCompleteEvent = new StatusCompleteEvent(asteriskServer); statusCompleteEvent.setDateReceived(now); dispatcher.dispatchEvent(statusCompleteEvent); disconnectEvent = new DisconnectEvent(asteriskServer); disconnectEvent.setDateReceived(now); dispatcher.dispatchEvent(disconnectEvent); socketConnectionFacadeMC.replay(); dispatcherMC.replay(); managerReader.setSocket(socketConnectionFacade); managerReader.run(); socketConnectionFacadeMC.verify(); dispatcherMC.verify(); } public void testRunReceivingUserEvent() throws Exception { DisconnectEvent disconnectEvent; MyUserEvent myUserEvent; managerReader.registerEventClass(MyUserEvent.class); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Event: MyUser"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(""); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(null); myUserEvent = new MyUserEvent(asteriskServer); myUserEvent.setDateReceived(now); dispatcher.dispatchEvent(myUserEvent); disconnectEvent = new DisconnectEvent(asteriskServer); disconnectEvent.setDateReceived(now); dispatcher.dispatchEvent(disconnectEvent); socketConnectionFacadeMC.replay(); dispatcherMC.replay(); managerReader.setSocket(socketConnectionFacade); managerReader.run(); socketConnectionFacadeMC.verify(); dispatcherMC.verify(); } public void testRunReceivingResponse() throws Exception { DisconnectEvent disconnectEvent; ManagerResponse response; socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Response: Success"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Message: Authentication accepted"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(""); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(null); response = new ManagerResponse(); response.setResponse("Success"); response.setMessage("Authentication accepted"); response.setDateReceived(now); dispatcher.dispatchResponse(response); disconnectEvent = new DisconnectEvent(asteriskServer); disconnectEvent.setDateReceived(now); dispatcher.dispatchEvent(disconnectEvent); socketConnectionFacadeMC.replay(); dispatcherMC.replay(); managerReader.setSocket(socketConnectionFacade); managerReader.run(); socketConnectionFacadeMC.verify(); dispatcherMC.verify(); } public void testRunReceivingCommandResponse() throws Exception { DisconnectEvent disconnectEvent; CommandResponse response; List result = new ArrayList(); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Response: Follows"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("ActionID: 12345"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Line1"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("Line2"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue("--END COMMAND--"); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(""); socketConnectionFacade.readLine(); socketConnectionFacadeMC.setReturnValue(null); response = new CommandResponse(); response.setResponse("Follows"); response.setActionId("12345"); result.add("Line1"); result.add("Line2"); response.setResult(result); response.setDateReceived(now); dispatcher.dispatchResponse(response); disconnectEvent = new DisconnectEvent(asteriskServer); disconnectEvent.setDateReceived(now); dispatcher.dispatchEvent(disconnectEvent); socketConnectionFacadeMC.replay(); dispatcherMC.replay(); managerReader.setSocket(socketConnectionFacade); managerReader.run(); socketConnectionFacadeMC.verify(); dispatcherMC.verify(); } public void testRunCatchingIOException() throws Exception { DisconnectEvent disconnectEvent; socketConnectionFacade.readLine(); socketConnectionFacadeMC.setThrowable(new IOException("Something happened to the network...")); disconnectEvent = new DisconnectEvent(asteriskServer); disconnectEvent.setDateReceived(now); dispatcher.dispatchEvent(disconnectEvent); socketConnectionFacadeMC.replay(); dispatcherMC.replay(); managerReader.setSocket(socketConnectionFacade); managerReader.run(); socketConnectionFacadeMC.verify(); dispatcherMC.verify(); } } --- NEW FILE: EventBuilderImplTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.manager.impl; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import net.sf.asterisk.manager.EventBuilder; import net.sf.asterisk.manager.event.CdrEvent; import net.sf.asterisk.manager.event.ChannelEvent; import net.sf.asterisk.manager.event.ManagerEvent; import net.sf.asterisk.manager.event.NewChannelEvent; import net.sf.asterisk.manager.event.NewExtenEvent; import net.sf.asterisk.manager.event.ResponseEvent; import net.sf.asterisk.manager.event.ShutdownEvent; import net.sf.asterisk.manager.event.StatusCompleteEvent; /** * @author srt * @version $Id: EventBuilderImplTest.java,v 1.1 2005/03/11 15:27:24 srt Exp $ */ public class EventBuilderImplTest extends TestCase { private EventBuilder eventBuilder; public void setUp() { this.eventBuilder = new EventBuilderImpl(); } public void testRegisterEvent() { eventBuilder.registerEventClass(NewChannelEvent.class); } public void testRegisterEventWithAbstractEvent() { try { eventBuilder.registerEventClass(ChannelEvent.class); fail("registerEvent() must not accept abstract classes"); } catch (IllegalArgumentException ex) { } } public void testRegisterEventWithWrongClass() { try { eventBuilder.registerEventClass(String.class); fail("registerEvent() must only accept subclasses of ManagerEvent"); } catch (IllegalArgumentException ex) { } } /* * public void testGetSetters() { Map setters; EventBuilderImpl eventBuilder = * getEventBuilder(); * * setters = eventBuilder.getSetters(NewChannelEvent.class); * * assertTrue("Setter not found", setters.containsKey("callerid")); } */ public void testBuildEventWithMixedCaseSetter() { Map properties = new HashMap(); String callerid = "1234"; NewChannelEvent event; properties.put("event", "Newchannel"); properties.put("callerid", callerid); event = (NewChannelEvent) eventBuilder.buildEvent(this, properties); assertNotNull(event); assertEquals("Returned event is of wrong type", NewChannelEvent.class, event.getClass()); assertEquals("String property not set correctly", callerid, event.getCallerId()); assertEquals("Source not set correctly", this, event.getSource()); } public void testBuildEventWithIntegerProperty() { Map properties = new HashMap(); String channel = "SIP/1234"; Integer priority = new Integer(1); NewExtenEvent event; properties.put("event", "newexten"); properties.put("channel", channel); properties.put("priority", priority.toString()); event = (NewExtenEvent) eventBuilder.buildEvent(this, properties); assertNotNull(event); assertEquals("Returned event is of wrong type", NewExtenEvent.class, event.getClass()); assertEquals("String property not set correctly", channel, event.getChannel()); assertEquals("Integer property not set correctly", priority, event.getPriority()); } public void testBuildEventWithBooleanProperty() { Map properties = new HashMap(); ShutdownEvent event; eventBuilder.registerEventClass(ShutdownEvent.class); properties.put("event", "shutdown"); properties.put("restart", "True"); event = (ShutdownEvent) eventBuilder.buildEvent(this, properties); assertNotNull(event); assertEquals("Returned event is of wrong type", ShutdownEvent.class, event.getClass()); assertEquals("Boolean property not set correctly", Boolean.TRUE, event.getRestart()); } public void testBuildEventWithUnregisteredEvent() { Map properties = new HashMap(); ManagerEvent event; properties.put("event", "Nonexisting"); event = eventBuilder.buildEvent(this, properties); assertNull(event); } public void testBuildEventWithEmptyAttributes() { Map properties = new HashMap(); ManagerEvent event; event = eventBuilder.buildEvent(this, properties); assertNull(event); } public void testBuildEventWithResponseEvent() { Map properties = new HashMap(); ManagerEvent event; properties.put("event", "StatusComplete"); properties.put("actionid", "1234-origId"); event = eventBuilder.buildEvent(this, properties); assertNotNull(event); assertEquals("Returned event is of wrong type", StatusCompleteEvent.class, event.getClass()); assertEquals("ActionId not set correctly", "origId", ((ResponseEvent) event).getActionId()); } public void testBuildEventWithSourceProperty() { Map properties = new HashMap(); ManagerEvent event; properties.put("event", "Cdr"); properties.put("source", "source value"); event = eventBuilder.buildEvent(this, properties); assertNotNull(event); assertEquals("Src property not set correctly", "source value", ((CdrEvent) event).getSrc()); } } --- NEW FILE: ManagerWriterImplTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.manager.impl; import junit.framework.TestCase; import net.sf.asterisk.io.SocketConnectionFacade; import net.sf.asterisk.manager.ManagerWriter; import net.sf.asterisk.manager.action.StatusAction; import org.easymock.MockControl; public class ManagerWriterImplTest extends TestCase { private ManagerWriter managerWriter; public void setUp() { managerWriter = new ManagerWriterImpl(); } public void testSendActionWithoutSocket() throws Exception { try { managerWriter.sendAction(new StatusAction()); fail("Must throw IllegalStateException"); } catch (IllegalStateException e) { assertTrue("Exception must be of type IllegalStateException", e instanceof IllegalStateException); } } public void testSendAction() throws Exception { MockControl socketMC; SocketConnectionFacade socketConnectionFacade; socketMC = MockControl.createControl(SocketConnectionFacade.class); socketConnectionFacade = (SocketConnectionFacade) socketMC.getMock(); socketConnectionFacade.write("action: Status\r\n\r\n"); socketConnectionFacade.flush(); socketMC.replay(); managerWriter.setSocket(socketConnectionFacade); managerWriter.sendAction(new StatusAction()); socketMC.verify(); } } --- NEW FILE: ActionBuilderImplTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.manager.impl; import junit.framework.TestCase; import net.sf.asterisk.manager.ActionBuilder; import net.sf.asterisk.manager.action.ManagerAction; public class ActionBuilderImplTest extends TestCase { private ActionBuilder actionBuilder; public void setUp() { this.actionBuilder = new ActionBuilderImpl(); } public void testBuildAction() { MyAction myAction; String actual; myAction = new MyAction(); myAction.setFirstProperty("first value"); myAction.setSecondProperty(new Integer(2)); myAction.setNonPublicProperty("private"); actual = actionBuilder.buildAction(myAction); assertTrue("Action name missing", actual.indexOf("action: My\r\n") >= 0); assertTrue("First property missing", actual.indexOf("firstproperty: first value\r\n") >= 0); assertTrue("Second property missing", actual.indexOf("secondproperty: 2\r\n") >= 0); assertTrue("Missing trailing CRNL CRNL", actual.endsWith("\r\n\r\n")); assertEquals("Incorrect length", 61, actual.length()); } public void testBuildActionWithNullValue() { MyAction myAction; String actual; myAction = new MyAction(); myAction.setFirstProperty("first value"); actual = actionBuilder.buildAction(myAction); assertTrue("Action name missing", actual.indexOf("action: My\r\n") >= 0); assertTrue("First property missing", actual.indexOf("firstproperty: first value\r\n") >= 0); assertTrue("Missing trailing CRNL CRNL", actual.endsWith("\r\n\r\n")); assertEquals("Incorrect length", 42, actual.length()); } class MyAction extends ManagerAction { private static final long serialVersionUID = 3257568425345102641L; private String firstProperty; private Integer secondProperty; private String nonPublicProperty; public String getAction() { return "My"; } public String getFirstProperty() { return firstProperty; } public void setFirstProperty(String firstProperty) { this.firstProperty = firstProperty; } public Integer getSecondProperty() { return secondProperty; } public void setSecondProperty(Integer secondProperty) { this.secondProperty = secondProperty; } protected String getNonPublicProperty() { return nonPublicProperty; } protected void setNonPublicProperty(String privateProperty) { this.nonPublicProperty = privateProperty; } public String get() { return "This method must not be considered a getter"; } public String getIndexedProperty(int i) { return "This method must not be considered a getter relevant for building the action"; } } } |
|
From: Stefan R. <sr...@us...> - 2005-03-11 15:27:35
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22772/src/test/net/sf/asterisk/manager Removed Files: ManagerWriterImplTest.java ResponseBuilderImplTest.java ManagerReaderImplTest.java ActionBuilderImplTest.java EventBuilderImplTest.java Log Message: Refactored private implementation classes into impl subpackage --- ManagerWriterImplTest.java DELETED --- --- ResponseBuilderImplTest.java DELETED --- --- ManagerReaderImplTest.java DELETED --- --- ActionBuilderImplTest.java DELETED --- --- EventBuilderImplTest.java DELETED --- |