asterisk-java-cvs Mailing List for Asterisk-Java Library (Page 89)
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
(5) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
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 --- |
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22772/src/java/net/sf/asterisk/manager/impl Added Files: ResponseBuilderImpl.java EventBuilderImpl.java ManagerReaderImpl.java ManagerWriterImpl.java ActionBuilderImpl.java Log Message: Refactored private implementation classes into impl subpackage --- NEW FILE: ResponseBuilderImpl.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.Map; 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; /** * Default implementation of the ResponseBuilder interface. * * @see net.sf.asterisk.manager.response.ManagerResponse * @author srt * @version $Id: ResponseBuilderImpl.java,v 1.1 2005/03/11 15:27:23 srt Exp $ */ public class ResponseBuilderImpl implements ResponseBuilder { /** * Constructs an instance of ManagerResponse based on a map of attributes. * * @param attributes the attributes and their values. The keys of this map must be all lower * case. * @return the response with the given attributes. */ public ManagerResponse buildResponse(final Map attributes) { ManagerResponse response; String responseType; responseType = (String) attributes.get("response"); // determine type if ("error".equalsIgnoreCase(responseType)) { response = new ManagerError(); } else if (attributes.containsKey("challenge")) { ChallengeResponse challengeResponse = new ChallengeResponse(); challengeResponse.setChallenge((String) attributes.get("challenge")); response = challengeResponse; } else if (attributes.containsKey("mailbox") && attributes.containsKey("waiting")) { MailboxStatusResponse mailboxStatusResponse = new MailboxStatusResponse(); mailboxStatusResponse.setMailbox((String) attributes.get("mailbox")); if ("1".equals((String) attributes.get("waiting"))) { mailboxStatusResponse.setWaiting(Boolean.TRUE); } else { mailboxStatusResponse.setWaiting(Boolean.FALSE); } response = mailboxStatusResponse; } else if (attributes.containsKey("mailbox") && attributes.containsKey("newmessages") && attributes.containsKey("oldmessages")) { MailboxCountResponse mailboxCountResponse = new MailboxCountResponse(); mailboxCountResponse.setMailbox((String) attributes.get("mailbox")); mailboxCountResponse.setNewMessages(new Integer((String) attributes.get("newmessages"))); mailboxCountResponse.setOldMessages(new Integer((String) attributes.get("oldmessages"))); response = mailboxCountResponse; } else if (attributes.containsKey("exten") && attributes.containsKey("context") && attributes.containsKey("hint") && attributes.containsKey("status")) { ExtensionStateResponse extensionStateResponse = new ExtensionStateResponse(); extensionStateResponse.setExten((String) attributes.get("exten")); extensionStateResponse.setContext((String) attributes.get("context")); extensionStateResponse.setHint((String) attributes.get("hint")); extensionStateResponse.setStatus(new Integer((String) attributes.get("status"))); response = extensionStateResponse; } else { response = new ManagerResponse(); } // fill known attributes response.setResponse(responseType); if (attributes.containsKey("actionid")) { response.setActionId((String) attributes.get("actionid")); } if (attributes.containsKey("message")) { response.setMessage((String) attributes.get("message")); } if (attributes.containsKey("uniqueid")) { response.setUniqueId((String) attributes.get("uniqueid")); } return response; } } --- NEW FILE: EventBuilderImpl.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.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import net.sf.asterisk.manager.EventBuilder; import net.sf.asterisk.manager.Util; import net.sf.asterisk.manager.event.AgentCallbackLoginEvent; import net.sf.asterisk.manager.event.AgentCallbackLogoffEvent; import net.sf.asterisk.manager.event.AgentCalledEvent; import net.sf.asterisk.manager.event.AgentLoginEvent; import net.sf.asterisk.manager.event.AgentLogoffEvent; import net.sf.asterisk.manager.event.AlarmClearEvent; import net.sf.asterisk.manager.event.AlarmEvent; import net.sf.asterisk.manager.event.CdrEvent; import net.sf.asterisk.manager.event.DialEvent; import net.sf.asterisk.manager.event.ExtensionStatusEvent; import net.sf.asterisk.manager.event.HangupEvent; import net.sf.asterisk.manager.event.HoldedCallEvent; import net.sf.asterisk.manager.event.JoinEvent; import net.sf.asterisk.manager.event.LeaveEvent; import net.sf.asterisk.manager.event.LinkEvent; import net.sf.asterisk.manager.event.ManagerEvent; import net.sf.asterisk.manager.event.MeetMeJoinEvent; import net.sf.asterisk.manager.event.MeetMeLeaveEvent; import net.sf.asterisk.manager.event.MessageWaitingEvent; import net.sf.asterisk.manager.event.NewCallerIdEvent; import net.sf.asterisk.manager.event.NewChannelEvent; import net.sf.asterisk.manager.event.NewExtenEvent; import net.sf.asterisk.manager.event.NewStateEvent; import net.sf.asterisk.manager.event.OriginateFailureEvent; import net.sf.asterisk.manager.event.OriginateSuccessEvent; import net.sf.asterisk.manager.event.ParkedCallEvent; import net.sf.asterisk.manager.event.ParkedCallsCompleteEvent; import net.sf.asterisk.manager.event.PeerStatusEvent; import net.sf.asterisk.manager.event.QueueEntryEvent; import net.sf.asterisk.manager.event.QueueMemberEvent; import net.sf.asterisk.manager.event.QueueMemberStatusEvent; import net.sf.asterisk.manager.event.QueueParamsEvent; import net.sf.asterisk.manager.event.RegistryEvent; import net.sf.asterisk.manager.event.ReloadEvent; import net.sf.asterisk.manager.event.RenameEvent; import net.sf.asterisk.manager.event.ResponseEvent; import net.sf.asterisk.manager.event.ShutdownEvent; import net.sf.asterisk.manager.event.StatusCompleteEvent; import net.sf.asterisk.manager.event.StatusEvent; import net.sf.asterisk.manager.event.UnlinkEvent; import net.sf.asterisk.manager.event.ZapShowChannelsCompleteEvent; import net.sf.asterisk.manager.event.ZapShowChannelsEvent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Default implementation of the EventBuilder interface. * * @see net.sf.asterisk.manager.event.ManagerEvent * @author srt * @version $Id: EventBuilderImpl.java,v 1.1 2005/03/11 15:27:23 srt Exp $ */ public class EventBuilderImpl implements EventBuilder { private final Log logger = LogFactory.getLog(getClass()); private Map registeredEventClasses; public EventBuilderImpl() { this.registeredEventClasses = new HashMap(); registerBuiltinEventClasses(); } private void registerBuiltinEventClasses() { registerEventClass(AgentCallbackLoginEvent.class); registerEventClass(AgentCallbackLogoffEvent.class); registerEventClass(AgentCalledEvent.class); registerEventClass(AgentLoginEvent.class); registerEventClass(AgentLogoffEvent.class); registerEventClass(AlarmEvent.class); registerEventClass(AlarmClearEvent.class); registerEventClass(CdrEvent.class); registerEventClass(DialEvent.class); registerEventClass(ExtensionStatusEvent.class); registerEventClass(HangupEvent.class); registerEventClass(HoldedCallEvent.class); registerEventClass(JoinEvent.class); registerEventClass(LeaveEvent.class); registerEventClass(LinkEvent.class); registerEventClass(MeetMeJoinEvent.class); registerEventClass(MeetMeLeaveEvent.class); registerEventClass(MessageWaitingEvent.class); registerEventClass(NewCallerIdEvent.class); registerEventClass(NewChannelEvent.class); registerEventClass(NewExtenEvent.class); registerEventClass(NewStateEvent.class); registerEventClass(OriginateFailureEvent.class); registerEventClass(OriginateSuccessEvent.class); registerEventClass(ParkedCallEvent.class); registerEventClass(ParkedCallsCompleteEvent.class); registerEventClass(PeerStatusEvent.class); registerEventClass(QueueEntryEvent.class); registerEventClass(QueueMemberEvent.class); registerEventClass(QueueMemberStatusEvent.class); registerEventClass(QueueParamsEvent.class); registerEventClass(RegistryEvent.class); registerEventClass(ReloadEvent.class); registerEventClass(RenameEvent.class); registerEventClass(ShutdownEvent.class); registerEventClass(StatusEvent.class); registerEventClass(StatusCompleteEvent.class); registerEventClass(UnlinkEvent.class); registerEventClass(ZapShowChannelsEvent.class); registerEventClass(ZapShowChannelsCompleteEvent.class); } public void registerEventClass(Class clazz) { String className; String eventType; className = clazz.getName(); eventType = className.substring(className.lastIndexOf('.') + 1).toLowerCase(); if (eventType.endsWith("event")) { eventType = eventType.substring(0, eventType.length() - "event".length()); } registerEventClass(eventType, clazz); } /** * Registers a new event class for the event given by eventType. * * @param eventType the name of the event to register the class for. For example "Join". * @param clazz the event class to register, must extend net.sf.asterisk.manager.event.Event. */ public void registerEventClass(String eventType, Class clazz) { Constructor defaultConstructor; if (!ManagerEvent.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException(clazz + " is not a ManagerEvent"); } if ((clazz.getModifiers() & Modifier.ABSTRACT) != 0) { throw new IllegalArgumentException(clazz + " is abstract"); } try { defaultConstructor = clazz.getConstructor(new Class[]{Object.class}); } catch (NoSuchMethodException ex) { throw new IllegalArgumentException(clazz + " has no usable constructor"); } if ((defaultConstructor.getModifiers() & Modifier.PUBLIC) == 0) { throw new IllegalArgumentException(clazz + " has no public default constructor"); } registeredEventClasses.put(eventType.toLowerCase(), clazz); logger.debug("Registered event type '" + eventType + "' (" + clazz + ")"); } public ManagerEvent buildEvent(Object source, Map attributes) { ManagerEvent event; String eventType; Class eventClass; Constructor constructor; if (attributes.get("event") == null) { logger.error("No event event type in properties"); return null; } eventType = ((String) attributes.get("event")).toLowerCase(); eventClass = (Class) registeredEventClasses.get(eventType); if (eventClass == null) { logger.warn("No event class registered for event type '" + eventType + "', attributes: " + attributes); return null; } try { constructor = eventClass.getConstructor(new Class[]{Object.class}); } catch (NoSuchMethodException ex) { logger.error("Unable to get constructor of " + eventClass, ex); return null; } try { event = (ManagerEvent) constructor.newInstance(new Object[]{source}); } catch (Exception ex) { logger.error("Unable to create new instance of " + eventClass, ex); return null; } setAttributes(event, attributes); if (event instanceof ResponseEvent) { ResponseEvent responseEvent; String actionId; responseEvent = (ResponseEvent) event; actionId = responseEvent.getActionId(); if (actionId != null) { responseEvent.setActionId(Util.stripInternalActionId(actionId)); } } return event; } private void setAttributes(ManagerEvent event, Map attributes) { Map setters; setters = getSetters(event.getClass()); Iterator i = attributes.keySet().iterator(); while (i.hasNext()) { String name; Object value; Class dataType; Method setter; name = (String) i.next(); if ("event".equals(name)) { continue; } /* * The source property needs special handling as it is already defined in * java.util.EventObject (the base class of ManagerEvent), so we have to translate it. */ if ("source".equals(name)) { setter = (Method) setters.get("src"); } else { setter = (Method) setters.get(name); } if (setter == null) { logger.error("Unable to set property '" + name + "' on " + event.getClass() + ": no setter"); continue; } dataType = setter.getParameterTypes()[0]; if (dataType.isAssignableFrom(String.class)) { value = attributes.get(name); } else { try { Constructor constructor = dataType.getConstructor(new Class[]{String.class}); value = constructor.newInstance(new Object[]{attributes.get(name)}); } catch (Exception e) { logger.error("Unable to convert value '" + attributes.get(name) + "' of property '" + name + "' on " + event.getClass() + " to required type " + dataType, e); continue; } } try { setter.invoke(event, new Object[]{value}); } catch (Exception e) { logger.error("Unable to set property '" + name + "' on " + event.getClass(), e); continue; } } } private Map getSetters(Class clazz) { Map accessors = new HashMap(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { String name; String methodName; Method method = methods[i]; methodName = method.getName(); if (!methodName.startsWith("set")) { continue; } // skip methods with != 1 parameters if (method.getParameterTypes().length != 1) { continue; } // ok seems to be an accessor name = methodName.substring("set".length()).toLowerCase(); accessors.put(name, method); } return accessors; } } --- NEW FILE: ManagerReaderImpl.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.HashMap; import java.util.List; import java.util.Map; import net.sf.asterisk.io.SocketConnectionFacade; import net.sf.asterisk.manager.AsteriskServer; import net.sf.asterisk.manager.DefaultManagerConnection; import net.sf.asterisk.manager.Dispatcher; import net.sf.asterisk.manager.EventBuilder; import net.sf.asterisk.manager.ManagerReader; import net.sf.asterisk.manager.ResponseBuilder; import net.sf.asterisk.manager.event.ConnectEvent; import net.sf.asterisk.manager.event.DisconnectEvent; 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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Default implementation of the ManagerReader interface. * * @author srt * @version $Id: ManagerReaderImpl.java,v 1.1 2005/03/11 15:27:23 srt Exp $ */ public class ManagerReaderImpl implements ManagerReader { /** * Instance logger. */ private final Log logger = LogFactory.getLog(getClass()); /** * The event builder utility to convert a map of attributes reveived from asterisk to instances * of registered event classes. */ private final EventBuilder eventBuilder; /** * The response builder utility to convert a map of attributes reveived from asterisk to * instances of well known response classes. */ private final ResponseBuilder responseBuilder; /** * The dispatcher to use for dispatching events and responses. */ private final Dispatcher dispatcher; /** * The asterisk server we are reading from. */ private final AsteriskServer asteriskServer; /** * The socket to use for reading from the asterisk server. */ private SocketConnectionFacade socket; /** * If set to <code>true</code>, terminates and closes the reader. */ private boolean die = false; /** * Creates a new ManagerReaderImpl. * * @param dispatcher the dispatcher to use for dispatching events and responses. */ public ManagerReaderImpl(final Dispatcher dispatcher, AsteriskServer asteriskServer) { this.dispatcher = dispatcher; this.asteriskServer = asteriskServer; this.eventBuilder = new EventBuilderImpl(); this.responseBuilder = new ResponseBuilderImpl(); } /** * Sets the socket to use for reading from the asterisk server. * * @param socket the socket to use for reading from the asterisk server. */ public void setSocket(final SocketConnectionFacade socket) { this.socket = socket; } public void registerEventClass(Class eventClass) { eventBuilder.registerEventClass(eventClass); } /** * Reads line by line from the asterisk server, sets the protocol identifier as soon as it is * received and dispatches the received events and responses via the associated dispatcher. * * @see DefaultManagerConnection#dispatchEvent(ManagerEvent) * @see DefaultManagerConnection#dispatchResponse(ManagerResponse) * @see DefaultManagerConnection#setProtocolIdentifier(String) */ public void run() { final Map buffer = new HashMap(); final List commandResult = new ArrayList(); String line; boolean processingCommandResult = false; if (socket == null) { throw new IllegalStateException("Unable to run: socket is null."); } this.die = false; try { while ((line = socket.readLine()) != null && !this.die) { // dirty hack for handling the CommandAction. Needs fix when manager protocol is // enhanced. if (processingCommandResult) { if ("--END COMMAND--".equals(line)) { CommandResponse commandResponse = new CommandResponse(); if (!commandResult.isEmpty() && ((String) commandResult.get(0)).startsWith("ActionID")) { String tmp = (String) commandResult.get(0); int delimiterIndex = tmp.indexOf(":"); if (delimiterIndex > 0 && tmp.length() > delimiterIndex + 2) { commandResult.remove(0); commandResponse.setActionId(tmp.substring(delimiterIndex + 2)); } } commandResponse.setResponse("Follows"); commandResponse.setDateReceived(DateUtil.getDate()); commandResponse.setResult(commandResult); dispatcher.dispatchResponse(commandResponse); processingCommandResult = false; } else { commandResult.add(line); } continue; } // Reponse: Follows indicates that the output starting on the next line until // --END COMMAND-- must be treated as raw output of a command executed by a // CommandAction. if ("Response: Follows".equalsIgnoreCase(line)) { processingCommandResult = true; commandResult.clear(); continue; } // maybe we will find a better way to identify the protocol identifier but for now // this works quite well. if (line.startsWith("Asterisk Call Manager/")) { ConnectEvent connectEvent = new ConnectEvent(asteriskServer); connectEvent.setProtocolIdentifier(line); connectEvent.setDateReceived(DateUtil.getDate()); dispatcher.dispatchEvent(connectEvent); continue; } // an empty line indicates a normal response's or event's end so we build // the corresponding value object and dispatch it through the ManagerConnection. if (line.length() == 0) { if (buffer.containsKey("response")) { ManagerResponse response = buildResponse(buffer); if (response != null) { dispatcher.dispatchResponse(response); } } else if (buffer.containsKey("event")) { ManagerEvent event = buildEvent(asteriskServer, buffer); if (event != null) { dispatcher.dispatchEvent(event); } } buffer.clear(); } else { int delimiterIndex; delimiterIndex = line.indexOf(":"); if (delimiterIndex > 0 && line.length() > delimiterIndex + 2) { String name; String value; name = line.substring(0, delimiterIndex).toLowerCase(); value = line.substring(delimiterIndex + 2); buffer.put(name, value); } } } logger.info("Reached end of stream, terminating reader."); } catch (IOException e) { logger.info("IOException while reading from asterisk server, terminating reader thread: " + e.getMessage()); } finally { // cleans resources and reconnects if needed DisconnectEvent disconnectEvent = new DisconnectEvent(asteriskServer); disconnectEvent.setDateReceived(DateUtil.getDate()); dispatcher.dispatchEvent(disconnectEvent); } } public void die() { this.die = true; } private ManagerResponse buildResponse(Map buffer) { ManagerResponse response; response = responseBuilder.buildResponse(buffer); if (response != null) { response.setDateReceived(DateUtil.getDate()); } return response; } private ManagerEvent buildEvent(Object source, Map buffer) { ManagerEvent event; event = eventBuilder.buildEvent(source, buffer); if (event != null) { event.setDateReceived(DateUtil.getDate()); } return event; } } --- NEW FILE: ManagerWriterImpl.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 net.sf.asterisk.io.SocketConnectionFacade; import net.sf.asterisk.manager.ActionBuilder; import net.sf.asterisk.manager.ManagerWriter; import net.sf.asterisk.manager.action.ManagerAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Default implementation of ManagerWriter interface. * * @author srt * @version $Id: ManagerWriterImpl.java,v 1.1 2005/03/11 15:27:23 srt Exp $ */ public class ManagerWriterImpl implements ManagerWriter { /** * Instance logger. */ private final Log logger = LogFactory.getLog(getClass()); /** * The action builder utility to convert ManagerAction to a String suitable to be sent to the * asterisk server. */ private final ActionBuilder actionBuilder; private SocketConnectionFacade socket; /** * Creates a new ManagerWriterImpl. */ public ManagerWriterImpl() { this.actionBuilder = new ActionBuilderImpl(); } public synchronized void setSocket(final SocketConnectionFacade socket) { this.socket = socket; } public synchronized void sendAction(final ManagerAction action) throws IOException { final String actionString; if (socket == null) { throw new IllegalStateException("Unable to send action: socket is null"); } actionString = actionBuilder.buildAction(action); socket.write(actionString); socket.flush(); logger.debug("Sent " + action.getAction() + " action with actionId '" + action.getActionId() + "':\n" + actionString); } } --- NEW FILE: ActionBuilderImpl.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.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import net.sf.asterisk.manager.ActionBuilder; import net.sf.asterisk.manager.action.ManagerAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Default implementation of the ActionBuilder interface. * * @author srt * @version $Id: ActionBuilderImpl.java,v 1.1 2005/03/11 15:27:23 srt Exp $ */ public class ActionBuilderImpl implements ActionBuilder { /** * Instance logger. */ private final Log logger = LogFactory.getLog(getClass()); public final String buildAction(final ManagerAction action) { StringBuffer sb; Map getters; sb = new StringBuffer(); getters = getGetters(action.getClass()); Iterator i = getters.keySet().iterator(); while (i.hasNext()) { String name; Method getter; Object value; String stringValue; name = (String) i.next(); if ("class".equals(name)) { continue; } getter = (Method) getters.get(name); try { value = getter.invoke(action, new Object[]{}); } catch (IllegalAccessException ex) { logger.error("Unable to retrieve property '" + name + "' of " + action.getClass(), ex); continue; } catch (InvocationTargetException ex) { logger.error("Unable to retrieve property '" + name + "' of " + action.getClass(), ex); continue; } if (value == null) { continue; } if (value instanceof String) { stringValue = (String) value; } else { stringValue = value.toString(); } sb.append(name); sb.append(": "); sb.append(stringValue); sb.append("\r\n"); } sb.append("\r\n"); return sb.toString(); } /** * Returns a Map of getter methods of the given class.<br> * The key of the map contains the name of the attribute that can be accessed by the getter, the * value the getter itself (an instance of java.lang.reflect.Method). A method is considered a * getter if its name starts with "get", it is declared public and takes no arguments. * * @param clazz the class to return the getters for * @return a Map of attributes and their accessor methods (getters) */ private Map getGetters(final Class clazz) { Map accessors = new HashMap(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { String name; String methodName; Method method = methods[i]; methodName = method.getName(); if (!methodName.startsWith("get")) { continue; } // skip methods with != 0 parameters if (method.getParameterTypes().length != 0) { continue; } // ok seems to be an accessor name = methodName.substring("get".length()).toLowerCase(); if (name.length() == 0) { continue; } accessors.put(name, method); } return accessors; } } |
From: Stefan R. <sr...@us...> - 2005-03-11 15:27:34
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22772/src/java/net/sf/asterisk/manager Modified Files: ManagerReader.java ManagerWriter.java DefaultManagerConnection.java Removed Files: ResponseBuilderImpl.java ActionBuilderImpl.java ManagerWriterImpl.java EventBuilderImpl.java ManagerReaderImpl.java Log Message: Refactored private implementation classes into impl subpackage Index: ManagerReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerReader.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -p -r1.9 -r1.10 --- ManagerReader.java 9 Mar 2005 09:59:03 -0000 1.9 +++ ManagerReader.java 11 Mar 2005 15:27:22 -0000 1.10 @@ -32,7 +32,7 @@ import net.sf.asterisk.manager.event.Man * @version $Id$ */ -interface ManagerReader extends Runnable +public interface ManagerReader extends Runnable { /** Index: ManagerWriter.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerWriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- ManagerWriter.java 9 Mar 2005 09:59:03 -0000 1.3 +++ ManagerWriter.java 11 Mar 2005 15:27:22 -0000 1.4 @@ -32,7 +32,7 @@ import net.sf.asterisk.manager.action.Ma * @author srt * @version $Id$ */ -interface ManagerWriter +public interface ManagerWriter { void setSocket(final SocketConnectionFacade socket); Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -p -r1.10 -r1.11 --- DefaultManagerConnection.java 9 Mar 2005 09:59:03 -0000 1.10 +++ DefaultManagerConnection.java 11 Mar 2005 15:27:22 -0000 1.11 @@ -35,6 +35,8 @@ import net.sf.asterisk.manager.action.Ma import net.sf.asterisk.manager.event.ConnectEvent; import net.sf.asterisk.manager.event.DisconnectEvent; import net.sf.asterisk.manager.event.ManagerEvent; +import net.sf.asterisk.manager.impl.ManagerReaderImpl; +import net.sf.asterisk.manager.impl.ManagerWriterImpl; import net.sf.asterisk.manager.response.ChallengeResponse; import net.sf.asterisk.manager.response.ManagerError; import net.sf.asterisk.manager.response.ManagerResponse; --- ResponseBuilderImpl.java DELETED --- --- ActionBuilderImpl.java DELETED --- --- ManagerWriterImpl.java DELETED --- --- EventBuilderImpl.java DELETED --- --- ManagerReaderImpl.java DELETED --- |
From: Stefan R. <sr...@us...> - 2005-03-11 15:26:48
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22623/src/test/net/sf/asterisk/manager/impl Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/impl added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-11 15:26:35
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22623/src/java/net/sf/asterisk/manager/impl Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/impl added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-11 15:21:05
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21021/src/java/net/sf/asterisk/fastagi/impl Added Files: AGIWriterImpl.java RequestBuilderImpl.java AGIReaderImpl.java AGIChannelImpl.java ReplyBuilderImpl.java AGIRequestImpl.java Log Message: Refactored private implementation classes into impl subpackage --- NEW FILE: AGIWriterImpl.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.impl; import java.io.IOException; import net.sf.asterisk.fastagi.AGIException; import net.sf.asterisk.fastagi.AGINetworkException; import net.sf.asterisk.fastagi.AGIWriter; import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.io.SocketConnectionFacade; /** * Default implementation of the AGIWriter interface. * * @author srt * @version $Id: AGIWriterImpl.java,v 1.1 2005/03/11 15:20:50 srt Exp $ */ public class AGIWriterImpl implements AGIWriter { private SocketConnectionFacade socket; public AGIWriterImpl(SocketConnectionFacade socket) { this.socket = socket; } public void sendCommand(AGICommand command) throws AGIException { try { socket.write(command.buildCommand() + "\n"); socket.flush(); } catch (IOException e) { throw new AGINetworkException( "Unable to send command to Asterisk: " + e.getMessage(), e); } } } --- NEW FILE: RequestBuilderImpl.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.impl; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import net.sf.asterisk.fastagi.AGIRequest; import net.sf.asterisk.fastagi.RequestBuilder; /** * Default implementation of the AGIRequestBuilder interface. * * @author srt * @version $Id: RequestBuilderImpl.java,v 1.1 2005/03/11 15:20:50 srt Exp $ */ public class RequestBuilderImpl implements RequestBuilder { /** * Creates a new AGIRequestBuilderImpl. */ public RequestBuilderImpl() { } public AGIRequest buildRequest(final Collection lines) { AGIRequestImpl request; Map map; if (lines == null) { throw new IllegalArgumentException("Environment must not be null."); } request = new AGIRequestImpl(); map = buildMap(lines); request.setScript((String) map.get("network_script")); request.setRequestURL((String) map.get("request")); request.setChannel((String) map.get("channel")); request.setUniqueId((String) map.get("uniqueid")); request.setType((String) map.get("type")); request.setLanguage((String) map.get("language")); if (map.get("callerid") != null) { String rawCallerId = (String) map.get("callerid"); request.setCallerId(getCallerId(rawCallerId)); request.setCallerIdName(getCallerIdName(rawCallerId)); } request.setDnid((String) map.get("dnid")); request.setRdnis((String) map.get("rdnis")); request.setContext((String) map.get("context")); request.setExtension((String) map.get("extension")); if (map.get("priority") != null) { request.setPriority(new Integer((String) map.get("priority"))); } if (map.get("enhanced") != null) { if ("1.0".equals((String) map.get("enhanced"))) { request.setEnhanced(Boolean.TRUE); } else { request.setEnhanced(Boolean.FALSE); } } request.setAccountCode((String) map.get("accountcode")); return request; } /** * Builds a map containing variable names as key (with the "agi_" prefix * stripped) and the corresponding values.<br> * Syntactically invalid and empty variables are skipped. * * @param lines the environment to transform. * @return a map with the variables set corresponding to the given * environment. */ private Map buildMap(final Collection lines) { Map map; Iterator lineIterator; map = new HashMap(); lineIterator = lines.iterator(); while (lineIterator.hasNext()) { String line; int colonPosition; String key; String value; line = (String) lineIterator.next(); colonPosition = line.indexOf(':'); // no colon on the line? if (colonPosition < 0) { continue; } // key doesn't start with agi_? if (!line.startsWith("agi_")) { continue; } // first colon in line is last character -> no value present? if (line.length() < colonPosition + 2) { continue; } key = line.substring(4, colonPosition).toLowerCase(); value = line.substring(colonPosition + 2); if (value.length() != 0) { map.put(key, value); } } return map; } private String getCallerId(final String rawCallerId) { int lbPosition; int rbPosition; lbPosition = rawCallerId.indexOf('<'); rbPosition = rawCallerId.indexOf('>'); if (lbPosition < 0 || rbPosition < 0) { return rawCallerId; } return rawCallerId.substring(lbPosition + 1, rbPosition); } private String getCallerIdName(final String rawCallerId) { int lbPosition; String callerIdName; lbPosition = rawCallerId.indexOf('<'); if (lbPosition < 0) { return null; } callerIdName = rawCallerId.substring(0, lbPosition).trim(); if (callerIdName.startsWith("\"") && callerIdName.endsWith("\"")) { callerIdName = callerIdName.substring(1, callerIdName.length() - 1); } if (callerIdName.length() == 0) { return null; } else { return callerIdName; } } } --- NEW FILE: AGIReaderImpl.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.impl; import java.io.IOException; import java.util.ArrayList; import java.util.List; import net.sf.asterisk.fastagi.AGIException; import net.sf.asterisk.fastagi.AGIHangupException; import net.sf.asterisk.fastagi.AGINetworkException; import net.sf.asterisk.fastagi.AGIReader; import net.sf.asterisk.fastagi.AGIRequest; import net.sf.asterisk.fastagi.ReplyBuilder; import net.sf.asterisk.fastagi.RequestBuilder; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; /** * Default implementation of the AGIReader implementation. * * @author srt * @version $Id: AGIReaderImpl.java,v 1.1 2005/03/11 15:20:50 srt Exp $ */ public class AGIReaderImpl implements AGIReader { private SocketConnectionFacade socket; private ReplyBuilder replyBuilder; private RequestBuilder requestBuilder; public AGIReaderImpl(SocketConnectionFacade socket) { this.socket = socket; this.replyBuilder = new ReplyBuilderImpl(); this.requestBuilder = new RequestBuilderImpl(); } public AGIRequest readRequest() throws AGIException { AGIRequest request; String line; List lines; lines = new ArrayList(); try { while ((line = socket.readLine()) != null) { if (line.length() == 0) { break; } lines.add(line); } } catch (IOException e) { throw new AGINetworkException( "Unable to read request from Asterisk: " + e.getMessage(), e); } request = requestBuilder.buildRequest(lines); return request; } public AGIReply readReply() throws AGIException { AGIReply reply; List lines; String line; lines = new ArrayList(); try { line = socket.readLine(); } catch (IOException e) { throw new AGINetworkException( "Unable to read reply from Asterisk: " + e.getMessage(), e); } if (line == null) { throw new AGIHangupException(); } lines.add(line); // read synopsis and usage if statuscode is 520 if (line.startsWith(Integer .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) { try { while ((line = socket.readLine()) != null) { lines.add(line); if (line.startsWith(Integer .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) { break; } } } catch (IOException e) { throw new AGINetworkException( "Unable to read reply from Asterisk: " + e.getMessage(), e); } } reply = replyBuilder.buildReply(lines); return reply; } } --- NEW FILE: AGIChannelImpl.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.impl; import net.sf.asterisk.fastagi.AGIChannel; import net.sf.asterisk.fastagi.AGIException; import net.sf.asterisk.fastagi.AGIReader; import net.sf.asterisk.fastagi.AGIWriter; import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; /** * Default implementation of the AGIChannel interface. * * @author srt * @version $Id: AGIChannelImpl.java,v 1.1 2005/03/11 15:20:50 srt Exp $ */ public class AGIChannelImpl implements AGIChannel { 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 { AGIReply reply; agiWriter.sendCommand(command); reply = agiReader.readReply(); return reply; } } --- NEW FILE: ReplyBuilderImpl.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.impl; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.sf.asterisk.fastagi.ReplyBuilder; import net.sf.asterisk.fastagi.reply.AGIReply; /** * Default implementation of the ReplyBuilder interface. * * @author srt * @version $Id: ReplyBuilderImpl.java,v 1.1 2005/03/11 15:20:50 srt Exp $ */ public class ReplyBuilderImpl implements ReplyBuilder { private static final Pattern STATUS_PATTERN = Pattern .compile("^(\\d{3})[ -]"); private static final Pattern RESULT_PATTERN = Pattern .compile("^200 result=(\\S+)"); private static final Pattern PARENTHESIS_PATTERN = Pattern .compile("^200 result=\\S+ \\((.*)\\)"); private static final Pattern ADDITIONAL_ATTRIBUTES_PATTERN = Pattern .compile("^200 result=\\S+( \\(.*\\) )?(.+)$"); private static final Pattern ADDITIONAL_ATTRIBUTE_PATTERN = Pattern .compile("(\\S+)=(\\S+)"); private static final Pattern SYNOPSIS_PATTERN = Pattern .compile("^\\s*Usage:\\s*(.*)\\s*$"); private static final String END_OF_PROPER_USAGE = "520 End of proper usage."; public AGIReply buildReply(List lines) { String firstLine; AGIReply reply; Matcher matcher; if (lines.size() == 0) { return null; } reply = new AGIReply(); firstLine = (String) lines.get(0); matcher = STATUS_PATTERN.matcher(firstLine); if (matcher.find()) { reply.setStatus(Integer.parseInt(matcher.group(1))); } if (reply.getStatus() == AGIReply.SC_SUCCESS) { matcher = RESULT_PATTERN.matcher(firstLine); if (matcher.find()) { reply.setResult(matcher.group(1)); } matcher = PARENTHESIS_PATTERN.matcher(firstLine); if (matcher.find()) { reply.setExtra(matcher.group(1)); } matcher = ADDITIONAL_ATTRIBUTES_PATTERN.matcher(firstLine); if (matcher.find()) { String s; Matcher attributeMatcher; s = matcher.group(2); attributeMatcher = ADDITIONAL_ATTRIBUTE_PATTERN.matcher(s); while (attributeMatcher.find()) { String key; String value; key = attributeMatcher.group(1); value = attributeMatcher.group(2); reply.setAttribute(key, value); } } } else if (reply.getStatus() == AGIReply.SC_INVALID_COMMAND_SYNTAX) { StringBuffer usageSB; if (lines.size() > 1) { String secondLine; Matcher synopsisMatcher; secondLine = (String) lines.get(1); synopsisMatcher = SYNOPSIS_PATTERN.matcher(secondLine); if (synopsisMatcher.find()) { reply.setSynopsis(synopsisMatcher.group(1)); } } usageSB = new StringBuffer(); for (int i = 2; i < lines.size(); i++) { String line; line = (String) lines.get(i); if (END_OF_PROPER_USAGE.equals(line)) { break; } usageSB.append(line.trim()); usageSB.append(" "); } reply.setUsage(usageSB.toString().trim()); } return reply; } } --- NEW FILE: AGIRequestImpl.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.impl; import java.io.Serializable; import net.sf.asterisk.fastagi.AGIRequest; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; /** * Default implementation of the AGIRequest interface. * * @author srt * @version $Id: AGIRequestImpl.java,v 1.1 2005/03/11 15:20:50 srt Exp $ */ public class AGIRequestImpl implements Serializable, AGIRequest { /** * Serial version identifier. */ private static final long serialVersionUID = 3257001047145789496L; /** * The name of the script to execute. */ private String script; /** * The full URL of the request in the form agi://host[:port][/script] */ private String requestURL; /** * The name of the channel. */ private String channel; /** * The unique id of the channel. */ private String uniqueId; /** * The type of the channel, for example "SIP". */ private String type; /** * The language, for example "en". */ private String language; /** * The Caller*ID, for example "1234". */ private String callerId; /** * The Caller*ID Name, for example "John Doe". */ private String callerIdName; private String dnid; private String rdnis; /** * The context in the dial plan from which the AGI script was called. */ private String context; /** * The extension in the dial plan from which the AGI script was called. */ private String extension; /** * The priority in the dial plan from which the AGI script was called. */ private Integer priority; /** * Boolean.TRUE if this agi is passed audio (EAGI - Enhanced AGI).<br> * Enhanced AGI is currently not supported on FastAGI. */ private Boolean enhanced; /** * The account code set for the call. */ private String accountCode; /** * Creates a new AGIRequestImpl. */ public AGIRequestImpl() { } /** * Returns the name of the script to execute. * * @return the name of the script to execute. */ public String getScript() { return script; } /** * Sets the name of the script to execute. * * @param script the name of the script to execute. */ public void setScript(String script) { this.script = script; } /** * Returns the full URL of the request in the form * agi://host[:port][/script]. * * @return the full URL of the request in the form * agi://host[:port][/script]. */ public String getRequestURL() { return requestURL; } /** * Sets the full URL of the request in the form agi://host[:port][/script]. * * @param requestURL the full URL of the request in the form * agi://host[:port][/script]. */ public void setRequestURL(String requestURL) { this.requestURL = requestURL; } /** * Returns the name of the channel. * * @return the name of the channel. */ public String getChannel() { return channel; } /** * Sets the name of the channel. * * @param channel the name of the channel. */ public void setChannel(String channel) { this.channel = channel; } /** * Returns the unqiue id of the channel. * * @return the unqiue id of the channel. */ public String getUniqueId() { return uniqueId; } /** * Sets the unqiue id of the channel. * * @param uniqueId the unqiue id of the channel. */ public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; } /** * Returns the type of the channel, for example "SIP". * * @return the type of the channel, for example "SIP". */ public String getType() { return type; } /** * Sets the type of the channel, for example "SIP". * * @param type the type of the channel, for example "SIP". */ public void setType(String type) { this.type = type; } /** * Returns the language, for example "en". * * @return the language, for example "en". */ public String getLanguage() { return language; } /** * Sets the language, for example "en". * * @param language the language, for example "en". */ public void setLanguage(String language) { this.language = language; } /** * Returns the Caller*ID, for example "1234". * * @return the Caller*ID, for example "1234". */ public String getCallerId() { return callerId; } /** * Sets the Caller*ID, for example "1234". * * @param callerId the Caller*ID, for example "1234". */ public void setCallerId(String callerId) { this.callerId = callerId; } /** * Returns the the Caller*ID Name, for example "John Doe". * * @return the the Caller*ID Name, for example "John Doe". */ public String getCallerIdName() { return callerIdName; } /** * Sets the the Caller*ID Name, for example "John Doe". * * @param callerIdName the the Caller*ID Name, for example "John Doe". */ public void setCallerIdName(String callerIdName) { this.callerIdName = callerIdName; } public String getDnid() { return dnid; } public void setDnid(String dnid) { this.dnid = dnid; } public String getRdnis() { return rdnis; } public void setRdnis(String rdnis) { this.rdnis = rdnis; } /** * Returns the context in the dial plan from which the AGI script was * called. * * @return the context in the dial plan from which the AGI script was * called. */ public String getContext() { return context; } /** * Sets the context in the dial plan from which the AGI script was called. * * @param context the context in the dial plan from which the AGI script was * called. */ public void setContext(String context) { this.context = context; } /** * Returns the extension in the dial plan from which the AGI script was * called. * * @return the extension in the dial plan from which the AGI script was * called. */ public String getExtension() { return extension; } /** * Sets the extension in the dial plan from which the AGI script was called. * * @param extension the extension in the dial plan from which the AGI script * was called. */ public void setExtension(String extension) { this.extension = extension; } /** * Returns the priority in the dial plan from which the AGI script was * called. * * @return the priority in the dial plan from which the AGI script was * called. */ public Integer getPriority() { return priority; } /** * Sets the priority in the dial plan from which the AGI script was called. * * @param priority the priority in the dial plan from which the AGI script * was called. */ public void setPriority(Integer priority) { this.priority = priority; } /** * Returns wheather this agi is passed audio (EAGI - Enhanced AGI).<br> * Enhanced AGI is currently not supported on FastAGI. * * @return Boolean.TRUE if this agi is passed audio, Boolean.FALSE * otherwise. */ public Boolean getEnhanced() { return enhanced; } /** * Sets wheather this agi is passed audio. * * @param enhanced Boolean.TRUE if this agi is passed audio, Boolean.FALSE * otherwise. */ public void setEnhanced(Boolean enhanced) { this.enhanced = enhanced; } /** * Returns the account code set for the call. * * @return the account code set for the call. */ public String getAccountCode() { return accountCode; } /** * Sets the account code set for the call. * * @param accountCode the account code set for the call. */ public void setAccountCode(String accountCode) { this.accountCode = accountCode; } public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); } public boolean equals(Object o) { return EqualsBuilder.reflectionEquals(this, o); } public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); } } |
From: Stefan R. <sr...@us...> - 2005-03-11 15:21:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21021/src/test/net/sf/asterisk/fastagi Modified Files: ResourceBundleMappingStrategyTest.java Removed Files: ReplyBuilderImplTest.java AGIReaderImplTest.java AGIWriterImplTest.java RequestBuilderImplTest.java AGIChannelImplTest.java Log Message: Refactored private implementation classes into impl subpackage Index: ResourceBundleMappingStrategyTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/ResourceBundleMappingStrategyTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ResourceBundleMappingStrategyTest.java 10 Mar 2005 23:16:11 -0000 1.2 +++ ResourceBundleMappingStrategyTest.java 11 Mar 2005 15:20:51 -0000 1.3 @@ -17,6 +17,7 @@ package net.sf.asterisk.fastagi; import junit.framework.TestCase; +import net.sf.asterisk.fastagi.impl.AGIRequestImpl; public class ResourceBundleMappingStrategyTest extends TestCase { --- ReplyBuilderImplTest.java DELETED --- --- AGIReaderImplTest.java DELETED --- --- AGIWriterImplTest.java DELETED --- --- RequestBuilderImplTest.java DELETED --- --- AGIChannelImplTest.java DELETED --- |
From: Stefan R. <sr...@us...> - 2005-03-11 15:21:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21021/src/java/net/sf/asterisk/fastagi Modified Files: AGIConnectionHandler.java Removed Files: AGIChannelImpl.java ReplyBuilderImpl.java RequestBuilderImpl.java AGIWriterImpl.java AGIRequestImpl.java AGIReaderImpl.java Log Message: Refactored private implementation classes into impl subpackage Index: AGIConnectionHandler.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIConnectionHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- AGIConnectionHandler.java 11 Mar 2005 09:37:39 -0000 1.6 +++ AGIConnectionHandler.java 11 Mar 2005 15:20:49 -0000 1.7 @@ -18,6 +18,9 @@ package net.sf.asterisk.fastagi; import java.io.IOException; +import net.sf.asterisk.fastagi.impl.AGIChannelImpl; +import net.sf.asterisk.fastagi.impl.AGIReaderImpl; +import net.sf.asterisk.fastagi.impl.AGIWriterImpl; import net.sf.asterisk.io.SocketConnectionFacade; import org.apache.commons.logging.Log; --- AGIChannelImpl.java DELETED --- --- ReplyBuilderImpl.java DELETED --- --- RequestBuilderImpl.java DELETED --- --- AGIWriterImpl.java DELETED --- --- AGIRequestImpl.java DELETED --- --- AGIReaderImpl.java DELETED --- |
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21021/src/test/net/sf/asterisk/fastagi/impl Added Files: AGIReaderImplTest.java AGIChannelImplTest.java RequestBuilderImplTest.java AGIWriterImplTest.java ReplyBuilderImplTest.java Log Message: Refactored private implementation classes into impl subpackage --- NEW FILE: AGIReaderImplTest.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.impl; import junit.framework.TestCase; import net.sf.asterisk.fastagi.AGIHangupException; import net.sf.asterisk.fastagi.AGIReader; import net.sf.asterisk.fastagi.AGIRequest; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; import org.easymock.MockControl; public class AGIReaderImplTest extends TestCase { private AGIReader agiReader; private MockControl socketMC; private SocketConnectionFacade socket; protected void setUp() throws Exception { super.setUp(); this.socketMC = MockControl.createControl(SocketConnectionFacade.class); this.socket = (SocketConnectionFacade) socketMC.getMock(); this.agiReader = new AGIReaderImpl(socket); } public void testReadRequest() throws Exception { AGIRequest request; socket.readLine(); socketMC.setReturnValue("agi_network: yes"); socket.readLine(); socketMC.setReturnValue("agi_network_script: myscript.agi"); socket.readLine(); socketMC.setReturnValue("agi_request: agi://host/myscript.agi"); socket.readLine(); socketMC.setReturnValue("agi_channel: SIP/1234-d715"); socket.readLine(); socketMC.setReturnValue(""); socketMC.replay(); request = agiReader.readRequest(); assertEquals("incorrect script", "myscript.agi", request.getScript()); assertEquals("incorrect requestURL", "agi://host/myscript.agi", request .getRequestURL()); assertEquals("incorrect channel", "SIP/1234-d715", request.getChannel()); socketMC.verify(); } public void testReadReply() throws Exception { AGIReply reply; socket.readLine(); socketMC.setReturnValue("200 result=49 endpos=2240"); socketMC.replay(); reply = agiReader.readReply(); assertEquals("Incorrect status", AGIReply.SC_SUCCESS, reply.getStatus()); assertEquals("Incorrect result", 49, reply.getResultCode()); socketMC.verify(); } public void testReadReplyInvalidOrUnknownCommand() throws Exception { AGIReply reply; socket.readLine(); socketMC.setReturnValue("510 Invalid or unknown command"); socketMC.replay(); reply = agiReader.readReply(); assertEquals("Incorrect status", AGIReply.SC_INVALID_OR_UNKNOWN_COMMAND, reply.getStatus()); socketMC.verify(); } public void testReadReplyInvalidCommandSyntax() throws Exception { AGIReply reply; socket.readLine(); socketMC .setReturnValue("520-Invalid command syntax. Proper usage follows:"); socket.readLine(); socketMC.setReturnValue(" Usage: DATABASE DEL <family> <key>"); socket.readLine(); socketMC .setReturnValue(" Deletes an entry in the Asterisk database for a"); socket.readLine(); socketMC.setReturnValue(" given family and key."); socket.readLine(); socketMC.setReturnValue(" Returns 1 if succesful, 0 otherwise"); socket.readLine(); socketMC.setReturnValue("520 End of proper usage."); socketMC.replay(); reply = agiReader.readReply(); assertEquals("Incorrect status", AGIReply.SC_INVALID_COMMAND_SYNTAX, reply.getStatus()); assertEquals("Incorrect synopsis", "DATABASE DEL <family> <key>", reply .getSynopsis()); socketMC.verify(); } public void testReadReplyWhenHungUp() throws Exception { socket.readLine(); socketMC.setReturnValue(null); socketMC.replay(); try { agiReader.readReply(); fail("Must throw AGIHangupException"); } catch (AGIHangupException e) { } socketMC.verify(); } } --- NEW FILE: AGIChannelImplTest.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.impl; import junit.framework.TestCase; import net.sf.asterisk.fastagi.AGIChannel; import net.sf.asterisk.fastagi.AGIReader; import net.sf.asterisk.fastagi.AGIWriter; import net.sf.asterisk.fastagi.command.NoopCommand; import net.sf.asterisk.fastagi.reply.AGIReply; import org.easymock.MockControl; public class AGIChannelImplTest extends TestCase { private MockControl agiWriterMC; private AGIWriter agiWriter; private MockControl agiReaderMC; private AGIReader agiReader; private AGIChannel agiChannel; protected void setUp() throws Exception { super.setUp(); this.agiWriterMC = MockControl.createControl(AGIWriter.class); this.agiWriter = (AGIWriter) agiWriterMC.getMock(); this.agiReaderMC = MockControl.createControl(AGIReader.class); this.agiReader = (AGIReader) agiReaderMC.getMock(); this.agiChannel = new AGIChannelImpl(agiWriter, agiReader); } public void testSendCommand() throws Exception { AGIReply reply; NoopCommand command; reply = new AGIReply(); reply.setStatus(AGIReply.SC_SUCCESS); reply.setResult("0"); command = new NoopCommand(); agiWriter.sendCommand(command); agiReader.readReply(); agiReaderMC.setReturnValue(reply); agiWriterMC.replay(); agiReaderMC.replay(); assertEquals(reply, agiChannel.sendCommand(command)); agiWriterMC.verify(); agiReaderMC.verify(); } } --- NEW FILE: RequestBuilderImplTest.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.impl; import java.util.ArrayList; import java.util.Collection; import junit.framework.TestCase; import net.sf.asterisk.fastagi.AGIRequest; import net.sf.asterisk.fastagi.RequestBuilder; public class RequestBuilderImplTest extends TestCase { private RequestBuilder requestBuilder; protected void setUp() { this.requestBuilder = new RequestBuilderImpl(); } public void testBuildRequest() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_network: yes"); lines.add("agi_network_script: myscript.agi"); lines.add("agi_request: agi://host/myscript.agi"); lines.add("agi_channel: SIP/1234-d715"); lines.add("agi_language: en"); lines.add("agi_type: SIP"); lines.add("agi_uniqueid: 1110023416.6"); lines.add("agi_callerid: John Doe<1234>"); lines.add("agi_dnid: 8870"); lines.add("agi_rdnis: unknown"); lines.add("agi_context: local"); lines.add("agi_extension: 8870"); lines.add("agi_priority: 1"); lines.add("agi_enhanced: 0.0"); lines.add("agi_accountcode: "); request = requestBuilder.buildRequest(lines); assertEquals("incorrect script", "myscript.agi", request.getScript()); assertEquals("incorrect requestURL", "agi://host/myscript.agi", request.getRequestURL()); assertEquals("incorrect channel", "SIP/1234-d715", request.getChannel()); assertEquals("incorrect uniqueId", "SIP/1234-d715", request.getChannel()); assertEquals("incorrect type", "SIP", request.getType()); assertEquals("incorrect uniqueId", "1110023416.6", request.getUniqueId()); assertEquals("incorrect language", "en", request.getLanguage()); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); assertEquals("incorrect dnid", "8870", request.getDnid()); assertEquals("incorrect rdnis", "unknown", request.getRdnis()); assertEquals("incorrect context", "local", request.getContext()); assertEquals("incorrect extension", "8870", request.getExtension()); assertEquals("incorrect priority", new Integer(1), request.getPriority()); assertEquals("incorrect enhanced", Boolean.FALSE, request.getEnhanced()); assertNull("incorrect accountCode must not be set", request.getAccountCode()); } public void testBuildRequestWithoutCallerIdName() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: 1234"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithoutCallerIdNameButBracket() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: <1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithoutCallerIdNameButBracketAndQuotesAndSpace() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"\" <1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithQuotedCallerIdName() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"John Doe\"<1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); } public void testBuildRequestWithQuotedCallerIdNameAndSpace() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"John Doe\" <1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); } public void testBuildRequestWithoutCallerId() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: "); request = requestBuilder.buildRequest(lines); assertNull("callerId must not be set", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithNullEnvironment() { try { requestBuilder.buildRequest(null); fail("No IllegalArgumentException thrown."); } catch (IllegalArgumentException e) { } } public void testBuildRequestWithUnusualInput() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("var without agi prefix: a value"); lines.add("agi_without_colon another value"); lines.add("agi_without_space_after_colon:"); lines.add("agi_channel: SIP/1234-a892"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect channel", "SIP/1234-a892", request.getChannel()); } } --- NEW FILE: AGIWriterImplTest.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.impl; import junit.framework.TestCase; import net.sf.asterisk.fastagi.AGIWriter; import net.sf.asterisk.fastagi.command.StreamFileCommand; import net.sf.asterisk.io.SocketConnectionFacade; import org.easymock.MockControl; public class AGIWriterImplTest extends TestCase { private AGIWriter agiWriter; private MockControl socketMC; private SocketConnectionFacade socket; protected void setUp() throws Exception { super.setUp(); this.socketMC = MockControl.createControl(SocketConnectionFacade.class); this.socket = (SocketConnectionFacade) socketMC.getMock(); this.agiWriter = new AGIWriterImpl(socket); } public void testSendCommand() throws Exception { StreamFileCommand command; command = new StreamFileCommand("welcome"); socket.write("STREAM FILE \"welcome\" \"\"\n"); socket.flush(); socketMC.replay(); agiWriter.sendCommand(command); socketMC.verify(); } } --- NEW FILE: ReplyBuilderImplTest.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.impl; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import net.sf.asterisk.fastagi.reply.AGIReply; public class ReplyBuilderImplTest extends TestCase { private ReplyBuilderImpl replyBuilder; private List lines; protected void setUp() { this.replyBuilder = new ReplyBuilderImpl(); this.lines = new ArrayList(); } public void testBuildReply() { AGIReply reply; lines.add("200 result=49"); reply = replyBuilder.buildReply(lines); assertEquals("Incorrect status", AGIReply.SC_SUCCESS, reply.getStatus()); assertEquals("Incorrect result", 49, reply.getResultCode()); assertEquals("Incorrect result as character", '1', reply .getResultCodeAsChar()); assertEquals("Incorrect result when get via getAttribute()", "49", reply.getAttribute("result")); } public void testBuildReplyWithAdditionalAttribute() { AGIReply reply; lines.add("200 result=49 endpos=2240"); reply = replyBuilder.buildReply(lines); assertEquals("Incorrect status", AGIReply.SC_SUCCESS, reply.getStatus()); assertEquals("Incorrect result", 49, reply.getResultCode()); assertEquals("Incorrect result as character", '1', reply .getResultCodeAsChar()); assertEquals("Incorrect result when get via getAttribute()", "49", reply.getAttribute("result")); assertEquals("Incorrect endpos attribute", "2240", reply .getAttribute("endpos")); } public void testBuildReplyWithMultipleAdditionalAttribute() { AGIReply reply; lines.add("200 result=49 startpos=1234 endpos=2240"); reply = replyBuilder.buildReply(lines); assertEquals("Incorrect status", AGIReply.SC_SUCCESS, reply.getStatus()); assertEquals("Incorrect result", 49, reply.getResultCode()); assertEquals("Incorrect result as character", '1', reply .getResultCodeAsChar()); assertEquals("Incorrect result when get via getAttribute()", "49", reply.getAttribute("result")); assertEquals("Incorrect startpos attribute", "1234", reply .getAttribute("startpos")); assertEquals("Incorrect endpos attribute", "2240", reply .getAttribute("endpos")); } public void testBuildReplyWithParenthesis() { AGIReply reply; lines.add("200 result=1 ((hello)(world))"); reply = replyBuilder.buildReply(lines); assertEquals("Incorrect status", AGIReply.SC_SUCCESS, reply.getStatus()); assertEquals("Incorrect result", 1, reply.getResultCode()); assertEquals("Incorrect parenthesis", "(hello)(world)", reply .getExtra()); } public void testBuildReplyWithAdditionalAttributeAndParenthesis() { AGIReply reply; lines.add("200 result=1 ((hello)(world)) endpos=2240"); reply = replyBuilder.buildReply(lines); assertEquals("Incorrect status", AGIReply.SC_SUCCESS, reply.getStatus()); assertEquals("Incorrect result", 1, reply.getResultCode()); assertEquals("Incorrect parenthesis", "(hello)(world)", reply .getExtra()); assertEquals("Incorrect endpos attribute", "2240", reply .getAttribute("endpos")); } public void testBuildReplyInvalidOrUnknownCommand() { AGIReply reply; lines.add("510 Invalid or unknown command"); reply = replyBuilder.buildReply(lines); assertEquals("Incorrect status", AGIReply.SC_INVALID_OR_UNKNOWN_COMMAND, reply.getStatus()); } public void testBuildReplyInvalidCommandSyntax() { AGIReply reply; lines.add("520-Invalid command syntax. Proper usage follows:"); lines.add(" Usage: DATABASE DEL <family> <key>"); lines.add(" Deletes an entry in the Asterisk database for a"); lines.add(" given family and key."); lines.add(" Returns 1 if succesful, 0 otherwise"); lines.add("520 End of proper usage."); reply = replyBuilder.buildReply(lines); assertEquals("Incorrect status", AGIReply.SC_INVALID_COMMAND_SYNTAX, reply.getStatus()); assertEquals("Incorrect synopsis", "DATABASE DEL <family> <key>", reply .getSynopsis()); assertEquals( "Incorrect usage", "Deletes an entry in the Asterisk database for a given family and key. Returns 1 if succesful, 0 otherwise", reply.getUsage()); } public void testBuildReplyNoLines() { AGIReply reply; reply = replyBuilder.buildReply(lines); assertNull(reply); } } |
From: Stefan R. <sr...@us...> - 2005-03-11 15:20:14
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20768/src/test/net/sf/asterisk/fastagi/impl Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/impl added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-11 15:20:13
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20768/src/java/net/sf/asterisk/fastagi/impl Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-11 14:15:47
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3854/src/java/net/sf/asterisk/fastagi/command Modified Files: SetPriorityCommand.java Log Message: priority _is_ int... Index: SetPriorityCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SetPriorityCommand.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- SetPriorityCommand.java 11 Mar 2005 13:58:43 -0000 1.3 +++ SetPriorityCommand.java 11 Mar 2005 14:15:34 -0000 1.4 @@ -32,7 +32,7 @@ public class SetPriorityCommand extends /** * The priority for continuation upon exiting the application. */ - private String priority; + private int priority; /** * Creates a new SetPriorityCommand. @@ -40,7 +40,7 @@ public class SetPriorityCommand extends * @param priority the priority for continuation upon exiting the * application. */ - public SetPriorityCommand(String priority) + public SetPriorityCommand(int priority) { this.priority = priority; } @@ -50,7 +50,7 @@ public class SetPriorityCommand extends * * @return the priority for continuation upon exiting the application. */ - public String getPriority() + public int getPriority() { return priority; } @@ -61,7 +61,7 @@ public class SetPriorityCommand extends * @param priority the priority for continuation upon exiting the * application. */ - public void setPriority(String priority) + public void setPriority(int priority) { this.priority = priority; } |
From: Stefan R. <sr...@us...> - 2005-03-11 14:15:47
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3854/src/java/net/sf/asterisk/fastagi Modified Files: AbstractAGIScript.java Log Message: priority _is_ int... Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -p -r1.5 -r1.6 --- AbstractAGIScript.java 11 Mar 2005 13:49:26 -0000 1.5 +++ AbstractAGIScript.java 11 Mar 2005 14:15:35 -0000 1.6 @@ -19,6 +19,9 @@ package net.sf.asterisk.fastagi; import net.sf.asterisk.fastagi.command.AnswerCommand; import net.sf.asterisk.fastagi.command.GetVariableCommand; import net.sf.asterisk.fastagi.command.HangupCommand; +import net.sf.asterisk.fastagi.command.SetContextCommand; +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.reply.AGIReply; @@ -47,6 +50,24 @@ public abstract class AbstractAGIScript channel.sendCommand(new HangupCommand()); } + protected void setContext(AGIChannel channel, String context) + throws AGIException + { + channel.sendCommand(new SetContextCommand(context)); + } + + protected void setExtension(AGIChannel channel, String extension) + throws AGIException + { + channel.sendCommand(new SetExtensionCommand(extension)); + } + + protected void setPriority(AGIChannel channel, int priority) + throws AGIException + { + channel.sendCommand(new SetPriorityCommand(priority)); + } + /** * Returns the value of the given channel variable. * |