Search in sources :

Example 1 with StatusAction

use of org.asteriskjava.manager.action.StatusAction in project openhab1-addons by openhab.

the class AsteriskBinding method connect.

/**
     * Connects to <code>host</code> and opens a ManagerConnection by using the
     * given <code>username</code> and <code>password</code>. Note: The Asterisk
     * ManagerInterface on your Asterisk PBX is deactivated by default. Please
     * refer to the documentation how to activate the ManagerInterface (AMI).
     * 
     * @param host where to find the Asterisk PBX
     * @param username username to login to Asterisk ManagerInterface
     * @param password password to login to Asterisk ManagerInterface
     */
private void connect(String host, String username, String password) {
    ManagerConnectionFactory factory = new ManagerConnectionFactory(host, username, password);
    AsteriskBinding.managerConnection = factory.createManagerConnection();
    AsteriskBinding.managerConnection.addEventListener(new AsteriskEventManager());
    try {
        AsteriskBinding.managerConnection.login();
    } catch (AuthenticationFailedException afe) {
        logger.error("Authentication failed.  Please verify username and password.");
    } catch (IOException ioe) {
        logger.error("Could not connect to manager interface on host {}: {}", host, ioe);
    } catch (Exception e) {
        logger.error("Login to Asterisk manager interface on host {} threw an exception: {}", host, e);
    }
    try {
        AsteriskBinding.managerConnection.sendAction(new StatusAction());
    } catch (Exception e) {
        logger.error("Registering for status update threw an exception: {}", e);
    }
}
Also used : StatusAction(org.asteriskjava.manager.action.StatusAction) AuthenticationFailedException(org.asteriskjava.manager.AuthenticationFailedException) ManagerConnectionFactory(org.asteriskjava.manager.ManagerConnectionFactory) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) AuthenticationFailedException(org.asteriskjava.manager.AuthenticationFailedException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 AuthenticationFailedException (org.asteriskjava.manager.AuthenticationFailedException)1 ManagerConnectionFactory (org.asteriskjava.manager.ManagerConnectionFactory)1 StatusAction (org.asteriskjava.manager.action.StatusAction)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1