Re: [Asterisk-java-users] Asterisk java with tomcat
Brought to you by:
srt
From: Maciek T. <mlo...@gm...> - 2008-03-27 14:00:27
|
Hi, Let's say that you want to originate some call to somebody by clicking button on HTML site. PHP script will look something like that ----PHP CODE filename: clickToCall.php <?php if (!isset($_POST['call']) or $_POST['call']=='') { //display form to user ?> <form action="clickToCall.php" method="POST"> <input type="text" name="destination" value="enter destination number here...."> <input type="submit" value="call" name="call"> </form> <?php } else { //call web service using curl $destination=$_POST['destination']; $ch = curl_init(); $url="http://your.tomcat.host/serletname?dest=$destination"; //you can also use fopen or file_get_contents functions curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); $data = curl_exec($ch); if ($data='OK') { echo "Ok... call is no the way"; } else { echo "Some problems...:-("; } } ?> ---end of PHP code I thin it won't work if You use Ctrl-C Ctrl-V, but it may looks like thise above Next you have to write a web service servlet that will handle request from php script: ----JAVA CODE package clickToCall; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import org.asteriskjava.manager.AuthenticationFailedException; import org.asteriskjava.manager.ManagerConnection; import org.asteriskjava.manager.ManagerConnectionFactory; import org.asteriskjava.manager.TimeoutException; import org.asteriskjava.manager.action.OriginateAction; import org.asteriskjava.manager.response.ManagerResponse; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String destinationNo=request.getParameter("dest"); //pasted from http://asterisk-java.org/development/tutorial.html :-) try { ManagerConnectionFactory factory = new ManagerConnectionFactory( "localhost", "manager", "pa55w0rd"); // this.managerConnection = factory.createManagerConnection(); OriginateAction originateAction; ManagerResponse originateResponse; originateAction = new OriginateAction(); originateAction.setChannel("SIP/YOUR_TRUNK_NAME/"+destination); originateAction.setContext("default"); originateAction.setExten("1300"); 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); // and finally log off and disconnect managerConnection.logoff(); out.println("OK"); } catch (Exception e) { out.println("NOT OK"); } } } ---End of JAVA code It also won't work after pasting it. Remember to put your Trunk name context etc. when setting up originate action. Of course you have to set up your Tomcat with this servlet. Php script can be simply putted into /varr/www folder of your server Regards, Maciek 2008/3/27, Gopal krishnan <sa...@gm...>: > > Hi, > > Thanks for the reply, can I have any help or hello world example to set > this. It would be a great help for me. Thanks > > On Thu, Mar 27, 2008 at 2:51 PM, Maciek Tokarski <mlo...@gm...> > wrote: > > > HI, > > Yes- it is possible. Once, I've developed Tomcat servlet (simple > > WebService) on Asterisk box to monitor users count on MeetMe rooms. It works > > fine. In my opinion best way of integrating manager API with HTML sites is > > interract with Asterisk not exacly via Tomcat servlet but via WebServices > > servlets (on Tomcat) calling it form eg. PHP scripts using CURL. > > > > Your SITE<------CURL/SOAP------>Tomcat WS servlet<--AMI--->Asterisk Box > > > > > > Regards, Maciek > > > > 2008/3/27, Gopal krishnan <sa...@gm...>: > > > > > > Hi, > > > > > > Is it possible I can use a manager api program with tomcat. If so > > > how should i integrate that, please assist me. > > > > > > I would like to initate a action from a html page so that it will > > > hit a program developed with manager api. > > > > > > -- > > > Thank you with regards, > > > Gopal, > > > PeopleTech Systems Private Limited > > > www.peopletech.co.in > > > > > > ------------------------------------------------------------------------- > > > Check out the new SourceForge.net Marketplace. > > > It's the best place to buy or sell services for > > > just about anything Open Source. > > > > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > > _______________________________________________ > > > Asterisk-java-users mailing list > > > Ast...@li... > > > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > > > > > > > > > > > > > > > ------------------------------------------------------------------------- > > Check out the new SourceForge.net Marketplace. > > It's the best place to buy or sell services for > > just about anything Open Source. > > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > _______________________________________________ > > Asterisk-java-users mailing list > > Ast...@li... > > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > > > > > > -- > Thank you with regards, > Gopal, > PeopleTech Systems Private Limited > www.peopletech.co.in > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > -- Pozdrawiam Maciek Tokarski |