Update of /cvsroot/asterisk-java/asterisk-java/xdocs
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4509/xdocs
Modified Files:
tutorial.xml
Log Message:
Added HelloManager example with OriginateAction
Index: tutorial.xml
===================================================================
RCS file: /cvsroot/asterisk-java/asterisk-java/xdocs/tutorial.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -p -r1.3 -r1.4
--- tutorial.xml 14 Mar 2005 16:28:16 -0000 1.3
+++ tutorial.xml 14 Mar 2005 18:44:00 -0000 1.4
@@ -204,7 +204,75 @@ write=system,call,log,verbose,agent,comm
<p>This will enable the Manager AP, allow access from any IP address using the
username "manager" and the password "pa55w0rd".</p>
<subsection name="Hello Manager!">
- <p>to be done.</p>
+ <p>Assume we have a phone connected via SIP that is available at SIP/john and
+ we want to initiate a call from that phone to extension 1300 in the default
+ context.</p>
+ <p>We have to obtain a
+ <a href="apidocs/net/sf/asterisk/manager/ManagerConnection.html">ManagerConnection</a>
+ providing the hostname Asterisk is running on and the username and password
+ as configured in <code>manager.conf</code>. Next we log in and send an
+ <a href="apidocs/net/sf/asterisk/manager/action/OriginateCallAction.html">OriginateCallAction</a>
+ and finally we disconnect.</p>
+ <p>An example that does this is shown below.</p>
+<source><![CDATA[
+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("SIP/John");
+ originateAction.setContext("default");
+ originateAction.setExten("1300");
+ originateAction.setPriority(new Integer(1));
+ originateAction.setTimeout(new Integer(3000));
+
+ // 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, 3000);
+
+ // 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();
+ }
+}
+]]></source>
+ <p></p>
</subsection>
</section>
</body>
|