asterisk-java-cvs Mailing List for Asterisk-Java Library (Page 91)
Brought to you by:
srt
You can subscribe to this list here.
2005 |
Jan
(4) |
Feb
(75) |
Mar
(211) |
Apr
(70) |
May
(12) |
Jun
(7) |
Jul
(96) |
Aug
(90) |
Sep
(11) |
Oct
(42) |
Nov
(45) |
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(20) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(32) |
Aug
|
Sep
(4) |
Oct
(2) |
Nov
(10) |
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
(3) |
Aug
(73) |
Sep
(13) |
Oct
(4) |
Nov
(1) |
Dec
(7) |
2009 |
Jan
(1) |
Feb
(2) |
Mar
(48) |
Apr
(21) |
May
(14) |
Jun
(11) |
Jul
(9) |
Aug
(2) |
Sep
(11) |
Oct
(14) |
Nov
(6) |
Dec
(4) |
2010 |
Jan
(3) |
Feb
(2) |
Mar
|
Apr
|
May
(3) |
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
(9) |
Nov
|
Dec
(12) |
2011 |
Jan
(1) |
Feb
(5) |
Mar
(7) |
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(10) |
Sep
|
Oct
(5) |
Nov
|
Dec
|
2012 |
Jan
(3) |
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
(2) |
Dec
(2) |
2013 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
(2) |
Nov
|
Dec
(1) |
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(5) |
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
(25) |
May
(10) |
Jun
(4) |
Jul
(7) |
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
(3) |
Dec
(1) |
2016 |
Jan
|
Feb
(42) |
Mar
(6) |
Apr
(15) |
May
(3) |
Jun
(1) |
Jul
(11) |
Aug
|
Sep
|
Oct
(17) |
Nov
(2) |
Dec
|
2017 |
Jan
|
Feb
(4) |
Mar
(1) |
Apr
(3) |
May
(2) |
Jun
(3) |
Jul
(7) |
Aug
(11) |
Sep
(5) |
Oct
(7) |
Nov
(4) |
Dec
(4) |
2018 |
Jan
(11) |
Feb
(11) |
Mar
(3) |
Apr
|
May
(9) |
Jun
(6) |
Jul
(17) |
Aug
(9) |
Sep
(2) |
Oct
(4) |
Nov
(3) |
Dec
(3) |
2019 |
Jan
(13) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(5) |
Jun
|
Jul
(1) |
Aug
(6) |
Sep
|
Oct
|
Nov
(3) |
Dec
|
2020 |
Jan
(2) |
Feb
(72) |
Mar
(8) |
Apr
(11) |
May
(12) |
Jun
(3) |
Jul
(12) |
Aug
(3) |
Sep
(5) |
Oct
(4) |
Nov
|
Dec
(9) |
2021 |
Jan
|
Feb
(31) |
Mar
(6) |
Apr
(3) |
May
|
Jun
(2) |
Jul
|
Aug
(2) |
Sep
|
Oct
(9) |
Nov
|
Dec
(32) |
2022 |
Jan
(5) |
Feb
(7) |
Mar
(2) |
Apr
(3) |
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
(2) |
Oct
(111) |
Nov
(105) |
Dec
(26) |
2023 |
Jan
(25) |
Feb
(6) |
Mar
(10) |
Apr
(54) |
May
(41) |
Jun
(24) |
Jul
(6) |
Aug
(11) |
Sep
(9) |
Oct
(8) |
Nov
(55) |
Dec
(34) |
2024 |
Jan
(6) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(89) |
Sep
(48) |
Oct
(31) |
Nov
(9) |
Dec
(19) |
2025 |
Jan
(12) |
Feb
(18) |
Mar
(9) |
Apr
(7) |
May
|
Jun
(7) |
Jul
(5) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Stefan R. <sr...@us...> - 2005-03-10 21:48:23
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13678/src/java/net/sf/asterisk/fastagi/command Modified Files: SetAutoHangupCommand.java SayPhoneticCommand.java GetVariableCommand.java ExecCommand.java SayTimeCommand.java SayDigitsCommand.java VerboseCommand.java SetVariableCommand.java Log Message: Fixed parameter names Index: SetAutoHangupCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SetAutoHangupCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SetAutoHangupCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ SetAutoHangupCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -68,9 +68,9 @@ public class SetAutoHangupCommand extend * hung up.<br> * 0 disables the autohangup feature. */ - public void setTime(int timeout) + public void setTime(int time) { - this.time = timeout; + this.time = time; } public String buildCommand() Index: SayPhoneticCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SayPhoneticCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SayPhoneticCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ SayPhoneticCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -60,10 +60,10 @@ public class SayPhoneticCommand extends * @param escapeDigits contains the digits that allow the user to interrupt * this command. */ - public SayPhoneticCommand(String text, String interruptDigits) + public SayPhoneticCommand(String text, String escapeDigits) { this.text = text; - this.escapeDigits = interruptDigits; + this.escapeDigits = escapeDigits; } /** Index: GetVariableCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/GetVariableCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- GetVariableCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ GetVariableCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -62,9 +62,9 @@ public class GetVariableCommand extends * * @param variable the name of the variable to retrieve. */ - public void setVariable(String context) + public void setVariable(String variable) { - this.variable = context; + this.variable = variable; } public String buildCommand() Index: ExecCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/ExecCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ExecCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ ExecCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -78,9 +78,9 @@ public class ExecCommand extends AGIComm * * @param application the name of the application to execute. */ - public void setApplication(String channel) + public void setApplication(String application) { - this.application = channel; + this.application = application; this.options = null; } Index: SayTimeCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SayTimeCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SayTimeCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ SayTimeCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -62,10 +62,10 @@ public class SayTimeCommand extends AGIC * @param escapeDigits contains the digits that allow the user to interrupt * this command. */ - public SayTimeCommand(long time, String interruptDigits) + public SayTimeCommand(long time, String escapeDigits) { this.time = time; - this.escapeDigits = interruptDigits; + this.escapeDigits = escapeDigits; } /** Index: SayDigitsCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SayDigitsCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SayDigitsCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ SayDigitsCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -48,9 +48,9 @@ public class SayDigitsCommand extends AG * * @param number the number to say. */ - public SayDigitsCommand(String digits) + public SayDigitsCommand(String number) { - this.number = digits; + this.number = number; this.escapeDigits = null; } Index: VerboseCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/VerboseCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- VerboseCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ VerboseCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -77,9 +77,9 @@ public class VerboseCommand extends AGIC * * @param message the message to send. */ - public void setMessage(String context) + public void setMessage(String message) { - this.message = context; + this.message = message; } /** Index: SetVariableCommand.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command/SetVariableCommand.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SetVariableCommand.java 8 Mar 2005 16:48:34 -0000 1.2 +++ SetVariableCommand.java 10 Mar 2005 21:48:11 -0000 1.3 @@ -66,9 +66,9 @@ public class SetVariableCommand extends * * @param variable the name of the variable to set. */ - public void setVariable(String context) + public void setVariable(String variable) { - this.variable = context; + this.variable = variable; } /** |
From: Stefan R. <sr...@us...> - 2005-03-10 21:31:44
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8941/src/test/net/sf/asterisk/fastagi Added Files: ResourceBundleMappingStrategyTest.java fastagi-mapping.properties HelloAGIScript.java Log Message: Added ResourceBundleMappingStrategy --- NEW FILE: ResourceBundleMappingStrategyTest.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 junit.framework.TestCase; public class ResourceBundleMappingStrategyTest extends TestCase { private ResourceBundleMappingStrategy mappingStrategy; protected void setUp() throws Exception { super.setUp(); this.mappingStrategy = new ResourceBundleMappingStrategy(); this.mappingStrategy .setResourceBundleName("net.sf.asterisk.fastagi.fastagi-mapping"); } public void testDetermineScript() { AGIScript scriptFirstPass; AGIScript scriptSecondPass; AGIRequestImpl request; request = new AGIRequestImpl(); request.setScript("hello.agi"); scriptFirstPass = mappingStrategy.determineScript(request); scriptSecondPass = mappingStrategy.determineScript(request); assertTrue("incorrect script determined", scriptFirstPass instanceof HelloAGIScript); assertTrue("script instances are not cached", scriptFirstPass == scriptSecondPass); } public void testDetermineScriptWithResourceBundleUnavailable() { AGIRequestImpl request; request = new AGIRequestImpl(); request.setScript("hello.agi"); mappingStrategy.setResourceBundleName("net.sf.asterisk.fastagi.unavailable"); assertNull(mappingStrategy.determineScript(request)); } } --- NEW FILE: fastagi-mapping.properties --- hello.agi = net.sf.asterisk.fastagi.HelloAGIScript string.agi = java.lang.String nonexisting.agi = net.sf.asterisk.fastagi.NonExistingAGIScript --- NEW FILE: HelloAGIScript.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; /** * Test script for use with the ResourceBundleMappingStrategyTest. * * @author srt * @version $Id: HelloAGIScript.java,v 1.1 2005/03/10 21:31:31 srt Exp $ */ public class HelloAGIScript implements AGIScript { public HelloAGIScript() { } public void service(AGIRequest request, AGIResponse response) { return; } } |
From: Stefan R. <sr...@us...> - 2005-03-10 21:31:44
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8941/src/java/net/sf/asterisk/fastagi Modified Files: DefaultAGIServer.java Added Files: ResourceBundleMappingStrategy.java Log Message: Added ResourceBundleMappingStrategy --- NEW FILE: ResourceBundleMappingStrategy.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.lang.reflect.Constructor; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * A MappingStrategy that is configured via a resource bundle.<br> * The resource bundle contains the script part of the url as key and the fully * qualified class name of the corresponding AGIScript as value.<br> * Example: * * <pre> * leastcostdial.agi = com.example.fastagi.LeastCostDialAGIScript * hello.agi = com.example.fastagi.HelloAGIScript * </pre> * * LeastCostDialAGIScript and HelloAGIScript must both implement the AGIScript * interface and have a default constructor with no parameters.<br> * The resource bundle (properties) file must be called * <code>fastagi-mapping.properties</code> and be available on the classpath. * * @author srt * @version $Id: ResourceBundleMappingStrategy.java,v 1.1 2005/03/10 21:31:30 srt Exp $ */ public class ResourceBundleMappingStrategy implements MappingStrategy { private static final String DEFAULT_RESOURCE_BUNDLE_NAME = "fastagi-mapping"; private final Log logger = LogFactory.getLog(getClass()); private String resourceBundleName; private Map mapping; public ResourceBundleMappingStrategy() { this.resourceBundleName = DEFAULT_RESOURCE_BUNDLE_NAME; this.mapping = null; } public void setResourceBundleName(String propertiesName) { this.resourceBundleName = propertiesName; } private void loadResourceBundle() { ResourceBundle resourceBundle; Enumeration keys; mapping = new HashMap(); try { resourceBundle = ResourceBundle.getBundle(resourceBundleName); } catch (MissingResourceException e) { logger.error("Resource bundle " + resourceBundleName + " is missing."); return; } keys = resourceBundle.getKeys(); while (keys.hasMoreElements()) { String scriptName; String className; AGIScript agiScript; scriptName = (String) keys.nextElement(); className = resourceBundle.getString(scriptName); agiScript = createAGIScriptInstance(className); if (agiScript == null) { continue; } mapping.put(scriptName, agiScript); } } private AGIScript createAGIScriptInstance(String className) { Class agiScriptClass; Constructor constructor; AGIScript agiScript; try { agiScriptClass = Class.forName(className); constructor = agiScriptClass.getConstructor(new Class[]{}); agiScript = (AGIScript) constructor.newInstance(new Object[]{}); } catch (Exception e) { logger.error("Unable to create AGIScript instance of type " + className); return null; } return agiScript; } public AGIScript determineScript(AGIRequest request) { if (mapping == null) { loadResourceBundle(); } return (AGIScript) mapping.get(request.getScript()); } } Index: DefaultAGIServer.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/DefaultAGIServer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- DefaultAGIServer.java 10 Mar 2005 16:36:43 -0000 1.2 +++ DefaultAGIServer.java 10 Mar 2005 21:31:30 -0000 1.3 @@ -81,6 +81,7 @@ public class DefaultAGIServer implements { this.bindPort = DEFAULT_BIND_PORT; this.poolSize = DEFAULT_POOL_SIZE; + this.mappingStrategy = new ResourceBundleMappingStrategy(); } /** |
From: Stefan R. <sr...@us...> - 2005-03-10 16:36:57
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27555/src/test/net/sf/asterisk/fastagi Modified Files: DefaultAGIServerTest.java Log Message: Added MappingStrategy Index: DefaultAGIServerTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/DefaultAGIServerTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- DefaultAGIServerTest.java 10 Mar 2005 13:44:32 -0000 1.1 +++ DefaultAGIServerTest.java 10 Mar 2005 16:36:43 -0000 1.2 @@ -61,7 +61,7 @@ public class DefaultAGIServerTest extend serverSocket.accept(); serverSocketMC.setReturnValue(socket); serverSocket.accept(); - serverSocketMC.setThrowable(new IOException()); + serverSocketMC.setThrowable(new IOException("Unexpected IOException")); serverSocket.close(); serverSocketMC.replay(); |
From: Stefan R. <sr...@us...> - 2005-03-10 16:36:57
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27555/src/java/net/sf/asterisk/fastagi Modified Files: AGIConnectionHandler.java DefaultAGIServer.java Added Files: MappingStrategy.java Log Message: Added MappingStrategy --- NEW FILE: MappingStrategy.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; /** * A MappingStrategy determines which AGIScript has to be called to service a * given AGIRequest. * * @author srt * @version $Id: MappingStrategy.java,v 1.1 2005/03/10 16:36:43 srt Exp $ */ public interface MappingStrategy { /** * Returns the AGIScript that is responsible to handle the given request. * * @param request the request to lookup. * @return the responsible script. */ AGIScript determineScript(AGIRequest request); } Index: AGIConnectionHandler.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIConnectionHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIConnectionHandler.java 10 Mar 2005 13:45:23 -0000 1.1 +++ AGIConnectionHandler.java 10 Mar 2005 16:36:43 -0000 1.2 @@ -35,35 +35,68 @@ import org.apache.commons.logging.LogFac public class AGIConnectionHandler implements Runnable { private final Log logger = LogFactory.getLog(getClass()); + + /** + * The socket connection. + */ private SocketConnectionFacade socket; - private AGIReader reader; - private AGIWriter writer; /** + * The strategy to use to determine which script to run. + */ + private MappingStrategy mappingStrategy; + + /** * Creates a new AGIConnectionHandler to handle the given socket connection. + * * @param socket the socket connection to handle. + * @param mappingStrategy the strategy to use to determine which script to + * run. */ - public AGIConnectionHandler(SocketConnectionFacade socket) + public AGIConnectionHandler(SocketConnectionFacade socket, + MappingStrategy mappingStrategy) { this.socket = socket; - this.reader = new AGIReaderImpl(socket); - this.writer = new AGIWriterImpl(socket); + this.mappingStrategy = mappingStrategy; } - + + protected AGIReader createReader() + { + return new AGIReaderImpl(socket); + } + + protected AGIWriter createWriter() + { + return new AGIWriterImpl(socket); + } + public void run() { - AGIRequest request; - AGIResponse response; - AGIScript script; - try { + AGIReader reader; + AGIWriter writer; + AGIRequest request; + AGIResponse response; + AGIScript script; + + reader = createReader(); + writer = createWriter(); + request = reader.readRequest(); response = new AGIResponseImpl(writer, reader); - - //TODO find appropriate AGIScript - //TODO run AGIScript - //script.service(request, response); + + script = mappingStrategy.determineScript(request); + + if (script != null) + { + script.service(request, response); + } + else + { + logger.error("Unable to determine which script to run for " + + request.getRequestURL()); + } } catch (IOException e) { @@ -75,7 +108,7 @@ public class AGIConnectionHandler implem { socket.close(); } - catch(IOException e) + catch (IOException e) { } } Index: DefaultAGIServer.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/DefaultAGIServer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- DefaultAGIServer.java 10 Mar 2005 13:44:32 -0000 1.1 +++ DefaultAGIServer.java 10 Mar 2005 16:36:43 -0000 1.2 @@ -28,7 +28,14 @@ import net.sf.asterisk.util.ThreadPool; public class DefaultAGIServer implements AGIServer { - private static final int DEFAULT_PORT = 4573; + /** + * The default bind port. + */ + private static final int DEFAULT_BIND_PORT = 4573; + + /** + * The default thread pool size. + */ private static final int DEFAULT_POOL_SIZE = 10; /** @@ -41,7 +48,7 @@ public class DefaultAGIServer implements /** * The port to listen on. */ - protected int port = DEFAULT_PORT; + private int bindPort; /** * The thread pool that contains the worker threads to process incoming @@ -53,18 +60,65 @@ public class DefaultAGIServer implements * The number of worker threads in the thread pool. This equals the maximum * number of concurrent requests this AGIServer can serve. */ - private int poolSize = DEFAULT_POOL_SIZE; + private int poolSize; + /** + * True while this server is shut down. + */ private boolean die; + /** + * The strategy to use for mapping AGIRequests to AGIScripts that serve + * them. + */ + private MappingStrategy mappingStrategy; + + /** + * Creates a new DefaultAGIServer. + * + */ public DefaultAGIServer() { - this.pool = new ThreadPool("AGIServer", poolSize); + this.bindPort = DEFAULT_BIND_PORT; + this.poolSize = DEFAULT_POOL_SIZE; + } + + /** + * Sets the number of worker threads in the thread pool.<br> + * This equals the maximum number of concurrent requests this AGIServer can + * serve. + * + * @param poolSize the size of the worker thread pool. + */ + public void setPoolSize(int poolSize) + { + this.poolSize = poolSize; + } + + /** + * Sets the TCP port to listen on for new connections. + * + * @param bindPort the port to bind to. + */ + public void setBindPort(int bindPort) + { + this.bindPort = bindPort; + } + + /** + * Sets the strategy to use for mapping AGIRequests to AGIScripts that serve + * them. + * + * @param mappingStrategy the mapping strategy to use. + */ + public void setMappingStrategy(MappingStrategy mappingStrategy) + { + this.mappingStrategy = mappingStrategy; } protected ServerSocketFacade createServerSocket() throws IOException { - return new ServerSocketFacadeImpl(port); + return new ServerSocketFacadeImpl(bindPort, 0, null); } public void startup() throws IOException, IllegalStateException @@ -78,6 +132,8 @@ public class DefaultAGIServer implements AGIConnectionHandler connectionHandler; die = false; + pool = new ThreadPool("AGIServer", poolSize); + logger.info("Thread pool started."); try { serverSocket = createServerSocket(); @@ -86,29 +142,35 @@ public class DefaultAGIServer implements while ((socket = serverSocket.accept()) != null) { logger.info("Received connection."); - connectionHandler = new AGIConnectionHandler(socket); + connectionHandler = new AGIConnectionHandler(socket, + mappingStrategy); pool.addJob(connectionHandler); } } catch (IOException e) { // swallow if shutdown - if (die) + if (!die) { logger.error("IOException while waiting for connections.", e); } } finally { - try - { - serverSocket.close(); - } - catch (IOException e) + if (serverSocket != null) { - // swallow + try + { + serverSocket.close(); + } + catch (IOException e) + { + // swallow + } } serverSocket = null; + pool.shutdown(); + logger.info("AGIServer shut down."); } } @@ -120,12 +182,18 @@ public class DefaultAGIServer implements { serverSocket.close(); } - logger.info("AGIServer shut down."); } public void shutdown() throws IOException, IllegalStateException { - pool.shutdown(); die(); } + + public static void main(String[] args) throws Exception + { + AGIServer server; + + server = new DefaultAGIServer(); + server.startup(); + } } |
From: Stefan R. <sr...@us...> - 2005-03-10 16:02:55
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19396/src/java/net/sf/asterisk/io Modified Files: ServerSocketFacadeImpl.java Log Message: Added backlog and bindAddr to ServerSocketFacadeImpl Index: ServerSocketFacadeImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/io/ServerSocketFacadeImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ServerSocketFacadeImpl.java 8 Mar 2005 16:48:35 -0000 1.1 +++ ServerSocketFacadeImpl.java 10 Mar 2005 16:02:45 -0000 1.2 @@ -17,27 +17,36 @@ package net.sf.asterisk.io; import java.io.IOException; +import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; +/** + * Default implementation of the ServerSocketFacade interface using standard + * java.io classes (ServerSocket in this case). + * + * @author srt + * @version $Id$ + */ public class ServerSocketFacadeImpl implements ServerSocketFacade { private ServerSocket serverSocket; - - public ServerSocketFacadeImpl(int port) throws IOException + + public ServerSocketFacadeImpl(int port, int backlog, InetAddress bindAddress) + throws IOException { - this.serverSocket = new ServerSocket(port); + this.serverSocket = new ServerSocket(port, backlog, bindAddress); } public SocketConnectionFacade accept() throws IOException { Socket socket; - + socket = serverSocket.accept(); - + return new SocketConnectionFacadeImpl(socket); } - + public void close() throws IOException { serverSocket.close(); |
From: Stefan R. <sr...@us...> - 2005-03-10 16:01:26
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19052/src/java/net/sf/asterisk/util Modified Files: ThreadPool.java Log Message: Added jobs.notifyAll() to shutdown Index: ThreadPool.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util/ThreadPool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ThreadPool.java 10 Mar 2005 13:45:24 -0000 1.1 +++ ThreadPool.java 10 Mar 2005 16:01:12 -0000 1.2 @@ -125,6 +125,10 @@ public class ThreadPool public void shutdown() { running = false; + synchronized (jobs) + { + jobs.notifyAll(); + } logger.debug("ThreadPool shutting down."); } |
From: Stefan R. <sr...@us...> - 2005-03-10 13:54:18
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18184/src/java/net/sf/asterisk/fastagi/reply Modified Files: AGIReply.java Log Message: Added toString(), hashCode() and equals() Index: AGIReply.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply/AGIReply.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -p -r1.8 -r1.9 --- AGIReply.java 9 Mar 2005 23:45:23 -0000 1.8 +++ AGIReply.java 10 Mar 2005 13:54:06 -0000 1.9 @@ -18,6 +18,11 @@ package net.sf.asterisk.fastagi.reply; 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; + /** * Reply received in response to an AGICommand.<br> * The AGIReply contains information about success or failure of the execution @@ -142,7 +147,7 @@ public class AGIReply implements Seriali * syntax (getStatus() == SC_INVALID_COMMAND_SYNTAX). * * @return the synopsis of the command sent, <code>null</code> if there - * were no syntax errors. + * were no syntax errors. */ public String getSynopsis() { @@ -164,7 +169,7 @@ public class AGIReply implements Seriali * syntax (getStatus() == SC_INVALID_COMMAND_SYNTAX). * * @return the usage of the command sent, <code>null</code> if there were - * no syntax errors. + * no syntax errors. */ public String getUsage() { @@ -180,4 +185,20 @@ public class AGIReply implements Seriali { this.usage = usage; } + + public String toString() + { + return ToStringBuilder.reflectionToString(this, + ToStringStyle.MULTI_LINE_STYLE); + } + + public boolean equals(Object o) + { + return EqualsBuilder.reflectionEquals(this, o); + } + + public int hashCode() + { + return HashCodeBuilder.reflectionHashCode(this); + } } |
From: Stefan R. <sr...@us...> - 2005-03-10 13:45:50
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16225/src/test/net/sf/asterisk/fastagi Modified Files: AGIReaderImplTest.java Added Files: RequestBuilderImplTest.java Removed Files: AGIRequestBuilderImplTest.java Log Message: --- NEW FILE: RequestBuilderImplTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; import java.util.ArrayList; import java.util.Collection; import junit.framework.TestCase; public class RequestBuilderImplTest extends TestCase { private RequestBuilder requestBuilder; protected void setUp() { this.requestBuilder = new RequestBuilderImpl(); } public void testBuildRequest() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_network: yes"); lines.add("agi_network_script: myscript.agi"); lines.add("agi_request: agi://host/myscript.agi"); lines.add("agi_channel: SIP/1234-d715"); lines.add("agi_language: en"); lines.add("agi_type: SIP"); lines.add("agi_uniqueid: 1110023416.6"); lines.add("agi_callerid: John Doe<1234>"); lines.add("agi_dnid: 8870"); lines.add("agi_rdnis: unknown"); lines.add("agi_context: local"); lines.add("agi_extension: 8870"); lines.add("agi_priority: 1"); lines.add("agi_enhanced: 0.0"); lines.add("agi_accountcode: "); request = requestBuilder.buildRequest(lines); assertEquals("incorrect script", "myscript.agi", request.getScript()); assertEquals("incorrect requestURL", "agi://host/myscript.agi", request.getRequestURL()); assertEquals("incorrect channel", "SIP/1234-d715", request.getChannel()); assertEquals("incorrect uniqueId", "SIP/1234-d715", request.getChannel()); assertEquals("incorrect type", "SIP", request.getType()); assertEquals("incorrect uniqueId", "1110023416.6", request.getUniqueId()); assertEquals("incorrect language", "en", request.getLanguage()); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); assertEquals("incorrect dnid", "8870", request.getDnid()); assertEquals("incorrect rdnis", "unknown", request.getRdnis()); assertEquals("incorrect context", "local", request.getContext()); assertEquals("incorrect extension", "8870", request.getExtension()); assertEquals("incorrect priority", new Integer(1), request.getPriority()); assertEquals("incorrect enhanced", Boolean.FALSE, request.getEnhanced()); assertNull("incorrect accountCode must not be set", request.getAccountCode()); } public void testBuildRequestWithoutCallerIdName() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: 1234"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithoutCallerIdNameButBracket() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: <1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithoutCallerIdNameButBracketAndQuotesAndSpace() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"\" <1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithQuotedCallerIdName() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"John Doe\"<1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); } public void testBuildRequestWithQuotedCallerIdNameAndSpace() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: \"John Doe\" <1234>"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect callerId", "1234", request.getCallerId()); assertEquals("incorrect callerIdName", "John Doe", request.getCallerIdName()); } public void testBuildRequestWithoutCallerId() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("agi_callerid: "); request = requestBuilder.buildRequest(lines); assertNull("callerId must not be set", request.getCallerId()); assertNull("callerIdName must not be set", request.getCallerIdName()); } public void testBuildRequestWithNullEnvironment() { try { requestBuilder.buildRequest(null); fail("No IllegalArgumentException thrown."); } catch (IllegalArgumentException e) { } } public void testBuildRequestWithUnusualInput() { Collection lines; AGIRequest request; lines = new ArrayList(); lines.add("var without agi prefix: a value"); lines.add("agi_without_colon another value"); lines.add("agi_without_space_after_colon:"); lines.add("agi_channel: SIP/1234-a892"); request = requestBuilder.buildRequest(lines); assertEquals("incorrect channel", "SIP/1234-a892", request.getChannel()); } } Index: AGIReaderImplTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/AGIReaderImplTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIReaderImplTest.java 9 Mar 2005 23:33:04 -0000 1.1 +++ AGIReaderImplTest.java 10 Mar 2005 13:45:23 -0000 1.2 @@ -16,13 +16,12 @@ */ package net.sf.asterisk.fastagi; +import junit.framework.TestCase; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; import org.easymock.MockControl; -import junit.framework.TestCase; - public class AGIReaderImplTest extends TestCase { private AGIReader agiReader; @@ -37,6 +36,33 @@ public class AGIReaderImplTest extends T this.agiReader = new AGIReaderImpl(socket); } + public void testReadRequest() throws Exception + { + AGIRequest request; + + socket.readLine(); + socketMC.setReturnValue("agi_network: yes"); + socket.readLine(); + socketMC.setReturnValue("agi_network_script: myscript.agi"); + socket.readLine(); + socketMC.setReturnValue("agi_request: agi://host/myscript.agi"); + socket.readLine(); + socketMC.setReturnValue("agi_channel: SIP/1234-d715"); + socket.readLine(); + socketMC.setReturnValue(""); + + socketMC.replay(); + + request = agiReader.readRequest(); + + assertEquals("incorrect script", "myscript.agi", request.getScript()); + assertEquals("incorrect requestURL", "agi://host/myscript.agi", request + .getRequestURL()); + assertEquals("incorrect channel", "SIP/1234-d715", request.getChannel()); + + socketMC.verify(); + } + public void testReadReply() throws Exception { AGIReply reply; --- AGIRequestBuilderImplTest.java DELETED --- |
From: Stefan R. <sr...@us...> - 2005-03-10 13:45:38
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16225/src/java/net/sf/asterisk/fastagi Modified Files: AGIReader.java AGIReaderImpl.java Added Files: RequestBuilderImpl.java AGIConnectionHandler.java RequestBuilder.java Removed Files: AGIRequestBuilderImpl.java AGIRequestBuilder.java Log Message: --- NEW FILE: RequestBuilderImpl.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; 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: RequestBuilderImpl.java,v 1.1 2005/03/10 13:45:23 srt Exp $ */ public class RequestBuilderImpl implements RequestBuilder { /** * Creates a new AGIRequestBuilderImpl. */ public RequestBuilderImpl() { } public AGIRequest buildRequest(final Collection lines) { AGIRequestImpl request; Map map; if (lines == null) { throw new IllegalArgumentException("Environment must not be null."); } request = new AGIRequestImpl(); map = buildMap(lines); request.setScript((String) map.get("network_script")); request.setRequestURL((String) map.get("request")); request.setChannel((String) map.get("channel")); request.setUniqueId((String) map.get("uniqueid")); request.setType((String) map.get("type")); request.setLanguage((String) map.get("language")); if (map.get("callerid") != null) { String rawCallerId = (String) map.get("callerid"); request.setCallerId(getCallerId(rawCallerId)); request.setCallerIdName(getCallerIdName(rawCallerId)); } request.setDnid((String) map.get("dnid")); request.setRdnis((String) map.get("rdnis")); request.setContext((String) map.get("context")); request.setExtension((String) map.get("extension")); if (map.get("priority") != null) { request.setPriority(new Integer((String) map.get("priority"))); } if (map.get("enhanced") != null) { if ("1.0".equals((String) map.get("enhanced"))) { request.setEnhanced(Boolean.TRUE); } else { request.setEnhanced(Boolean.FALSE); } } request.setAccountCode((String) map.get("accountcode")); return request; } /** * Builds a map containing variable names as key (with the "agi_" prefix * stripped) and the corresponding values.<br> * Syntactically invalid and empty variables are skipped. * * @param lines the environment to transform. * @return a map with the variables set corresponding to the given * environment. */ private Map buildMap(final Collection lines) { Map map; Iterator lineIterator; map = new HashMap(); lineIterator = lines.iterator(); while (lineIterator.hasNext()) { String line; int colonPosition; String key; String value; line = (String) lineIterator.next(); colonPosition = line.indexOf(':'); // no colon on the line? if (colonPosition < 0) { continue; } // key doesn't start with agi_? if (!line.startsWith("agi_")) { continue; } // first colon in line is last character -> no value present? if (line.length() < colonPosition + 2) { continue; } key = line.substring(4, colonPosition).toLowerCase(); value = line.substring(colonPosition + 2); if (value.length() != 0) { map.put(key, value); } } return map; } private String getCallerId(final String rawCallerId) { int lbPosition; int rbPosition; lbPosition = rawCallerId.indexOf('<'); rbPosition = rawCallerId.indexOf('>'); if (lbPosition < 0 || rbPosition < 0) { return rawCallerId; } return rawCallerId.substring(lbPosition + 1, rbPosition); } private String getCallerIdName(final String rawCallerId) { int lbPosition; String callerIdName; lbPosition = rawCallerId.indexOf('<'); if (lbPosition < 0) { return null; } callerIdName = rawCallerId.substring(0, lbPosition).trim(); if (callerIdName.startsWith("\"") && callerIdName.endsWith("\"")) { callerIdName = callerIdName.substring(1, callerIdName.length() - 1); } if (callerIdName.length() == 0) { return null; } else { return callerIdName; } } } --- NEW FILE: AGIConnectionHandler.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.IOException; import net.sf.asterisk.io.SocketConnectionFacade; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * An AGIConnectionHandler is created and run by the AGIServer whenever a new * socket connection from an Asterisk Server is received.<br> * It reads the request using an AGIReader and runs the AGIScript configured to * handle this type of request. Finally it closes the socket connection. * * @author srt * @version $Id: AGIConnectionHandler.java,v 1.1 2005/03/10 13:45:23 srt Exp $ */ public class AGIConnectionHandler implements Runnable { private final Log logger = LogFactory.getLog(getClass()); private SocketConnectionFacade socket; private AGIReader reader; private AGIWriter writer; /** * Creates a new AGIConnectionHandler to handle the given socket connection. * @param socket the socket connection to handle. */ public AGIConnectionHandler(SocketConnectionFacade socket) { this.socket = socket; this.reader = new AGIReaderImpl(socket); this.writer = new AGIWriterImpl(socket); } public void run() { AGIRequest request; AGIResponse response; AGIScript script; try { request = reader.readRequest(); response = new AGIResponseImpl(writer, reader); //TODO find appropriate AGIScript //TODO run AGIScript //script.service(request, response); } catch (IOException e) { logger.error("IOException while handling request", e); } finally { try { socket.close(); } catch(IOException e) { } } } } --- NEW FILE: RequestBuilder.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: RequestBuilder.java,v 1.1 2005/03/10 13:45:23 srt Exp $ */ public interface RequestBuilder { /** * 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 buildRequest(Collection lines); } Index: AGIReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- AGIReader.java 9 Mar 2005 23:45:06 -0000 1.2 +++ AGIReader.java 10 Mar 2005 13:45:23 -0000 1.3 @@ -30,7 +30,15 @@ import net.sf.asterisk.fastagi.reply.AGI public interface AGIReader { /** - * Reads one reply from the network. + * Reads the initial request data from Asterisk. + * + * @return the request read. + * @throws IOException if the request can't be read. + */ + AGIRequest readRequest() throws IOException; + + /** + * Reads one reply to an AGICommand from Asterisk. * * @return the reply read. * @throws IOException if the reply can't be read. Index: AGIReaderImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIReaderImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIReaderImpl.java 9 Mar 2005 23:33:03 -0000 1.1 +++ AGIReaderImpl.java 10 Mar 2005 13:45:23 -0000 1.2 @@ -33,13 +33,38 @@ public class AGIReaderImpl implements AG { private SocketConnectionFacade socket; private ReplyBuilder replyBuilder; + private RequestBuilder requestBuilder; public AGIReaderImpl(SocketConnectionFacade socket) { this.socket = socket; this.replyBuilder = new ReplyBuilderImpl(); + this.requestBuilder = new RequestBuilderImpl(); } + public AGIRequest readRequest() throws IOException + { + AGIRequest request; + String line; + List lines; + + lines = new ArrayList(); + + while ((line = socket.readLine()) != null) + { + if (line.length() == 0) + { + break; + } + + lines.add(line); + } + + request = requestBuilder.buildRequest(lines); + + return request; + } + public AGIReply readReply() throws IOException { AGIReply reply; --- AGIRequestBuilderImpl.java DELETED --- --- AGIRequestBuilder.java DELETED --- |
From: Stefan R. <sr...@us...> - 2005-03-10 13:45:37
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16225/src/java/net/sf/asterisk/util Added Files: ThreadPool.java Log Message: --- NEW FILE: ThreadPool.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.util; import java.util.LinkedList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class ThreadPool { private final Log logger = LogFactory.getLog(getClass()); private boolean running; private int numThreads; private String name; private List jobs; /** * Creates a new ThreadPool of numThreads size. These Threads are waiting * for jobs to be added via the addJob method. * * @param name the name to use for the thread group and worker threads. * @param numThreads the number of threads to create. */ public ThreadPool(String name, int numThreads) { PoolThreadGroup group; this.name = name; this.numThreads = numThreads; jobs = new LinkedList(); running = true; group = new PoolThreadGroup(name); // create and start the threads for (int i = 0; i < numThreads; i++) { TaskThread thread; thread = new TaskThread(group, name + "-TaskThread-" + i); thread.start(); } logger.debug("ThreadPool created with " + numThreads + " threads."); } /** * Gets a job from the queue. If none is availble the calling thread is * blocked until one is added. * * @return the next job to service, <code>null</code> if the worker thread * should be shut down. */ Runnable obtainJob() { Runnable job = null; synchronized (jobs) { while (job == null && running) { try { if (jobs.size() == 0) { jobs.wait(); } } catch (InterruptedException ie) { } if (jobs.size() > 0) { job = (Runnable) jobs.get(0); jobs.remove(0); } } } if (running) { // Got a job from the queue return job; } else { // Shut down the pool return null; } } /** * Adds a new job to the queue. This will be picked up by the next available * active thread. */ public void addJob(Runnable runnable) { synchronized (jobs) { jobs.add(runnable); jobs.notifyAll(); } } /** * Turn off the pool. Every thread, when finished with its current work, * will realize that the pool is no longer running, and will exit. */ public void shutdown() { running = false; logger.debug("ThreadPool shutting down."); } /** * A TaskThread sits in a loop, asking the pool for a job, and servicing it. */ class TaskThread extends Thread { public TaskThread(ThreadGroup group, String name) { super(group, name); } /** * Get a job from the pool, run it, repeat. If the obtained job is null, * we exit the loop and the thread. */ public void run() { while (true) { Runnable job; job = obtainJob(); if (job == null) { // no more jobs available as ThreadPool has been closed? -> // end this Thread break; } job.run(); } } } /** * Provided the exception handler for all task threads. */ class PoolThreadGroup extends ThreadGroup { public PoolThreadGroup(String name) { super(name); } /** * Logs all exceptions that are not caught within the task threads. */ public void uncaughtException(Thread t, Throwable e) { logger.warn("Uncaught exception in Thread " + t.getName(), e); } } } |
From: Stefan R. <sr...@us...> - 2005-03-10 13:45:35
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16225/src/test/net/sf/asterisk/util Added Files: ThreadPoolTest.java Log Message: --- NEW FILE: ThreadPoolTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.util; import junit.framework.TestCase; public class ThreadPoolTest extends TestCase { private ThreadPool pool; private int sleepTime = 100; protected void setUp() throws Exception { super.setUp(); pool = new ThreadPool("test", 2); } protected void tearDown() { pool.shutdown(); } public void testAddJob() throws Exception { MyJob job1 = new MyJob(); MyJob job2 = new MyJob(); MyJob job3 = new MyJob(); pool.addJob(job1); pool.addJob(job2); pool.addJob(job3); // wait for all jobs to finish while (true) { if (job1.end != -1 && job2.end != -1 && job3.end != -1) { break; } Thread.sleep(sleepTime / 10); } assertTrue("Job3 started before Job 1 or Job 2 ended.", job3.start >= job1.end || job3.start >= job2.end); } public void testUncaughtException() throws Exception { Runnable job; job = new Runnable() { public void run() { throw new RuntimeException(); } }; pool.addJob(job); pool.addJob(job); Thread.sleep(50); } class MyJob implements Runnable { public long start = -1; public long end = -1; public void run() { start = System.currentTimeMillis(); try { Thread.sleep(sleepTime); } catch (InterruptedException e) { } end = System.currentTimeMillis(); } } } |
From: Stefan R. <sr...@us...> - 2005-03-10 13:45:14
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16151/src/java/net/sf/asterisk/util Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-10 13:45:13
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16151/src/test/net/sf/asterisk/util Log Message: Directory /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/util added to the repository |
From: Stefan R. <sr...@us...> - 2005-03-10 13:44:44
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16005/src/test/net/sf/asterisk/fastagi Added Files: DefaultAGIServerTest.java Log Message: Added DefaultAGIServer --- NEW FILE: DefaultAGIServerTest.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.IOException; import org.easymock.MockControl; import net.sf.asterisk.io.ServerSocketFacade; import net.sf.asterisk.io.SocketConnectionFacade; import junit.framework.TestCase; public class DefaultAGIServerTest extends TestCase { private DefaultAGIServer server; private MockControl serverSocketMC; private ServerSocketFacade serverSocket; protected void setUp() throws Exception { super.setUp(); serverSocketMC = MockControl.createControl(ServerSocketFacade.class); serverSocket = (ServerSocketFacade) serverSocketMC.getMock(); server = new MockedDefaultAGIServer(); } protected void tearDown() throws Exception { super.tearDown(); server.shutdown(); } public void testStartup() throws Exception { MockControl socketMC; SocketConnectionFacade socket; socketMC = MockControl.createControl(SocketConnectionFacade.class); socket = (SocketConnectionFacade) socketMC.getMock(); socket.readLine(); socketMC.setReturnValue(null); socket.close(); socketMC.replay(); serverSocket.accept(); serverSocketMC.setReturnValue(socket); serverSocket.accept(); serverSocketMC.setThrowable(new IOException()); serverSocket.close(); serverSocketMC.replay(); server.startup(); serverSocketMC.verify(); socketMC.verify(); } class MockedDefaultAGIServer extends DefaultAGIServer { protected ServerSocketFacade createServerSocket() { return serverSocket; } } } |
From: Stefan R. <sr...@us...> - 2005-03-10 13:44:44
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16005/src/java/net/sf/asterisk/fastagi Added Files: DefaultAGIServer.java Log Message: Added DefaultAGIServer --- NEW FILE: DefaultAGIServer.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.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import net.sf.asterisk.io.ServerSocketFacade; import net.sf.asterisk.io.ServerSocketFacadeImpl; import net.sf.asterisk.io.SocketConnectionFacade; import net.sf.asterisk.util.ThreadPool; public class DefaultAGIServer implements AGIServer { private static final int DEFAULT_PORT = 4573; private static final int DEFAULT_POOL_SIZE = 10; /** * Instance logger. */ private final Log logger = LogFactory.getLog(DefaultAGIServer.class); private ServerSocketFacade serverSocket; /** * The port to listen on. */ protected int port = DEFAULT_PORT; /** * The thread pool that contains the worker threads to process incoming * requests. */ private ThreadPool pool; /** * The number of worker threads in the thread pool. This equals the maximum * number of concurrent requests this AGIServer can serve. */ private int poolSize = DEFAULT_POOL_SIZE; private boolean die; public DefaultAGIServer() { this.pool = new ThreadPool("AGIServer", poolSize); } protected ServerSocketFacade createServerSocket() throws IOException { return new ServerSocketFacadeImpl(port); } public void startup() throws IOException, IllegalStateException { run(); } public void run() { SocketConnectionFacade socket; AGIConnectionHandler connectionHandler; die = false; try { serverSocket = createServerSocket(); logger.info("Waiting for new connections."); while ((socket = serverSocket.accept()) != null) { logger.info("Received connection."); connectionHandler = new AGIConnectionHandler(socket); pool.addJob(connectionHandler); } } catch (IOException e) { // swallow if shutdown if (die) { logger.error("IOException while waiting for connections.", e); } } finally { try { serverSocket.close(); } catch (IOException e) { // swallow } serverSocket = null; } } public void die() throws IOException { die = true; if (serverSocket != null) { serverSocket.close(); } logger.info("AGIServer shut down."); } public void shutdown() throws IOException, IllegalStateException { pool.shutdown(); die(); } } |
From: Stefan R. <sr...@us...> - 2005-03-10 07:35:18
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1721/src/test/net/sf/asterisk/fastagi Added Files: AGIResponseImplTest.java Log Message: Added AGIResponseImpl --- NEW FILE: AGIResponseImplTest.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 net.sf.asterisk.fastagi.command.NoopCommand; import net.sf.asterisk.fastagi.reply.AGIReply; import org.easymock.MockControl; import junit.framework.TestCase; public class AGIResponseImplTest extends TestCase { private MockControl agiWriterMC; private AGIWriter agiWriter; private MockControl agiReaderMC; private AGIReader agiReader; private AGIResponse agiResponse; protected void setUp() throws Exception { super.setUp(); this.agiWriterMC = MockControl.createControl(AGIWriter.class); this.agiWriter = (AGIWriter) agiWriterMC.getMock(); this.agiReaderMC = MockControl.createControl(AGIReader.class); this.agiReader = (AGIReader) agiReaderMC.getMock(); this.agiResponse = new AGIResponseImpl(agiWriter, agiReader); } public void testSendCommand() throws Exception { AGIReply reply; NoopCommand command; reply = new AGIReply(); reply.setStatus(AGIReply.SC_SUCCESS); reply.setResult(0); command = new NoopCommand(); agiWriter.sendCommand(command); agiReader.readReply(); agiReaderMC.setReturnValue(reply); agiWriterMC.replay(); agiReaderMC.replay(); assertEquals(reply, agiResponse.sendCommand(command)); agiWriterMC.verify(); agiReaderMC.verify(); } } |
From: Stefan R. <sr...@us...> - 2005-03-10 07:35:17
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1721/src/java/net/sf/asterisk/fastagi Added Files: AGIResponseImpl.java Log Message: Added AGIResponseImpl --- NEW FILE: AGIResponseImpl.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.IOException; import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; /** * Default implementation of the AGIResponse interface. * * @author srt * @version $Id: AGIResponseImpl.java,v 1.1 2005/03/10 07:35:07 srt Exp $ */ public class AGIResponseImpl implements AGIResponse { private AGIWriter agiWriter; private AGIReader agiReader; private SocketConnectionFacade socket; public AGIResponseImpl(SocketConnectionFacade socket) { this.socket = socket; this.agiWriter = new AGIWriterImpl(socket); this.agiReader = new AGIReaderImpl(socket); } public AGIResponseImpl(AGIWriter agiWriter, AGIReader agiReader) { this.agiWriter = agiWriter; this.agiReader = agiReader; } public synchronized AGIReply sendCommand(AGICommand command) throws IOException { AGIReply reply; agiWriter.sendCommand(command); reply = agiReader.readReply(); return reply; } } |
From: Stefan R. <sr...@us...> - 2005-03-09 23:52:59
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22613/src/test/net/sf/asterisk/fastagi Added Files: AGIWriterImplTest.java Log Message: Added AGIWriter --- NEW FILE: AGIWriterImplTest.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; import net.sf.asterisk.fastagi.command.StreamFileCommand; import net.sf.asterisk.io.SocketConnectionFacade; import org.easymock.MockControl; import junit.framework.TestCase; public class AGIWriterImplTest extends TestCase { private AGIWriter agiWriter; private MockControl socketMC; private SocketConnectionFacade socket; protected void setUp() throws Exception { super.setUp(); this.socketMC = MockControl.createControl(SocketConnectionFacade.class); this.socket = (SocketConnectionFacade) socketMC.getMock(); this.agiWriter = new AGIWriterImpl(socket); } public void testSendCommand() throws Exception { StreamFileCommand command; command = new StreamFileCommand("welcome"); socket.write("STREAM FILE \"welcome\" \"\"\n"); socket.flush(); socketMC.replay(); agiWriter.sendCommand(command); socketMC.verify(); } } |
From: Stefan R. <sr...@us...> - 2005-03-09 23:52:57
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22613/src/java/net/sf/asterisk/fastagi Added Files: AGIWriter.java AGIWriterImpl.java Log Message: Added AGIWriter --- NEW FILE: AGIWriter.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.IOException; import net.sf.asterisk.fastagi.command.AGICommand; /** * The AGIWriter sends commands to Asterisk. * * @author srt * @version $Id: AGIWriter.java,v 1.1 2005/03/09 23:52:48 srt Exp $ */ public interface AGIWriter { /** * Sends the given command to the Asterisk server. * * @param command the command to send. * @throws IOException if the command can't be sent. */ void sendCommand(AGICommand command) throws IOException; } --- NEW FILE: AGIWriterImpl.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; import java.io.IOException; import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.io.SocketConnectionFacade; /** * Default implementation of the AGIWriter interface. * * @author srt * @version $Id: AGIWriterImpl.java,v 1.1 2005/03/09 23:52:48 srt Exp $ */ public class AGIWriterImpl implements AGIWriter { private SocketConnectionFacade socket; public AGIWriterImpl(SocketConnectionFacade socket) { this.socket = socket; } public void sendCommand(AGICommand command) throws IOException { socket.write(command.buildCommand() + "\n"); socket.flush(); } } |
From: Stefan R. <sr...@us...> - 2005-03-09 23:45:34
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20740/src/java/net/sf/asterisk/fastagi/reply Modified Files: AGIReply.java Log Message: Fixed formatting Index: AGIReply.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply/AGIReply.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- AGIReply.java 9 Mar 2005 23:42:09 -0000 1.7 +++ AGIReply.java 9 Mar 2005 23:45:23 -0000 1.8 @@ -103,13 +103,14 @@ public class AGIReply implements Seriali /** * Returns the return code as character. + * * @return the return code as character. */ public char getResultAsChar() { return (char) result; } - + /** * Returns the status code.<br> * Supported status codes are: |
From: Stefan R. <sr...@us...> - 2005-03-09 23:45:15
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20682/src/java/net/sf/asterisk/fastagi Modified Files: AGIReader.java Log Message: Fixed javadoc for IOException thrown by readReply() Index: AGIReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIReader.java 9 Mar 2005 23:33:03 -0000 1.1 +++ AGIReader.java 9 Mar 2005 23:45:06 -0000 1.2 @@ -33,7 +33,7 @@ public interface AGIReader * Reads one reply from the network. * * @return the reply read. - * @throws IOException if the reply can be read. + * @throws IOException if the reply can't be read. */ AGIReply readReply() throws IOException; } |
From: Stefan R. <sr...@us...> - 2005-03-09 23:42:23
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20105/src/java/net/sf/asterisk/fastagi/reply Modified Files: AGIReply.java Log Message: Added getResultAsChar() to AGIReply Index: AGIReply.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply/AGIReply.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- AGIReply.java 9 Mar 2005 23:29:46 -0000 1.6 +++ AGIReply.java 9 Mar 2005 23:42:09 -0000 1.7 @@ -102,6 +102,15 @@ public class AGIReply implements Seriali } /** + * Returns the return code as character. + * @return the return code as character. + */ + public char getResultAsChar() + { + return (char) result; + } + + /** * Returns the status code.<br> * Supported status codes are: * <ul> |
From: Stefan R. <sr...@us...> - 2005-03-09 23:42:23
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20105/src/test/net/sf/asterisk/fastagi Modified Files: ReplyBuilderImplTest.java Log Message: Added getResultAsChar() to AGIReply Index: ReplyBuilderImplTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/fastagi/ReplyBuilderImplTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- ReplyBuilderImplTest.java 9 Mar 2005 20:31:36 -0000 1.1 +++ ReplyBuilderImplTest.java 9 Mar 2005 23:42:09 -0000 1.2 @@ -44,6 +44,7 @@ public class ReplyBuilderImplTest extend assertEquals("Incorrect status", AGIReply.SC_SUCCESS, reply.getStatus()); assertEquals("Incorrect result", 49, reply.getResult()); + assertEquals("Incorrect result as character", '1', reply.getResultAsChar()); } public void testBuildReplyInvalidOrUnknownCommand() |
From: Stefan R. <sr...@us...> - 2005-03-09 23:33:15
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17393/src/java/net/sf/asterisk/fastagi Added Files: AGIReader.java AGIReaderImpl.java Log Message: Added AGIReader --- NEW FILE: AGIReader.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.IOException; import net.sf.asterisk.fastagi.reply.AGIReply; /** * The AGIReader reads the replies from the network and parses them using a * ReplyBuilder. * * @author srt * @version $Id: AGIReader.java,v 1.1 2005/03/09 23:33:03 srt Exp $ */ public interface AGIReader { /** * Reads one reply from the network. * * @return the reply read. * @throws IOException if the reply can be read. */ AGIReply readReply() throws IOException; } --- NEW FILE: AGIReaderImpl.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; import java.io.IOException; import java.util.ArrayList; import java.util.List; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; /** * Default implementation of the AGIReader implementation. * * @author srt * @version $Id: AGIReaderImpl.java,v 1.1 2005/03/09 23:33:03 srt Exp $ */ public class AGIReaderImpl implements AGIReader { private SocketConnectionFacade socket; private ReplyBuilder replyBuilder; public AGIReaderImpl(SocketConnectionFacade socket) { this.socket = socket; this.replyBuilder = new ReplyBuilderImpl(); } public AGIReply readReply() throws IOException { AGIReply reply; List lines; String line; lines = new ArrayList(); line = socket.readLine(); lines.add(line); // read synopsis and usage if statuscode is 520 if (line.startsWith(Integer .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) { while ((line = socket.readLine()) != null) { lines.add(line); if (line.startsWith(Integer .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) { break; } } } reply = replyBuilder.buildReply(lines); return reply; } } |