Hello Experts! Would like to ask if you have some sample code implementing Astrisk using Java and AsteriskJava. I successfully installed the Asterisk, however, I would like to create a simple Java application that can call extensions. Thanks
up
up what? i just sent you the link to all the asterisk-java tutorials… what more are you looking for?
Perhaps scrolling down the page was a lot of effort… here is an excerpt for a call origination:
[code]
import java.io.IOException;
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 HelloManager
{
private ManagerConnection managerConnection;
public HelloManager() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"localhost", "manager", "pa55w0rd");
this.managerConnection = factory.createManagerConnection();
}
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(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();
}
}[/code]
I tested the HelloManger application. It is working fine however with the use of a X-Lite Phone. Asterisk will call the X-Lite and when I answer the call it will call the extension I provided on the code. Do you know how can I bind the Java application to the AsteriskServer so that i can run the HelloManager witout the use of X-Lite? Thanks