asterisk-java-cvs Mailing List for Asterisk-Java Library (Page 94)
Brought to you by:
srt
You can subscribe to this list here.
2005 |
Jan
(4) |
Feb
(75) |
Mar
(211) |
Apr
(70) |
May
(12) |
Jun
(7) |
Jul
(96) |
Aug
(90) |
Sep
(11) |
Oct
(42) |
Nov
(45) |
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(20) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(32) |
Aug
|
Sep
(4) |
Oct
(2) |
Nov
(10) |
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
(3) |
Aug
(73) |
Sep
(13) |
Oct
(4) |
Nov
(1) |
Dec
(7) |
2009 |
Jan
(1) |
Feb
(2) |
Mar
(48) |
Apr
(21) |
May
(14) |
Jun
(11) |
Jul
(9) |
Aug
(2) |
Sep
(11) |
Oct
(14) |
Nov
(6) |
Dec
(4) |
2010 |
Jan
(3) |
Feb
(2) |
Mar
|
Apr
|
May
(3) |
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
(9) |
Nov
|
Dec
(12) |
2011 |
Jan
(1) |
Feb
(5) |
Mar
(7) |
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(10) |
Sep
|
Oct
(5) |
Nov
|
Dec
|
2012 |
Jan
(3) |
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
(2) |
Dec
(2) |
2013 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
(2) |
Nov
|
Dec
(1) |
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(5) |
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
(25) |
May
(10) |
Jun
(4) |
Jul
(7) |
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
(3) |
Dec
(1) |
2016 |
Jan
|
Feb
(42) |
Mar
(6) |
Apr
(15) |
May
(3) |
Jun
(1) |
Jul
(11) |
Aug
|
Sep
|
Oct
(17) |
Nov
(2) |
Dec
|
2017 |
Jan
|
Feb
(4) |
Mar
(1) |
Apr
(3) |
May
(2) |
Jun
(3) |
Jul
(7) |
Aug
(11) |
Sep
(5) |
Oct
(7) |
Nov
(4) |
Dec
(4) |
2018 |
Jan
(11) |
Feb
(11) |
Mar
(3) |
Apr
|
May
(9) |
Jun
(6) |
Jul
(17) |
Aug
(9) |
Sep
(2) |
Oct
(4) |
Nov
(3) |
Dec
(3) |
2019 |
Jan
(13) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(5) |
Jun
|
Jul
(1) |
Aug
(6) |
Sep
|
Oct
|
Nov
(3) |
Dec
|
2020 |
Jan
(2) |
Feb
(72) |
Mar
(8) |
Apr
(11) |
May
(12) |
Jun
(3) |
Jul
(12) |
Aug
(3) |
Sep
(5) |
Oct
(4) |
Nov
|
Dec
(9) |
2021 |
Jan
|
Feb
(31) |
Mar
(6) |
Apr
(3) |
May
|
Jun
(2) |
Jul
|
Aug
(2) |
Sep
|
Oct
(9) |
Nov
|
Dec
(32) |
2022 |
Jan
(5) |
Feb
(7) |
Mar
(2) |
Apr
(3) |
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
(2) |
Oct
(111) |
Nov
(105) |
Dec
(26) |
2023 |
Jan
(25) |
Feb
(6) |
Mar
(10) |
Apr
(54) |
May
(41) |
Jun
(24) |
Jul
(6) |
Aug
(11) |
Sep
(9) |
Oct
(8) |
Nov
(55) |
Dec
(34) |
2024 |
Jan
(6) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(89) |
Sep
(48) |
Oct
(31) |
Nov
(9) |
Dec
(19) |
2025 |
Jan
(12) |
Feb
(18) |
Mar
(9) |
Apr
(7) |
May
|
Jun
(7) |
Jul
(7) |
Aug
(3) |
Sep
(22) |
Oct
(2) |
Nov
|
Dec
|
From: Stefan R. <sr...@us...> - 2005-03-05 23:03:09
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27697/src/test/net/sf/asterisk/fastagi Modified Files: AGIRequestBuilderImplTest.java Log Message: Added verification for uniqueId Fixed test for line without colon Index: AGIRequestBuilderImplTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/AGIRequestBuilderImplTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIRequestBuilderImplTest.java 5 Mar 2005 22:46:59 -0000 1.1 +++ AGIRequestBuilderImplTest.java 5 Mar 2005 23:02:30 -0000 1.2 @@ -60,6 +60,7 @@ public class AGIRequestBuilderImplTest e 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()); @@ -182,7 +183,7 @@ public class AGIRequestBuilderImplTest e lines = new ArrayList(); lines.add("var without agi prefix: a value"); - lines.add("agi_without_colon: another value"); + lines.add("agi_without_colon another value"); lines.add("agi_without_space_after_colon:"); lines.add("agi_channel: SIP/1234-a892"); |
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24114/src/java/net/sf/asterisk/fastagi/command Added Files: DatabaseDelCommand.java SetPriorityCommand.java AGICommand.java DatabaseDelTreeCommand.java SayTimeCommand.java SayNumberCommand.java SetMusicOnCommand.java GetVariableCommand.java SetContextCommand.java DatabasePutCommand.java SetMusicOffCommand.java SetVariableCommand.java SetAutoHangupCommand.java GetDataCommand.java SayPhoneticCommand.java SendImageCommand.java ExecCommand.java SetExtensionCommand.java SendTextCommand.java HangupCommand.java SayDigitsCommand.java ChannelStatusCommand.java StreamFileCommand.java VerboseCommand.java SetCallerIdCommand.java TDDModeCommand.java WaitForDigitCommand.java AnswerCommand.java ReceiveCharCommand.java NoopCommand.java DatabaseGetCommand.java RecordFileCommand.java Log Message: Added initial stuff for fastagi support --- NEW FILE: DatabaseDelCommand.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.command; /** * Deletes a family or specific keytree within a family in the Asterisk database.<br> * Returns 1 if successful, 0 otherwise. * * @author srt * @version $Id: DatabaseDelCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class DatabaseDelCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The family (or family of the keytree) to delete. */ private String family; /** * The keyTree to delete. */ private String keyTree; /** * Creates a new DatabaseDelCommand to delete a family. * * @param family the family to delete. */ public DatabaseDelCommand(String family) { this.family = family; this.keyTree = null; } /** * Creates a new DatabaseDelCommand to delete a keytree. * * @param family the family of the keytree to delete. * @param keyTree the keytree to delete. */ public DatabaseDelCommand(String family, String keyTree) { this.family = family; this.keyTree = keyTree; } /** * Returns the family (or family of the keytree) to delete. * * @return the family (or family of the keytree) to delete. */ public String getFamily() { return family; } /** * Sets the family (or family of the keytree) to delete. * * @param family the family (or family of the keytree) to delete. */ public void setFamily(String family) { this.family = family; } /** * Returns the the keytree to delete. * * @return the keytree to delete. */ public String getKeyTree() { return keyTree; } /** * Sets the keytree to delete. * * @param keyTree the keytree to delete. */ public void setKeyTree(String keyTree) { this.keyTree = keyTree; } public String buildCommand() { return "DATABASE DELTREE " + escapeAndQuote(family) + (keyTree == null ? "" : " " + escapeAndQuote(keyTree)); } } --- NEW FILE: SetPriorityCommand.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.command; /** * Sets the priority for continuation upon exiting the application. * * @author srt * @version $Id: SetPriorityCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SetPriorityCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The priority for continuation upon exiting the application. */ private int priority; /** * Creates a new SetPriorityCommand. * * @param priority the priority for continuation upon exiting the application. */ public SetPriorityCommand(int priority) { this.priority = priority; } /** * Returns the priority for continuation upon exiting the application. * * @return the priority for continuation upon exiting the application. */ public int getPriority() { return priority; } /** * Sets the priority for continuation upon exiting the application. * * @param priority the priority for continuation upon exiting the application. */ public void setPriority(int priority) { this.priority = priority; } public String buildCommand() { return "SET PRIORITY " + priority; } } --- NEW FILE: AGICommand.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.command; import java.io.Serializable; 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; /** * * @author srt * @version $Id: AGICommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public abstract class AGICommand implements Serializable { /** * Serial version identifier. */ private static final long serialVersionUID = 3257849874518456633L; /** * Returns a string suitable to be sent to asterisk.<br> * * @return a string suitable to be sent to asterisk. */ public abstract String buildCommand(); protected String escapeAndQuote(String s) { String tmp; if (s == null) { return "\"\""; } tmp = s; tmp = tmp.replaceAll("\\\"", "\\\\\""); // escape quotes tmp = tmp.replaceAll("\\\n", ""); // filter newline return "\"" + tmp + "\""; // add quotes } 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); } } --- NEW FILE: DatabaseDelTreeCommand.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.command; /** * Deletes an entry in the Asterisk database for a given family and key.<br> * Returns 1 if successful, 0 otherwise. * * @author srt * @version $Id: DatabaseDelTreeCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class DatabaseDelTreeCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The family of the key to delete. */ private String family; /** * The key to delete. */ private String key; /** * Creates a new DatabaseDelCommand. * * @param family the family of the key to delete. * @param key the key to delete. */ public DatabaseDelTreeCommand(String family, String key) { this.family = family; this.key = key; } /** * Returns the family of the key to delete. * * @return the family of the key to delete. */ public String getFamily() { return family; } /** * Sets the family of the key to delete. * * @param family the family of the key to delete. */ public void setFamily(String family) { this.family = family; } /** * Returns the the key to delete. * * @return the key to delete. */ public String getKey() { return key; } /** * Sets the key to delete. * * @param key the key to delete. */ public void setKey(String key) { this.key = key; } public String buildCommand() { return "DATABASE DEL " + escapeAndQuote(family) + " " + escapeAndQuote(key); } } --- NEW FILE: SayTimeCommand.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this time 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.command; /** * Say a given time, returning early if any of the given DTMF digits are received on the channel.<br> * Time is the number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal * Time (UTC).<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. * * @author srt * @version $Id: SayTimeCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SayTimeCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256721797012404276L; /** * The time to say in seconds since 00:00:00 on January 1, 1970. */ private long time; /** * When one of these digits is pressed the command returns. */ private String escapeDigits; /** * Creates a new SayTimeCommand. * * @param time the time to say in seconds since 00:00:00 on January 1, 1970. */ public SayTimeCommand(long time) { this.time = time; this.escapeDigits = null; } /** * Creates a new SayTimeCommand. * * @param time the time to say in seconds since 00:00:00 on January 1, 1970. * @param escapeDigits contains the digits that allow the user to interrupt this command. */ public SayTimeCommand(long time, String interruptDigits) { this.time = time; this.escapeDigits = interruptDigits; } /** * Returns the time to say in seconds since 00:00:00 on January 1, 1970. * * @return the time to say in seconds since 00:00:00 on January 1, 1970. */ public long getTime() { return time; } /** * Sets the time to say in seconds since 00:00:00 on January 1, 1970. * * @param time the time to say in seconds since 00:00:00 on January 1, 1970. */ public void setTime(long time) { this.time = time; } /** * Returns the digits that allow the user to interrupt this command. * * @return the digits that allow the user to interrupt this command. */ public String getEscapeDigits() { return escapeDigits; } /** * Sets the digits that allow the user to interrupt this command. * * @param escapeDigits the time that allow the user to interrupt this command or * <code>null</code> for none. */ public void setEscapeDigits(String escapeDigits) { this.escapeDigits = escapeDigits; } public String buildCommand() { return "SAY TIME " + time + " " + escapeAndQuote(escapeDigits); } } --- NEW FILE: SayNumberCommand.java --- /* * 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 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.command; /** * Say a given number, returning early if any of the given DTMF number 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. * * @author srt * @version $Id: SayNumberCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SayNumberCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3833744404153644087L; /** * The number to say. */ private String number; /** * When one of these number is pressed while streaming the command returns. */ private String interruptDigits; /** * Creates a new SayNumberCommand. * * @param number the number to say. */ public SayNumberCommand(String number) { this.number = number; this.interruptDigits = null; } /** * Creates a new SayNumberCommand. * * @param number the number to say. * @param interruptDigits contains the number that allow the user to interrupt this command. */ public SayNumberCommand(String number, String interruptDigits) { this.number = number; this.interruptDigits = interruptDigits; } /** * Returns the number to say. * * @return the number to say. */ public String getNumber() { return number; } /** * Sets the number to say. * * @param number the number to say. */ public void setNumber(String number) { this.number = number; } /** * Returns the number that allow the user to interrupt this command. * * @return the number that allow the user to interrupt this command. */ public String getInterruptDigits() { return interruptDigits; } /** * Sets the number that allow the user to interrupt this command. * * @param interruptDigits the number that allow the user to interrupt this command or * <code>null</code> for none. */ public void setInterruptDigits(String interruptDigits) { this.interruptDigits = interruptDigits; } public String buildCommand() { return "SAY NUMBER " + escapeAndQuote(number) + " " + escapeAndQuote(interruptDigits); } } --- NEW FILE: SetMusicOnCommand.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.command; /** * Turns on music on hold on the current channel.<br> * Always returns 0. * * @author srt * @version $Id: SetMusicOnCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SetMusicOnCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3762248656229053753L; /** * The music on hold class to play music from. */ private String musicOnHoldClass; /** * Creates a new SetMusicOnCommand playing music from the default music on hold class. */ public SetMusicOnCommand() { this.musicOnHoldClass = null; } /** * Returns the music on hold class to play music from. * * @return the music on hold class to play music from or <code>null</code> for the default * class. */ public String getMusicOnHoldClass() { return musicOnHoldClass; } /** * Sets the music on hold class to play music from. * * @param musicOnHoldClass the music on hold class to play music from or <code>null</code> for * the default class. */ public void setMusicOnHoldClass(String musicOnHoldClass) { this.musicOnHoldClass = musicOnHoldClass; } public String buildCommand() { return "SET MUSIC ON" + (musicOnHoldClass == null ? "" : " " + escapeAndQuote(musicOnHoldClass)); } } --- NEW FILE: GetVariableCommand.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.command; /** * Returns the value of the given channel varible.<br> * Returns 0 if is not set. Returns 1 if the variable is set and returns the variable in * parenthesis.<br> * Example return code: 200 result=1 (testvariable) * * @author srt * @version $Id: GetVariableCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class GetVariableCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The name of the variable to retrieve. */ private String variable; /** * Creates a new GetVariableCommand. * * @param variable the name of the variable to retrieve. */ public GetVariableCommand(String variable) { this.variable = variable; } /** * Returns the name of the variable to retrieve. * * @return the the name of the variable to retrieve. */ public String getVariable() { return variable; } /** * Sets the name of the variable to retrieve. * * @param variable the name of the variable to retrieve. */ public void setVariable(String context) { this.variable = context; } public String buildCommand() { return "GET VARIABLE " + escapeAndQuote(variable); } } --- NEW FILE: SetContextCommand.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.command; /** * Sets the context for continuation upon exiting the application. * * @author srt * @version $Id: SetContextCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SetContextCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The context for continuation upon exiting the application. */ private String context; /** * Creates a new SetPriorityCommand. * * @param context the context for continuation upon exiting the application. */ public SetContextCommand(String context) { this.context = context; } /** * Returns the context for continuation upon exiting the application. * * @return the context for continuation upon exiting the application. */ public String getContext() { return context; } /** * Sets the context for continuation upon exiting the application. * * @param context the context for continuation upon exiting the application. */ public void setContext(String context) { this.context = context; } public String buildCommand() { return "SET CONTEXT " + escapeAndQuote(context); } } --- NEW FILE: DatabasePutCommand.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.command; /** * Adds or updates an entry in the Asterisk database for a given family, key, and value.<br> * Returns 1 if successful, 0 otherwise. * * @author srt * @version $Id: DatabasePutCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class DatabasePutCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The family of the key to set. */ private String family; /** * The key to set. */ private String key; /** * The value to set. */ private String value; /** * Creates a new DatabasePutCommand. * * @param family the family of the key to set. * @param key the key to set. * @param value the value to set. */ public DatabasePutCommand(String family, String key, String value) { this.family = family; this.key = key; this.value = value; } /** * Returns the family of the key to set. * * @return the family of the key to set. */ public String getFamily() { return family; } /** * Sets the family of the key to set. * * @param family the family of the key to set. */ public void setFamily(String family) { this.family = family; } /** * Returns the the key to set. * * @return the key to set. */ public String getKey() { return key; } /** * Sets the key to set. * * @param key the key to set. */ public void setKey(String key) { this.key = key; } /** * Returns the value to set. * * @return the value to set. */ public String getValue() { return value; } /** * Sets the value to set. * * @param value the value to set. */ public void setValue(String value) { this.value = value; } public String buildCommand() { return "DATABASE PUT " + escapeAndQuote(family) + " " + escapeAndQuote(key) + " " + escapeAndQuote(value); } } --- NEW FILE: SetMusicOffCommand.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.command; /** * Turns off music on hold on the current channel.<br> * Always returns 0. * * @author srt * @version $Id: SetMusicOffCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SetMusicOffCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3762248656229053753L; /** * Creates a new SetMusicOffCommand. */ public SetMusicOffCommand() { } public String buildCommand() { return "SET MUSIC OFF"; } } --- NEW FILE: SetVariableCommand.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.command; /** * Sets the given channel varible to the given value. * * @author srt * @version $Id: SetVariableCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SetVariableCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The name of the variable to set. */ private String variable; /** * The value to set. */ private String value; /** * Creates a new GetVariableCommand. * * @param variable the name of the variable to set. * @param value the value to set. */ public SetVariableCommand(String variable, String value) { this.variable = variable; this.value = value; } /** * Returns the name of the variable to set. * * @return the the name of the variable to set. */ public String getVariable() { return variable; } /** * Sets the name of the variable to set. * * @param variable the name of the variable to set. */ public void setVariable(String context) { this.variable = context; } /** * Returns the value to set. * * @return the value to set. */ public String getValue() { return value; } /** * Sets the value to set. * * @param value the value to set. */ public void setValue(String value) { this.value = value; } public String buildCommand() { return "SET VARIABLE " + escapeAndQuote(variable) + " " + escapeAndQuote(value); } } --- NEW FILE: SetAutoHangupCommand.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.command; /** * Cause the channel to automatically hangup at the given number of seconds in the future.<br> * Of course it can be hungup before then as well. Setting to 0 will cause the autohangup feature to * be disabled on this channel. * * @author srt * @version $Id: SetAutoHangupCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SetAutoHangupCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3257562923458443314L; /** * The number of seconds before this channel is automatically hung up. */ private int time; /** * Creates a new SetAutoHangupCommand. * * @param time the number of seconds before this channel is automatically hung up.<br> * 0 disables the autohangup feature. */ public SetAutoHangupCommand(int time) { this.time = time; } /** * Returns the number of seconds before this channel is automatically hung up. * * @return the number of seconds before this channel is automatically hung up. */ public int getTime() { return time; } /** * Sets the number of seconds before this channel is automatically hung up. * * @param time the number of seconds before this channel is automatically hung up.<br> * 0 disables the autohangup feature. */ public void setTime(int timeout) { this.time = timeout; } public String buildCommand() { return "SET AUTOHANGUP " + time; } } --- NEW FILE: GetDataCommand.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.command; /** * Stream the given file, and recieve DTMF data.<br> * Returns the digits recieved from the channel at the other end.<br> * Input ends when the timeout is reached, the maximum number of digits is read or the user presses #. * * @author srt * @version $Id: GetDataCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class GetDataCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3978141041352128820L; /** * The name of the file to stream. */ private String file; /** * The timeout to wait for data.<br> * 0 means standard timeout value, -1 means "ludicrous time" (essentially never times out). */ private int timeout; /** * The maximum number of digits to read.<br> * Must be in [1..1024]. */ private int maxDigits; /** * Creates a new GetDataCommand with default timeout and maxDigits set to 1024. * * @param file the name of the file to stream, must not include extension. */ public GetDataCommand(String file) { this.file = file; this.timeout = 0; this.maxDigits = 1024; } /** * Creates a new GetDataCommand. * * @param file the name of the file to stream, must not include extension. * @param timeout the timeout to wait for data.<br> * 0 means standard timeout value, -1 means "ludicrous time" (essentially never times out). * @param maxDigits the maximum number of digits to read.<br> * Must be in [1..1024]. * * @throws IllegalArgumentException if maxDigits is not in [1..1024] */ public GetDataCommand(String file, int timeout, int maxDigits) throws IllegalArgumentException { if (maxDigits < 1 || maxDigits > 1024) { throw new IllegalArgumentException("maxDigits must be in [1..1024]"); } this.file = file; this.timeout = timeout; this.maxDigits = maxDigits; } /** * Returns the name of the file to stream. * * @return the name of the file to stream. */ public String getFile() { return file; } /** * Sets the name of the file to stream. * * @param file the name of the file to stream, must not include extension. */ public void setFile(String file) { this.file = file; } /** * Returns the timeout to wait for data. * * @return the timeout to wait for data. */ public int getTimeout() { return timeout; } /** * Sets the timeout to wait for data. * * @param timeout the timeout to wait for data.<br> * 0 means standard timeout value, -1 means "ludicrous time" (essentially never times out). */ public void setTimeout(int timeout) { this.timeout = timeout; } /** * Returns the maximum number of digits to read. * * @return the maximum number of digits to read. */ public int getMaxDigits() { return maxDigits; } /** * Sets the maximum number of digits to read. * * @param maxDigits the maximum number of digits to read.<br> * Must be in [1..1024]. * * @throws IllegalArgumentException if maxDigits is not in [1..1024] */ public void setMaxDigits(int maxDigits) throws IllegalArgumentException { if (maxDigits < 1 || maxDigits > 1024) { throw new IllegalArgumentException("maxDigits must be in [1..1024]"); } this.maxDigits = maxDigits; } public String buildCommand() { return "GET DATA " + escapeAndQuote(file) + " " + timeout + " " + maxDigits; } } --- NEW FILE: SayPhoneticCommand.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this text 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.command; /** * Say a given character string with phonetics, 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. * * @author srt * @version $Id: SayPhoneticCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SayPhoneticCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256721797012404276L; /** * The text to say. */ private String text; /** * When one of these digits is pressed the command returns. */ private String escapeDigits; /** * Creates a new SayPhonticCommand. * * @param text the text to say. */ public SayPhoneticCommand(String text) { this.text = text; this.escapeDigits = null; } /** * Creates a new SayPhoneticCommand. * * @param text the text to say. * @param escapeDigits contains the digits that allow the user to interrupt this command. */ public SayPhoneticCommand(String text, String interruptDigits) { this.text = text; this.escapeDigits = interruptDigits; } /** * Returns the text to say. * * @return the text to say. */ public String getText() { return text; } /** * Sets the text to say. * * @param text the text to say. */ public void setText(String text) { this.text = text; } /** * Returns the digits that allow the user to interrupt this command. * * @return the digits that allow the user to interrupt this command. */ public String getEscapeDigits() { return escapeDigits; } /** * Sets the digits that allow the user to interrupt this command. * * @param escapeDigits the text that allow the user to interrupt this command or * <code>null</code> for none. */ public void setEscapeDigits(String escapeDigits) { this.escapeDigits = escapeDigits; } public String buildCommand() { return "SAY PHONETIC " + escapeAndQuote(text) + " " + escapeAndQuote(escapeDigits); } } --- NEW FILE: SendImageCommand.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.command; /** * Sends the given image on a channel.<br> * Most channels do not support the transmission of images.<br> * Returns 0 if image is sent, or if the channel does not support image transmission. Returns -1 * only on error/hangup.<br> * Image names should not include extensions. * * @author srt * @version $Id: SendImageCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SendImageCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3904959746380281145L; /** * The name of the image to send. */ private String image; /** * Creates a new SendImageCommand. * * @param image the image to send, should not include extension. */ public SendImageCommand(String image) { this.image = image; } /** * Returns the image to send. * * @return the image to send. */ public String getImage() { return image; } /** * Sets the image to send. * * @param image the image to send, should not include extension. */ public void setImage(String image) { this.image = image; } public String buildCommand() { return "SEND IMAGE " + escapeAndQuote(image); } } --- NEW FILE: ExecCommand.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.command; /** * Executes an application with the given options.<br> * Returns whatever the application returns, or -2 on failure to find application. * * @author srt * @version $Id: ExecCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class ExecCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3904959746380281145L; /** * The name of the application to execute. */ private String application; /** * The options to pass to the application. */ private String options; /** * Creates a new ExecCommand. * * @param application the name of the application to execute. */ public ExecCommand(String application) { this.application = application; } /** * Creates a new ExecCommand. * * @param application the name of the application to execute. * @param options the options to pass to the application. */ public ExecCommand(String application, String options) { this.application = application; this.options = options; } /** * Returns the name of the application to execute. * * @return the name of the application to execute. */ public String getApplication() { return application; } /** * Sets the name of the application to execute. * * @param application the name of the application to execute. */ public void setApplication(String channel) { this.application = channel; this.options = null; } /** * Returns the options to pass to the application. * * @return the options to pass to the application. */ public String getOptions() { return options; } /** * Sets the options to pass to the application. * * @param options the options to pass to the application. */ public void setOptions(String options) { this.options = options; } public String buildCommand() { return "EXEC " + escapeAndQuote(application) + " " + escapeAndQuote(options); } } --- NEW FILE: SetExtensionCommand.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.command; /** * Sets the extension for continuation upon exiting the application. * * @author srt * @version $Id: SetExtensionCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SetExtensionCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3256719598056387384L; /** * The extension for continuation upon exiting the application. */ private String extension; /** * Creates a new SetPriorityCommand. * * @param extension the extension for continuation upon exiting the application. */ public SetExtensionCommand(String extension) { this.extension = extension; } /** * Returns the extension for continuation upon exiting the application. * * @return the extension for continuation upon exiting the application. */ public String getExtension() { return extension; } /** * Sets the extension for continuation upon exiting the application. * * @param extension the extension for continuation upon exiting the application. */ public void setExtension(String extension) { this.extension = extension; } public String buildCommand() { return "SET EXTENSION " + escapeAndQuote(extension); } } --- NEW FILE: SendTextCommand.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.command; /** * Sends the given text on a channel.<br> * Most channels do not support the transmission of text.<br> * Returns 0 if text is sent, or if the channel does not support text transmission. Returns -1 only * on error/hangup. * * @author srt * @version $Id: SendTextCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SendTextCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3904959746380281145L; /** * The text to send. */ private String text; /** * Creates a new SendTextCommand. * * @param text the text to send. */ public SendTextCommand(String text) { this.text = text; } /** * Returns the text to send. * * @return the text to send. */ public String getText() { return text; } /** * Sets the text to send. * * @param text the text to send. */ public void setText(String text) { this.text = text; } public String buildCommand() { return "SEND TEXT " + escapeAndQuote(text); } } --- NEW FILE: HangupCommand.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.command; /** * Hangs up the specified channel. If no channel name is given, hangs up the current channel. * * @author srt * @version $Id: HangupCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class HangupCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3904959746380281145L; /** * The name of the channel to hangup or <code>null</code> for the current channel. */ private String channel; /** * Creates a new HangupCommand that hangs up the current channel. */ public HangupCommand() { this.channel = null; } /** * Creates a new HangupCommand that hangs up the given channel. * * @param channel the name of the channel to hangup. */ public HangupCommand(String channel) { this.channel = channel; } /** * Returns the name of the channel to hangup. * * @return the name of the channel to hangup or <code>null</code> for the current channel. */ public String getChannel() { return channel; } /** * Sets the name of the channel to hangup. * * @param channel the name of the channel to hangup or <code>null</code> for the current * channel. */ public void setChannel(String channel) { this.channel = channel; } public String buildCommand() { return "HANGUP" + (channel == null ? "" : " " + escapeAndQuote(channel)); } } --- NEW FILE: SayDigitsCommand.java --- /* * 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 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.command; /** * Say a given digit string, returning early if any of the given DTMF number 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. * * @author srt * @version $Id: SayDigitsCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class SayDigitsCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3907207173934101552L; /** * The number to say. */ private String number; /** * When one of these digits is pressed while saying the number the command returns. */ private String escapeDigits; /** * Creates a new SayDigitsCommand. * * @param number the number to say. */ public SayDigitsCommand(String digits) { this.number = digits; this.escapeDigits = null; } /** * Creates a new SayDigitsCommand. * * @param number the number to say. * @param escapeDigits the digits that allow the user to interrupt this command. */ public SayDigitsCommand(String number, String escapeDigits) { this.number = number; this.escapeDigits = escapeDigits; } /** * Returns the number to say. * * @return the number to say. */ public String getNumber() { return number; } /** * Sets the number to say. * * @param number the number to say. */ public void setNumber(String number) { this.number = number; } /** * Returns the digits that allow the user to interrupt this command. * * @return the digits that allow the user to interrupt this command. */ public String getEscapeDigits() { return escapeDigits; } /** * Sets the digits that allow the user to interrupt this command. * * @param escapeDigits the digits that allow the user to interrupt this command or * <code>null</code> for none. */ public void setEscapeDigits(String escapeDigits) { this.escapeDigits = escapeDigits; } public String buildCommand() { return "STREAM DIGITS " + escapeAndQuote(number) + " " + escapeAndQuote(escapeDigits); } } --- NEW FILE: ChannelStatusCommand.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.command; /** * Returns the status of the specified channel. If no channel name is given the returns the status * of the current channel.<br> * Return values: * <ul> * <li>0 Channel is down and available * <li>1 Channel is down, but reserved * <li>2 Channel is off hook * <li>3 Digits (or equivalent) have been dialed * <li>4 Line is ringing * <li>5 Remote end is ringing * <li>6 Line is up * <li>7 Line is busy * </ul> * * @author srt * @version $Id: ChannelStatusCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class ChannelStatusCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3904959746380281145L; /** * The name of the channel to query or <code>null</code> for the current channel. */ private String channel; /** * Creates a new ChannelStatusCommand that queries the current channel. */ public ChannelStatusCommand() { this.channel = null; } /** * Creates a new ChannelStatusCommand that queries the given channel. * * @param channel the name of the channel to query. */ public ChannelStatusCommand(String channel) { this.channel = channel; } /** * Returns the name of the channel to query. * * @return the name of the channel to query or <code>null</code> for the current channel. */ public String getChannel() { return channel; } /** * Sets the name of the channel to query. * * @param channel the name of the channel to query or <code>null</code> for the current * channel. */ public void setChannel(String channel) { this.channel = channel; } public String buildCommand() { return "CHANNEL STATUS" + (channel == null ? "" : " " + escapeAndQuote(channel)); } } --- NEW FILE: StreamFileCommand.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.command; /** * Plays the given file, allowing playback to be interrupted by the given digits, if any.<br> * If offset is provided then the audio will seek to sample offset before play starts.<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 or if the channel was disconnected. <br> * Remember, the file extension must not be included in the filename. * * @author srt * @version $Id: StreamFileCommand.java,v 1.1 2005/03/05 22:46:58 srt Exp $ */ public class StreamFileCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3978141041352128820L; /** * The name of the file to stream. */ private String file; /** * When one of these digits is pressed while streaming the command returns. */ private String escapeDigits; /** * The offset samples to skip before streaming. */ private int offset; /** * Creates a new StreamFileCommand, streaming from the beginning. * * @param file the name of the file to stream, must not include extension. */ public StreamFileCommand(String file) { this.file = file; this.escapeDigits = null; this.offset = -1; } /** * Creates a new StreamFileCommand, streaming from the beginning. * * @param file the name of the file to stream, must not include extension. * @param escapeDigits contains the digits that allow the user to interrupt this command. */ public StreamFileCommand(String file, String escapeDigits) { this.file = file; this.escapeDigits = escapeDigits; this.offset = -1; } /** * Creates a new StreamFileCommand, streaming from the given offset. * * @param file the name of the file to stream, must not include extension. * @param escapeDigits contains the digits that allow the user to interrupt this command. Maybe * <code>null</code> if you don't want the user to interrupt. * @param offset the offset samples to skip before streaming. */ public StreamFileCommand(String file, String escapeDigits, int offset) { this.offset = offset; this.escapeDigits = escapeDigits; this.offset = offset; } /** * Returns the name of the file to stream. * * @return the name of the file to stream. */ public String getFile() { return file; } /** * Sets the name of the file to stream. * * @param file the name of the file to stream, must not include extension. */ public void setFile(String file) { this.file = file; } /** * Returns the digits that allow the user to interrupt this command. * * @return the digits that allow the user to interrupt this command. */ public String getEscapeDigits() { return escapeDigits; } /** * Sets the digits that allow the user to interrupt this command. * * @param escapeDigits the digits that allow the user to interrupt this command or * <code>null</code> for none. */ public void setEscapeDigits(String escapeDigits) { this.escapeDigits = escapeDigits; } /** * Returns the offset samples to skip before streaming. * * @return the offset samples to skip before streaming. */ public int getOffset() { return offset; } /** * Sets the offset samples to skip before streaming. * * @param offset the offset samples to skip before streaming. */ public void setOffset(int offset) { this.offset = offset; } public String buildCommand() { return "STREAM FILE " + escapeAndQuote(file) + " " + escapeAndQuote(escapeDigits) + (offset < 0 ? "" : " " + offset); } } --- NEW FILE: VerboseCommand.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.apach... [truncated message content] |
From: Stefan R. <sr...@us...> - 2005-03-05 22:47:12
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24114/src/java/net/sf/asterisk/fastagi Added Files: AGIRequestBuilderImpl.java AGIRequestBuilder.java AGIRequestImpl.java AGIRequest.java Log Message: Added initial stuff for fastagi support --- NEW FILE: AGIRequestBuilderImpl.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; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * Default implementation of the AGIRequestBuilder interface. * * @author srt * @version $Id: AGIRequestBuilderImpl.java,v 1.1 2005/03/05 22:46:59 srt Exp $ */ public class AGIRequestBuilderImpl implements AGIRequestBuilder { /** * Creates a new AGIRequestBuilderImpl. */ public AGIRequestBuilderImpl() { } public AGIRequest buildAGIRequest(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: AGIRequestBuilder.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; import java.util.Collection; /** * Parses the environment printed by asterisk's <code>setup_env</code> function to an AGIRequest. * * @author srt * @version $Id: AGIRequestBuilder.java,v 1.1 2005/03/05 22:46:59 srt Exp $ */ public interface AGIRequestBuilder { /** * Parses the environment printed by asterisk's <code>setup_env</code> function to an * AGIRequest. * * @param lines the environment printed by asterisk's <code>setup_env</code> function. * @return an AGIRequest setup according to the environment passed in. */ AGIRequest buildAGIRequest(Collection lines); } --- 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; import java.io.Serializable; 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/05 22:46:59 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); } } --- NEW FILE: AGIRequest.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; /** * * @author srt * @version $Id: AGIRequest.java,v 1.1 2005/03/05 22:46:59 srt Exp $ */ public interface AGIRequest { /** * Returns the name of the script to execute. * * @return the name of the script to execute. */ String getScript(); /** * Returns the full URL of the requestURL in the form agi://host[:port][/script]. * * @return the full URL of the requestURL in the form agi://host[:port][/script]. */ String getRequestURL(); /** * Returns the name of the channel. * * @return the name of the channel. */ String getChannel(); /** * Returns the unqiue id of the channel. * * @return the unqiue id of the channel. */ String getUniqueId(); /** * Returns the type of the channel, for example "SIP". * * @return the type of the channel, for example "SIP". */ String getType(); /** * Returns the language, for example "en". * * @return the language, for example "en". */ String getLanguage(); /** * Returns the Caller*ID, for example "1234". * * @return the Caller*ID, for example "1234". */ String getCallerId(); /** * Returns the the Caller*ID Name, for example "John Doe". * * @return the the Caller*ID Name, for example "John Doe". */ String getCallerIdName(); String getDnid(); String getRdnis(); /** * 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. */ String getContext(); /** * 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. */ String getExtension(); /** * 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. */ Integer getPriority(); /** * 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. */ Boolean getEnhanced(); /** * Returns the account code set for the call. * * @return the account code set for the call. */ String getAccountCode(); } |
From: Stefan R. <sr...@us...> - 2005-03-05 22:47:11
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24114/src/test/net/sf/asterisk/fastagi/command Added Files: AGICommandTest.java Log Message: Added initial stuff for fastagi support --- NEW FILE: AGICommandTest.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.command; import junit.framework.TestCase; public class AGICommandTest extends TestCase { private MyCommand myCommand; public void testEscapeAndQuote() { myCommand = new MyCommand("just a string"); assertEquals("MY \"just a string\"", myCommand.buildCommand()); } public void testEscapeAndQuoteWithNullString() { myCommand = new MyCommand(null); assertEquals("MY \"\"", myCommand.buildCommand()); } public void testEscapeAndQuoteWithEmptyString() { myCommand = new MyCommand(""); assertEquals("MY \"\"", myCommand.buildCommand()); } public void testEscapeAndQuoteWithStringContainingQuotes() { myCommand = new MyCommand("\"John Doe\" is calling"); assertEquals("MY \"\\\"John Doe\\\" is calling\"", myCommand.buildCommand()); } public void testEscapeAndQuoteWithStringContainingNewline() { myCommand = new MyCommand("Caller is:\nJohn Doe"); assertEquals("MY \"Caller is:John Doe\"", myCommand.buildCommand()); } public class MyCommand extends AGICommand { private static final long serialVersionUID = 3976731484641833012L; private String s; public MyCommand(String s) { this.s = s; } public String buildCommand() { return "MY " + escapeAndQuote(s); } } } |
From: Stefan R. <sr...@us...> - 2005-03-05 22:47:10
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24114/src/test/net/sf/asterisk/fastagi Added Files: AGIRequestBuilderImplTest.java Log Message: Added initial stuff for fastagi support --- NEW FILE: AGIRequestBuilderImplTest.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; import java.util.ArrayList; import java.util.Collection; import junit.framework.TestCase; public class AGIRequestBuilderImplTest extends TestCase { private AGIRequestBuilder agiRequestBuilder; protected void setUp() { this.agiRequestBuilder = new AGIRequestBuilderImpl(); } public void testBuildAGIRequest() { 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 = agiRequestBuilder.buildAGIRequest(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 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 testBuildAGIRequestWithoutCallerIdName() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: 1234"); request = agiRequestBuilder.buildAGIRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildAGIRequestWithoutCallerIdNameButBracket() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: <1234>"); request = agiRequestBuilder.buildAGIRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildAGIRequestWithoutCallerIdNameButBracketAndQuotesAndSpace() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"\" <1234>"); request = agiRequestBuilder.buildAGIRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildAGIRequestWithQuotedCallerIdName() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"John Doe\"<1234>"); request = agiRequestBuilder.buildAGIRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); } public void testBuildAGIRequestWithQuotedCallerIdNameAndSpace() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"John Doe\" <1234>"); request = agiRequestBuilder.buildAGIRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); } public void testBuildAGIRequestWithoutCallerId() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: "); request = agiRequestBuilder.buildAGIRequest(lines); assertNull("callerId must not be set", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildAGIRequestWithNullEnvironment() { try { agiRequestBuilder.buildAGIRequest(null); fail("No IllegalArgumentException thrown."); } catch (IllegalArgumentException e) { } } public void testBuildAGIRequestWithUnusualInput() { 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 = agiRequestBuilder.buildAGIRequest(lines); assertEquals("incorrect channel", "SIP/1234-a892", request.getChannel()); } } |
From: Stefan R. <sr...@us...> - 2005-03-05 22:46:29
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23987/src/java/net/sf/asterisk/fastagi/command Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-05 22:46:29
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23987/src/java/net/sf/asterisk/fastagi Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-05 22:46:29
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23987/src/test/net/sf/asterisk/fastagi/command Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/command added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-05 22:46:29
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23987/src/test/net/sf/asterisk/fastagi Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-05 13:34:39
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20712/src/java/net/sf/asterisk/manager Modified Files: ManagerReader.java ResponseBuilder.java ActionBuilder.java ManagerWriterImpl.java EventBuilder.java ManagerWriter.java ManagerReaderImpl.java Added Files: ResponseBuilderImpl.java ActionBuilderImpl.java EventBuilderImpl.java Log Message: Refactored (Action|Event|Response)Builder into interfaces --- 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; import java.util.Map; 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/05 13:34: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: 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; 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.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/05 13:34: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; } } --- 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; 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.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/05 13:34: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; } } Index: ManagerReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerReader.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- ManagerReader.java 5 Mar 2005 01:39:51 -0000 1.7 +++ ManagerReader.java 5 Mar 2005 13:34:23 -0000 1.8 @@ -21,7 +21,7 @@ import net.sf.asterisk.manager.io.Socket /** * The ManagerReader reads events and responses from the asterisk server, parses them using - * EventBuilder and ResponseBuilder and dispatches them to the associated ManagerConnection.<br> + * EventBuilderImpl and ResponseBuilder and dispatches them to the associated ManagerConnection.<br> * This class is intended to be used only by the DefaultManagerConnection. * * @see net.sf.asterisk.manager.EventBuilder @@ -43,7 +43,7 @@ interface ManagerReader extends Runnable void setSocket(final SocketConnectionFacade socket); /** - * Registers a new event type with the underlying EventBuilder.<br> + * Registers a new event type with the underlying EventBuilderImpl.<br> * The eventClass must extend ManagerEvent. * * @see EventBuilder Index: ResponseBuilder.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ResponseBuilder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ResponseBuilder.java 1 Mar 2005 19:25:35 -0000 1.1 +++ ResponseBuilder.java 5 Mar 2005 13:34:23 -0000 1.2 @@ -18,11 +18,6 @@ package net.sf.asterisk.manager; import java.util.Map; -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; /** @@ -32,8 +27,9 @@ import net.sf.asterisk.manager.response. * @author srt * @version $Id$ */ -public class ResponseBuilder +public interface ResponseBuilder { + /** * Constructs an instance of ManagerResponse based on a map of attributes. * @@ -41,80 +37,5 @@ public class ResponseBuilder * 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; - } + ManagerResponse buildResponse(Map attributes); } Index: ActionBuilder.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ActionBuilder.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- ActionBuilder.java 25 Feb 2005 23:34:52 -0000 1.4 +++ ActionBuilder.java 5 Mar 2005 13:34:23 -0000 1.5 @@ -16,17 +16,8 @@ */ package net.sf.asterisk.manager; -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.action.ManagerAction; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - /** * Transforms ManagerActions to Strings suitable to be sent to Asterisk.<br> * The attributes are determined using reflection. @@ -34,14 +25,9 @@ import org.apache.commons.logging.LogFac * @author srt * @version $Id$ */ -public class ActionBuilder +public interface ActionBuilder { /** - * Instance logger. - */ - private final Log logger = LogFactory.getLog(getClass()); - - /** * Builds a String suitable to be sent to Asterisk based on the given action object.<br> * Asterisk actions consist of an unordered set of key value pairs corresponding to the * attributes of the ManagerActions. Key and value are separated by a colon (":"), key value @@ -50,112 +36,5 @@ public class ActionBuilder * @param action the action to transform * @return a String representing the given action in an asterisk compatible format */ - 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; - } + String buildAction(final ManagerAction action); } Index: ManagerWriterImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerWriterImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ManagerWriterImpl.java 5 Mar 2005 04:18:52 -0000 1.2 +++ ManagerWriterImpl.java 5 Mar 2005 13:34:23 -0000 1.3 @@ -50,7 +50,7 @@ class ManagerWriterImpl implements Manag */ ManagerWriterImpl() { - this.actionBuilder = new ActionBuilder(); + this.actionBuilder = new ActionBuilderImpl(); } public synchronized void setSocket(final SocketConnectionFacade socket) Index: EventBuilder.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/EventBuilder.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- EventBuilder.java 2 Mar 2005 18:35:38 -0000 1.7 +++ EventBuilder.java 5 Mar 2005 13:34:23 -0000 1.8 @@ -16,58 +16,9 @@ */ package net.sf.asterisk.manager; -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.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; /** * Transforms maps of attributes to instances of ManagerEvent. @@ -76,60 +27,8 @@ import org.apache.commons.logging.LogFac * @author srt * @version $Id$ */ -public class EventBuilder +public interface EventBuilder { - private final Log logger = LogFactory.getLog(getClass()); - private Map registeredEventClasses; - - public EventBuilder() - { - 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); - } /** * Registers a new event class. The event this class is registered for is simply derived from @@ -139,221 +38,7 @@ public class EventBuilder * * @param clazz the event class to register, must extend net.sf.asterisk.manager.event.Event. */ - 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); - } + void registerEventClass(Class clazz); - return accessors; - } + ManagerEvent buildEvent(Object source, Map attributes); } Index: ManagerWriter.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ManagerWriter.java 2 Mar 2005 23:15:49 -0000 1.1 +++ ManagerWriter.java 5 Mar 2005 13:34:23 -0000 1.2 @@ -22,7 +22,7 @@ import net.sf.asterisk.manager.action.Ma import net.sf.asterisk.manager.io.SocketConnectionFacade; /** - * The ManagerWriter transforms actions using the ActionBuilder and sends them to the asterisk + * The ManagerWriter transforms actions using an ActionBuilder and sends them to the asterisk * server.<br> * This class is intended to be used only by the DefaultManagerConnection. * Index: ManagerReaderImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerReaderImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ManagerReaderImpl.java 5 Mar 2005 01:39:51 -0000 1.2 +++ ManagerReaderImpl.java 5 Mar 2005 13:34:23 -0000 1.3 @@ -80,6 +80,7 @@ class ManagerReaderImpl implements Manag /** * Creates a new ManagerReaderImpl. + * * @param dispatcher the dispatcher to use for dispatching events and responses. */ ManagerReaderImpl(final Dispatcher dispatcher, AsteriskServer asteriskServer) @@ -87,19 +88,20 @@ class ManagerReaderImpl implements Manag this.dispatcher = dispatcher; this.asteriskServer = asteriskServer; - this.eventBuilder = new EventBuilder(); - this.responseBuilder = new ResponseBuilder(); + 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); |
From: Stefan R. <sr...@us...> - 2005-03-05 13:34:35
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20712/src/test/net/sf/asterisk/manager Added Files: ResponseBuilderImplTest.java ActionBuilderImplTest.java EventBuilderImplTest.java Removed Files: ResponseBuilderTest.java EventBuilderTest.java ActionBuilderTest.java Log Message: Refactored (Action|Event|Response)Builder into interfaces --- 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; import java.util.HashMap; import java.util.Map; 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; import junit.framework.TestCase; 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: 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; import junit.framework.TestCase; 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"; } } } --- 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; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; 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/05 13:34:23 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()); } } --- ResponseBuilderTest.java DELETED --- --- EventBuilderTest.java DELETED --- --- ActionBuilderTest.java DELETED --- |
From: Stefan R. <sr...@us...> - 2005-03-05 04:19:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32475/src/java/net/sf/asterisk/manager Modified Files: ManagerWriterImpl.java Log Message: Renamed SocketConnectionFacade.print(String) to SocketConnectionFacade.write(String) Index: ManagerWriterImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerWriterImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ManagerWriterImpl.java 2 Mar 2005 23:15:49 -0000 1.1 +++ ManagerWriterImpl.java 5 Mar 2005 04:18:52 -0000 1.2 @@ -69,7 +69,7 @@ class ManagerWriterImpl implements Manag actionString = actionBuilder.buildAction(action); - socket.print(actionString); + socket.write(actionString); socket.flush(); logger.debug("Sent " + action.getAction() + " action with actionId '" + action.getActionId() + "':\n" |
From: Stefan R. <sr...@us...> - 2005-03-05 04:19:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32475/src/java/net/sf/asterisk/manager/io Modified Files: SocketConnectionFacade.java SocketConnectionFacadeImpl.java Log Message: Renamed SocketConnectionFacade.print(String) to SocketConnectionFacade.write(String) Index: SocketConnectionFacade.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/io/SocketConnectionFacade.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- SocketConnectionFacade.java 2 Mar 2005 23:15:50 -0000 1.1 +++ SocketConnectionFacade.java 5 Mar 2005 04:18:53 -0000 1.2 @@ -22,7 +22,7 @@ public interface SocketConnectionFacade { String readLine() throws IOException; - void print(String s) throws IOException; + void write(String s) throws IOException; void flush() throws IOException; Index: SocketConnectionFacadeImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/io/SocketConnectionFacadeImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SocketConnectionFacadeImpl.java 5 Mar 2005 04:13:18 -0000 1.2 +++ SocketConnectionFacadeImpl.java 5 Mar 2005 04:18:53 -0000 1.3 @@ -41,7 +41,7 @@ public class SocketConnectionFacadeImpl return reader.readLine(); } - public void print(String s) throws IOException + public void write(String s) throws IOException { writer.write(s); } |
From: Stefan R. <sr...@us...> - 2005-03-05 04:19:04
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32475/src/test/net/sf/asterisk/manager Modified Files: ManagerWriterImplTest.java Log Message: Renamed SocketConnectionFacade.print(String) to SocketConnectionFacade.write(String) Index: ManagerWriterImplTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/ManagerWriterImplTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ManagerWriterImplTest.java 2 Mar 2005 23:15:50 -0000 1.1 +++ ManagerWriterImplTest.java 5 Mar 2005 04:18:53 -0000 1.2 @@ -51,7 +51,7 @@ public class ManagerWriterImplTest exten socketMC = MockControl.createControl(SocketConnectionFacade.class); socketConnectionFacade = (SocketConnectionFacade) socketMC.getMock(); - socketConnectionFacade.print("action: Status\r\n\r\n"); + socketConnectionFacade.write("action: Status\r\n\r\n"); socketConnectionFacade.flush(); socketMC.replay(); |
From: Stefan R. <sr...@us...> - 2005-03-05 04:15:42
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31518/src/java/net/sf/asterisk/manager Modified Files: DefaultManagerConnection.java Log Message: Added name to readerThread for better debugging (it's called ManagerReaderThread) Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -p -r1.8 -r1.9 --- DefaultManagerConnection.java 5 Mar 2005 01:39:51 -0000 1.8 +++ DefaultManagerConnection.java 5 Mar 2005 04:15:34 -0000 1.9 @@ -330,7 +330,7 @@ public class DefaultManagerConnection im this.socket = createSocket(); this.reader.setSocket(socket); - this.readerThread = new Thread(reader); + this.readerThread = new Thread(reader, "ManagerReaderThread"); this.readerThread.start(); this.writer.setSocket(socket); |
From: Stefan R. <sr...@us...> - 2005-03-05 04:13:28
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30717/src/java/net/sf/asterisk/manager/io Modified Files: SocketConnectionFacadeImpl.java Log Message: Changed PrintWriter to BufferedWriter Index: SocketConnectionFacadeImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/io/SocketConnectionFacadeImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- SocketConnectionFacadeImpl.java 2 Mar 2005 23:15:50 -0000 1.1 +++ SocketConnectionFacadeImpl.java 5 Mar 2005 04:13:18 -0000 1.2 @@ -17,23 +17,23 @@ package net.sf.asterisk.manager.io; import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.net.Socket; public class SocketConnectionFacadeImpl implements SocketConnectionFacade { private final Socket socket; private final BufferedReader reader; - private final PrintWriter writer; + private final BufferedWriter writer; public SocketConnectionFacadeImpl(String host, int port) throws IOException { this.socket = new Socket(host, port); this.reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); - this.writer = new PrintWriter(new OutputStreamWriter(this.socket.getOutputStream())); + this.writer = new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream())); } public String readLine() throws IOException @@ -43,7 +43,7 @@ public class SocketConnectionFacadeImpl public void print(String s) throws IOException { - writer.print(s); + writer.write(s); } public void flush() throws IOException |
From: Stefan R. <sr...@us...> - 2005-03-05 04:12:50
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30402/src/java/net/sf/asterisk/manager Modified Files: DefaultAsteriskManager.java Log Message: Fixed handleConnectEvent Index: DefaultAsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultAsteriskManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- DefaultAsteriskManager.java 23 Feb 2005 22:50:57 -0000 1.2 +++ DefaultAsteriskManager.java 5 Mar 2005 04:12:39 -0000 1.3 @@ -66,6 +66,7 @@ public class DefaultAsteriskManager impl private boolean channelsInitialized; private boolean queuesInitialized; private boolean initialized; + private boolean loggedIn; public DefaultAsteriskManager() { @@ -76,6 +77,7 @@ public class DefaultAsteriskManager impl // TODO fix detection of queuesInitialized this.queuesInitialized = true; this.initialized = false; + this.loggedIn = false; } public void setManagerConnection(ManagerConnection connection) @@ -87,6 +89,8 @@ public class DefaultAsteriskManager impl { connection.addEventHandler(this); connection.login(); + + loggedIn = true; connection.sendAction(new StatusAction()); connection.sendAction(new QueueStatusAction()); } @@ -303,6 +307,12 @@ public class DefaultAsteriskManager impl */ protected void handleConnectEvent(ConnectEvent connectEvent) { + // first connect is no reconnect ;) + if (!loggedIn) + { + return; + } + try { connection.sendAction(new StatusAction()); |
From: Stefan R. <sr...@us...> - 2005-03-05 02:58:37
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14379/src/test/net/sf/asterisk/manager Modified Files: DefaultManagerConnectionTest.java Log Message: Fixed timing when checking for ManagerReader.run() being called Index: DefaultManagerConnectionTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/DefaultManagerConnectionTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -p -r1.5 -r1.6 --- DefaultManagerConnectionTest.java 5 Mar 2005 01:39:51 -0000 1.5 +++ DefaultManagerConnectionTest.java 5 Mar 2005 02:58:24 -0000 1.6 @@ -127,7 +127,10 @@ public class DefaultManagerConnectionTes assertEquals("unexpected other actions sent", 0, mockWriter.otherActionsSent); assertEquals("setSocket() not called 1 time", 1, mockReader.setSocketCalls); - // assertEquals("run() not called 1 time", 1, mockReader.runCalls); + // Some time for the reader thread to be started. Otherwise run() might not yet have been + // called. + Thread.sleep(10); + assertEquals("run() not called 1 time", 1, mockReader.runCalls); assertEquals("unexpected call to die()", 0, mockReader.dieCalls); assertTrue("keepAlive not set", dmc.getKeepAlive()); @@ -168,8 +171,10 @@ public class DefaultManagerConnectionTes assertEquals("unexpected other actions sent", 0, mockWriter.otherActionsSent); assertEquals("setSocket() not called 1 time", 1, mockReader.setSocketCalls); - // TODO why is run() not called? - // assertEquals("run() not called 1 time", 1, mockReader.runCalls); + // Some time for the reader thread to be started. Otherwise run() might not yet have been + // called. + Thread.sleep(10); + assertEquals("run() not called 1 time", 1, mockReader.runCalls); assertEquals("unexpected call to die()", 0, mockReader.dieCalls); socketMC.verify(); @@ -231,6 +236,9 @@ public class DefaultManagerConnectionTes assertEquals("unexpected other actions sent", 0, mockWriter.otherActionsSent); assertEquals("setSocket() not called 1 time", 1, mockReader.setSocketCalls); + // Some time for the reader thread to be started. Otherwise run() might not yet have been + // called. + Thread.sleep(10); assertEquals("run() not called 1 time", 1, mockReader.runCalls); assertEquals("unexpected call to die()", 0, mockReader.dieCalls); @@ -263,6 +271,9 @@ public class DefaultManagerConnectionTes assertEquals("unexpected other actions sent", 0, mockWriter.otherActionsSent); assertEquals("setSocket() not called 1 time", 1, mockReader.setSocketCalls); + // Some time for the reader thread to be started. Otherwise run() might not yet have been + // called. + Thread.sleep(10); assertEquals("run() not called 1 time", 1, mockReader.runCalls); assertEquals("unexpected call to die()", 0, mockReader.dieCalls); |
From: Stefan R. <sr...@us...> - 2005-03-05 02:28:06
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7613/src/java/net/sf/asterisk/manager Modified Files: ManagerConnection.java Log Message: Added UserEvent Index: ManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerConnection.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- ManagerConnection.java 5 Mar 2005 01:39:51 -0000 1.4 +++ ManagerConnection.java 5 Mar 2005 02:27:58 -0000 1.5 @@ -36,10 +36,16 @@ public interface ManagerConnection /** * Registers a new user event type.<br> * Asterisk allows you to send custom events via the UserEvent application. If you choose to - * send such events you can extend the abstract class ManagerEvent and add your own attributes. - * After registering a user event type asterisk-java will handle such events the same way it - * handles the internal events and inform your registered event handlers. + * send such events you can extend the abstract class UserEvent provide a name for your new + * event and optionally add your own attributes. After registering a user event type + * asterisk-java will handle such events the same way it handles the internal events and inform + * your registered event handlers.<br> + * Note: If you write your own asterisk applications that use asterisk's + * <code>manager_event()</code> function directly and don't use the channel and uniqueid + * attributes provided by UserEvent you can also register events that directly subclass + * ManagerEvent. * + * @see net.sf.asterisk.manager.event.UserEvent * @see ManagerEvent * * @param userEventClass the class of the user event to register. |
From: Stefan R. <sr...@us...> - 2005-03-05 02:28:06
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7613/src/java/net/sf/asterisk/manager/event Added Files: UserEvent.java Log Message: Added UserEvent --- NEW FILE: UserEvent.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.event; /** * Abstract base class for user events.<br> * You can send arbitrary user events via the UserEvent application provided with asterisk. A user * event by default has the attributes channel and uniqueId but you can add custom attributes by * specifying an event body.<br> * To add your own user events you must subclass this class and name it corresponding to your event. * If you plan to send an event by <code>UserEvent(VIPCall)</code> you will create a new class * called VIPCallEvent that extends UserEvent. To pass additional data create appropriate attributes * with getter and setter methods in your new class.<br> * Example: * <pre> * public class VIPCallEvent extends UserEvent * { * private String firstName; * * public VIPCallEvent(Object source) * { * super(source); * } * * public String getFirstName() * { * return firstName; * } * * public void setFirstName(String firstName) * { * this.firstName = firstName; * } * } * </pre> * To send this event use <code>UserEvent(VIPCall|firstName: Jon)</code> in your dialplan.<br> * The UserEvent is implemented in <code>apps/app_userevent.c</code>. * * @author srt * @version $Id: UserEvent.java,v 1.1 2005/03/05 02:27:58 srt Exp $ */ public abstract class UserEvent extends ManagerEvent { /** * Serial version identifier */ private static final long serialVersionUID = 3256725065466000695L; /** * The name of the channel. */ private String channel; /** * The unique id of the channel. */ private String uniqueId; public UserEvent(Object source) { super(source); } /** * Returns the name of the channel this event occured in. * * @return the name of the channel this event occured in. */ public String getChannel() { return channel; } /** * Sets the name of the channel this event occured in. * * @param channel the name of the channel this event occured in. */ public void setChannel(String channel) { this.channel = channel; } /** * Returns the unqiue id of the channel this event occured in. * * @return the unqiue id of the channel this event occured in. */ public String getUniqueId() { return uniqueId; } /** * Sets the unqiue id of the channel this event occured in. * * @param uniqueId the unqiue id of the channel this event occured in. */ public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; } } |
From: Stefan R. <sr...@us...> - 2005-03-05 01:40:02
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27309/src/java/net/sf/asterisk/manager Modified Files: ManagerReader.java DefaultManagerConnection.java ManagerConnection.java ManagerReaderImpl.java Log Message: Added registerUserEventClass() to ManagerConnection to allow users to add their custom event classes without changing asterisk-java's source code Index: ManagerReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerReader.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- ManagerReader.java 2 Mar 2005 23:15:38 -0000 1.6 +++ ManagerReader.java 5 Mar 2005 01:39:51 -0000 1.7 @@ -16,6 +16,7 @@ */ package net.sf.asterisk.manager; +import net.sf.asterisk.manager.event.ManagerEvent; import net.sf.asterisk.manager.io.SocketConnectionFacade; /** @@ -41,6 +42,17 @@ interface ManagerReader extends Runnable */ void setSocket(final SocketConnectionFacade socket); + /** + * Registers a new event type with the underlying EventBuilder.<br> + * The eventClass must extend ManagerEvent. + * + * @see EventBuilder + * @see ManagerEvent + * + * @param eventClass class of the event to register. + */ + void registerEventClass(Class event); + void die(); } Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- DefaultManagerConnection.java 5 Mar 2005 00:32:50 -0000 1.7 +++ DefaultManagerConnection.java 5 Mar 2005 01:39:51 -0000 1.8 @@ -194,6 +194,16 @@ public class DefaultManagerConnection im /* Implementation of ManagerConnection interface */ + public void registerUserEventClass(Class userEventClass) + { + if (reader == null) + { + reader = createReader(this, asteriskServer); + } + + reader.registerEventClass(userEventClass); + } + /** * Logs in to the asterisk manager using asterisk's MD5 based challenge/response protocol. The * login is delayed until the protocol identifier has been received by the reader. Index: ManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerConnection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- ManagerConnection.java 23 Feb 2005 23:00:50 -0000 1.3 +++ ManagerConnection.java 5 Mar 2005 01:39:51 -0000 1.4 @@ -19,6 +19,7 @@ package net.sf.asterisk.manager; import java.io.IOException; import net.sf.asterisk.manager.action.ManagerAction; +import net.sf.asterisk.manager.event.ManagerEvent; import net.sf.asterisk.manager.response.ManagerResponse; /** @@ -33,6 +34,19 @@ import net.sf.asterisk.manager.response. public interface ManagerConnection { /** + * Registers a new user event type.<br> + * Asterisk allows you to send custom events via the UserEvent application. If you choose to + * send such events you can extend the abstract class ManagerEvent and add your own attributes. + * After registering a user event type asterisk-java will handle such events the same way it + * handles the internal events and inform your registered event handlers. + * + * @see ManagerEvent + * + * @param userEventClass the class of the user event to register. + */ + void registerUserEventClass(Class userEventClass); + + /** * Logs in to the asterisk server with the username and password specified when this connection * was created. * @@ -132,6 +146,7 @@ public interface ManagerConnection /** * Returns the Asterisk server of this connection. + * * @return the Asterisk server of this connection. */ AsteriskServer getAsteriskServer(); Index: ManagerReaderImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerReaderImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ManagerReaderImpl.java 2 Mar 2005 23:15:50 -0000 1.1 +++ ManagerReaderImpl.java 5 Mar 2005 01:39:51 -0000 1.2 @@ -99,6 +99,11 @@ class ManagerReaderImpl implements Manag { 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 |
From: Stefan R. <sr...@us...> - 2005-03-05 01:40:02
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27309/src/test/net/sf/asterisk/manager Modified Files: ManagerReaderImplTest.java ManagerReaderMock.java DefaultManagerConnectionTest.java Added Files: MyUserEvent.java Log Message: Added registerUserEventClass() to ManagerConnection to allow users to add their custom event classes without changing asterisk-java's source code --- NEW FILE: MyUserEvent.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; import net.sf.asterisk.manager.event.ManagerEvent; public class MyUserEvent extends ManagerEvent { private static final long serialVersionUID = 3689913989471418169L; public MyUserEvent(Object source) { super(source); } } Index: ManagerReaderImplTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/ManagerReaderImplTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ManagerReaderImplTest.java 4 Mar 2005 22:21:04 -0000 1.2 +++ ManagerReaderImplTest.java 5 Mar 2005 01:39:51 -0000 1.3 @@ -54,7 +54,7 @@ public class ManagerReaderImplTest exten socketConnectionFacadeMC = MockControl.createControl(SocketConnectionFacade.class); socketConnectionFacade = (SocketConnectionFacade) socketConnectionFacadeMC.getMock(); } - + protected void tearDown() { DateUtil.overrideCurrentDate(null); @@ -132,6 +132,38 @@ public class ManagerReaderImplTest exten 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; Index: ManagerReaderMock.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/ManagerReaderMock.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ManagerReaderMock.java 4 Mar 2005 22:21:04 -0000 1.1 +++ ManagerReaderMock.java 5 Mar 2005 01:39:51 -0000 1.2 @@ -29,6 +29,11 @@ public class ManagerReaderMock implement } + public void registerEventClass(Class event) + { + throw new UnsupportedOperationException(); + } + public void setSocket(SocketConnectionFacade socket) { setSocketCalls++; Index: DefaultManagerConnectionTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/DefaultManagerConnectionTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- DefaultManagerConnectionTest.java 5 Mar 2005 00:43:45 -0000 1.4 +++ DefaultManagerConnectionTest.java 5 Mar 2005 01:39:51 -0000 1.5 @@ -76,6 +76,27 @@ public class DefaultManagerConnectionTes assertEquals("Invalid password", "p", dmc.getPassword()); } + public void testRegisterUserEventClass() + { + MockControl managerReaderMC; + ManagerReader managerReader; + + managerReaderMC = MockControl.createControl(ManagerReader.class); + managerReader = (ManagerReader) managerReaderMC.getMock(); + + managerReader.registerEventClass(MyUserEvent.class); + managerReaderMC.replay(); + + dmc = new MockedDefaultManagerConnection(managerReader, mockWriter, mockSocket); + dmc.registerUserEventClass(MyUserEvent.class); + + assertEquals("unexpected call to createSocket", 0, dmc.createSocketCalls); + assertEquals("unexpected call to createWriter", 0, dmc.createWriterCalls); + assertEquals("createReader not called 1 time", 1, dmc.createReaderCalls); + + managerReaderMC.verify(); + } + public void testLogin() throws Exception { MockControl managerEventHandlerMC; |
From: Stefan R. <sr...@us...> - 2005-03-05 00:43:53
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12473/src/test/net/sf/asterisk/manager Modified Files: DefaultManagerConnectionTest.java Log Message: Fixed setSleepTime and setDefaultTimeout to fit Index: DefaultManagerConnectionTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/DefaultManagerConnectionTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- DefaultManagerConnectionTest.java 5 Mar 2005 00:33:16 -0000 1.3 +++ DefaultManagerConnectionTest.java 5 Mar 2005 00:43:45 -0000 1.4 @@ -53,7 +53,8 @@ public class DefaultManagerConnectionTes dmc = new MockedDefaultManagerConnection(mockReader, mockWriter, mockSocket); // make tests faster that expect a TimeoutException - dmc.setDefaultTimeout(10); + dmc.setSleepTime(5); + dmc.setDefaultTimeout(20); mockWriter.setDispatcher(dmc); mockWriter.setAsteriskServer(asteriskServer); |
From: Stefan R. <sr...@us...> - 2005-03-05 00:33:27
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9825/src/test/net/sf/asterisk/manager Modified Files: ManagerWriterMock.java DefaultManagerConnectionTest.java Log Message: Added testReconnectWithKeepAliveAfterAuthenticationFailure Index: ManagerWriterMock.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/ManagerWriterMock.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ManagerWriterMock.java 5 Mar 2005 00:14:32 -0000 1.2 +++ ManagerWriterMock.java 5 Mar 2005 00:33:16 -0000 1.3 @@ -129,6 +129,7 @@ public class ManagerWriterMock implement { throw new RuntimeException("Expected authType 'MD5' got '" + authType + "'"); } + if (!expectedUsername.equals(username)) { throw new RuntimeException("Expected username '" + expectedUsername + "' got '" + username + "'"); @@ -140,7 +141,9 @@ public class ManagerWriterMock implement { ManagerResponse loginResponse; - if (key.equals(expectedKey)) + // let testReconnectWithKeepAliveAfterAuthenticationFailure succeed after + // 3 unsuccessful attempts + if (key.equals(expectedKey) || loginActionsSent > 2) { loginResponse = new ManagerResponse(); loginResponse.setResponse("Success"); Index: DefaultManagerConnectionTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/DefaultManagerConnectionTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- DefaultManagerConnectionTest.java 5 Mar 2005 00:14:32 -0000 1.2 +++ DefaultManagerConnectionTest.java 5 Mar 2005 00:33:16 -0000 1.3 @@ -422,7 +422,7 @@ public class DefaultManagerConnectionTes // fake successful login dmc.setKeepAlive(true); - + dmc.setThrowIOExceptionOnFirstSocketCreate(true); dmc.setUsername("username"); @@ -467,7 +467,40 @@ public class DefaultManagerConnectionTes assertEquals("unexpected other actions sent", 0, mockWriter.otherActionsSent); assertFalse("keepAlive not disabled", dmc.getKeepAlive()); - + + socketMC.verify(); + } + + public void testReconnectWithKeepAliveAfterAuthenticationFailure() throws Exception + { + DisconnectEvent disconnectEvent; + + // 2 unsuccessful attempts + mockSocket.close(); + mockSocket.close(); + socketMC.replay(); + disconnectEvent = new DisconnectEvent(asteriskServer); + + // fake successful login + dmc.setKeepAlive(true); + + // to prevent an infinite loop we will be able to log in after two unsuccessful attempts + // even if the password is not correct. + dmc.setKeepAliveAfterAuthenticationFailure(true); + dmc.setUsername("username"); + + dmc.dispatchEvent(disconnectEvent); + + assertEquals("createSocket not called 3 time", 3, dmc.createSocketCalls); + assertEquals("createWriter not called 1 time", 1, dmc.createWriterCalls); + assertEquals("createReader not called 1 time", 1, dmc.createReaderCalls); + + assertEquals("challenge action not sent 3 time", 3, mockWriter.challengeActionsSent); + assertEquals("login action not sent 3 time", 3, mockWriter.loginActionsSent); + assertEquals("unexpected other actions sent", 0, mockWriter.otherActionsSent); + + assertTrue("keepAlive not enabled", dmc.getKeepAlive()); + socketMC.verify(); } |
From: Stefan R. <sr...@us...> - 2005-03-05 00:32:59
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9684/src/java/net/sf/asterisk/manager Modified Files: DefaultManagerConnection.java Log Message: Fixed overly verbose exception logging Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- DefaultManagerConnection.java 5 Mar 2005 00:14:32 -0000 1.6 +++ DefaultManagerConnection.java 5 Mar 2005 00:32:50 -0000 1.7 @@ -684,7 +684,7 @@ public class DefaultManagerConnection im { if (this.keepAliveAfterAuthenticationFailure) { - logger.error("Unable to log in after reconnect.", e1); + logger.error("Unable to log in after reconnect."); } else { @@ -705,7 +705,7 @@ public class DefaultManagerConnection im catch (IOException e) { // server seems to be still down, just continue to attempt reconnection - logger.warn("Exception while trying to reconnect", e); + logger.warn("Exception while trying to reconnect: " + e.getMessage()); } numTries++; } |