[Asterisk-java-cvs] CVS: samples/src/java HelloAGIScript.java,NONE,1.1 fastagi.properties,NONE,1.1 f
Brought to you by:
srt
Update of /cvsroot/asterisk-java/samples/src/java In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24217/src/java Added Files: HelloAGIScript.java fastagi.properties fastagi-mapping.properties HelloEvents.java TestFastAGI.java HelloManager.java .cvsignore Log Message: - Initial import --- NEW FILE: HelloAGIScript.java --- import net.sf.asterisk.fastagi.AGIChannel; import net.sf.asterisk.fastagi.AGIException; import net.sf.asterisk.fastagi.AGIRequest; import net.sf.asterisk.fastagi.AbstractAGIScript; public class HelloAGIScript extends AbstractAGIScript { public void service(AGIRequest request, AGIChannel channel) throws AGIException { // Answer the channel... answer(channel); // ...say hello... streamFile(channel, "welcome"); // ...and hangup. hangup(channel); } } --- NEW FILE: fastagi.properties --- poolSize = 1 --- NEW FILE: fastagi-mapping.properties --- hello.agi = HelloAGIScript test.agi = TestFastAGI --- NEW FILE: HelloEvents.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. * */ import java.io.IOException; import net.sf.asterisk.manager.AuthenticationFailedException; import net.sf.asterisk.manager.ManagerConnection; import net.sf.asterisk.manager.ManagerConnectionFactory; import net.sf.asterisk.manager.ManagerEventHandler; import net.sf.asterisk.manager.TimeoutException; import net.sf.asterisk.manager.action.StatusAction; import net.sf.asterisk.manager.event.ManagerEvent; public class HelloEvents implements ManagerEventHandler { private ManagerConnection managerConnection; public HelloEvents() throws IOException { ManagerConnectionFactory factory = new ManagerConnectionFactory(); this.managerConnection = factory.getManagerConnection("localhost", "manager", "pa55w0rd"); } public void run() throws IOException, AuthenticationFailedException, TimeoutException, InterruptedException { // register for events managerConnection.addEventHandler(this); // connect to Asterisk and log in managerConnection.login(); // request channel state managerConnection.sendAction(new StatusAction()); // wait 10 seconds for events to come in Thread.sleep(10000); // and finally log off and disconnect managerConnection.logoff(); } public void handleEvent(ManagerEvent event) { // just print received events System.out.println(event); } public static void main(String[] args) throws Exception { HelloEvents helloEvents; helloEvents = new HelloEvents(); helloEvents.run(); } } --- NEW FILE: TestFastAGI.java --- import java.util.*; import net.sf.asterisk.fastagi.*; import net.sf.asterisk.fastagi.command.*; import net.sf.asterisk.fastagi.reply.*; /** * This class is a port of the fastagi-test perl script distributed with * Asterisk to demonstrate the FastAGI.<br> * It was kindly donated by Steve Drach. * * @author drach */ public class TestFastAGI extends AbstractAGIScript { private int tests, pass, fail; private int s, p; private void print(String s) { System.err.print(s); } private void checkResult(AGIReply reply) { tests++; if (reply.getStatus() == 200) { if (reply.getResult() == null) { print("FAIL (" + reply.getFirstLine() + ")\n"); fail++; } else { print("PASS (" + reply.getResult() + ")\n"); pass++; } } else { print("FAIL (unexpected result '" + reply.getFirstLine() + "')\n"); fail++; } } public void service(AGIRequest request, AGIChannel channel) throws AGIException { Map values; Iterator i; SortedSet keys = new TreeSet(); keys.addAll((values = request.getRequest()).keySet()); print("AGI Environment Dump from --\n"); i = keys.iterator(); while (i.hasNext()) { String key; key = (String) i.next(); print(" -- " + key + " = " + (String) values.get(key) + "\n"); } print("1. Testing 'sendfile'..."); checkResult(channel.sendCommand(new StreamFileCommand("beep"))); print("2. Testing 'sendtext'..."); checkResult(channel.sendCommand(new SendTextCommand("hello world"))); print("3. Testing 'sendimage'..."); checkResult(channel.sendCommand(new SendImageCommand("asterisk-image"))); print("4. Testing 'saynumber'..."); checkResult(channel.sendCommand(new SayNumberCommand("192837465"))); print("5. Testing 'waitdtmf'..."); checkResult(channel.sendCommand(new WaitForDigitCommand(1000))); print("6. Testing 'record'..."); checkResult(channel.sendCommand(new RecordFileCommand("testagi", "gsm", "1234", 3000))); print("6a. Testing 'record' playback..."); checkResult(channel.sendCommand(new StreamFileCommand("testagi"))); print("================== Complete ======================\n"); print(tests + " tests completed, " + pass + " passed, " + fail + " failed\n"); print("==================================================\n"); } } --- NEW FILE: HelloManager.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. * */ import java.io.IOException; import net.sf.asterisk.manager.AuthenticationFailedException; import net.sf.asterisk.manager.ManagerConnection; import net.sf.asterisk.manager.ManagerConnectionFactory; import net.sf.asterisk.manager.TimeoutException; import net.sf.asterisk.manager.action.OriginateAction; import net.sf.asterisk.manager.response.ManagerResponse; public class HelloManager { private ManagerConnection managerConnection; public HelloManager() throws IOException { ManagerConnectionFactory factory = new ManagerConnectionFactory(); this.managerConnection = factory.getManagerConnection("localhost", "manager", "pa55w0rd"); } public void run() throws IOException, AuthenticationFailedException, TimeoutException { OriginateAction originateAction; ManagerResponse originateResponse; originateAction = new OriginateAction(); originateAction.setChannel("Local/1310"); originateAction.setContext("default"); originateAction.setExten("1330"); originateAction.setPriority(new Integer(1)); originateAction.setTimeout(new Integer(30000)); // connect to Asterisk and log in managerConnection.login(); // send the originate action and wait for a maximum of 30 seconds for // Asterisk // to send a reply originateResponse = managerConnection.sendAction(originateAction, 30000); // print out whether the originate succeeded or not System.out.println(originateResponse.getResponse()); // and finally log off and disconnect managerConnection.logoff(); } public static void main(String[] args) throws Exception { HelloManager helloManager; helloManager = new HelloManager(); helloManager.run(); } } --- NEW FILE: .cvsignore --- *.jar *.class |