Asterisk auto-dial out with Java (asterisk-java)

# configure manager
/etc/asterisk/manager.conf
[general]
enabled = yes
port = 5038
bindaddr = 0.0.0.0 
 
[manager]
secret=pa55w0rd
permit=0.0.0.0/0.0.0.0
read=system,call,log,verbose,agent,command,user
write=system,call,log,verbose,agent,command,user
 
# create extension
/etc/asterisk/extensions.conf
[directdial]
exten => 1,1,Dial(CAPI/ISDN1/${customernum}/b)
 
# reload asterisk
/etc/init.d/asterisk restart
 
# download java class
wget http://maven.reucon.com/public-snapshot/org/asteriskjava/asterisk-java/1.0.0-SNAPSHOT/asterisk-java-1.0.0-20090303.204542-422.jar
 
# HelloManager.java
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("asterisk", "manager", "pa55w0rd");
 
        this.managerConnection = factory.createManagerConnection();
    }
 
    public void call(final String user, final String phoneNumber) throws IOException, AuthenticationFailedException, TimeoutException {
        OriginateAction originateAction;
        ManagerResponse originateResponse;
 
        originateAction = new OriginateAction();
        originateAction.setChannel("SIP/" + user);
        originateAction.setContext("directdial");
        originateAction.setExten("1");
        originateAction.setPriority(new Integer(1));
        originateAction.setTimeout(new Integer(30000));
        originateAction.setVariable("customernum", phoneNumber);
 
        // 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();
    }
 
    public static void main(String[] args) throws Exception {
        HelloManager helloManager = new HelloManager();
        helloManager.call("555-SHOE", "panticz");
    }
}
 
# Links
http://asterisk-java.org/0.2/tutorial.html
http://asterisk-java.org/development/tutorial.html
http://www.voip-info.org/tiki-index.php?page=Asterisk+auto-dial+out
http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Originate