Asterisk manager Example: Java

Asterisk Manager Example: Java


Java library


The Asterisk-java package (available unter Apache License from http://asterisk-java.org/) consists of a set of Java classes that allow you to use the Manager API Java applications.

It supports receiving events from the Asterisk server (e.g. call progess, registered peers, channel state) and sending actions to Asterisk (e.g. originate call, agent login/logoff, start/stop voice recording).

Example:

public class TestDefaultManagerConnection extends TestCase
{
private DefaultManagerConnection getDefaultManagerConnection()
{
DefaultManagerConnection dmc;

dmc = new DefaultManagerConnection();
dmc.setUsername("username");
dmc.setPassword("password");
dmc.setHostname("localhost");

return dmc;
}

public void testLogin() throws Exception
{
DefaultManagerConnection dmc;

dmc = getDefaultManagerConnection();
dmc.login();
dmc.addEventHandler(new ManagerEventHandler()
{
public void handleEvent(ManagerEvent event)
{
System.out.println(event);
}
});
dmc.sendAction(new StatusAction());

// wait for 3 seconds to receive events
Thread.sleep(3000);
dmc.logoff();
}
}



Back

Asterisk Manager Example: Java


Java library


The Asterisk-java package (available unter Apache License from http://asterisk-java.org/) consists of a set of Java classes that allow you to use the Manager API Java applications.

It supports receiving events from the Asterisk server (e.g. call progess, registered peers, channel state) and sending actions to Asterisk (e.g. originate call, agent login/logoff, start/stop voice recording).

Example:

public class TestDefaultManagerConnection extends TestCase
{
private DefaultManagerConnection getDefaultManagerConnection()
{
DefaultManagerConnection dmc;

dmc = new DefaultManagerConnection();
dmc.setUsername("username");
dmc.setPassword("password");
dmc.setHostname("localhost");

return dmc;
}

public void testLogin() throws Exception
{
DefaultManagerConnection dmc;

dmc = getDefaultManagerConnection();
dmc.login();
dmc.addEventHandler(new ManagerEventHandler()
{
public void handleEvent(ManagerEvent event)
{
System.out.println(event);
}
});
dmc.sendAction(new StatusAction());

// wait for 3 seconds to receive events
Thread.sleep(3000);
dmc.logoff();
}
}



Back

Created by: flobi, Last modification: Sun 16 of Jul, 2006 (12:25 UTC) by srt
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+