如何使用带有Java的Asterisk AMI在AsteriskNow中进行出站调用

时间:2014-02-06 12:14:34

标签: java asterisk asteriskami

我想在LAN网络中发起从分机号码到另一个号码的呼叫。我通过FreePBX GUI完成了这项任务。现在我尝试使用带有Java代码的Asterisk AMI来执行此任务。 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( 
"192.168.68.173", "admin", "admin"); 

this.managerConnection = factory.createManagerConnection(); 
} 

public void run() throws IOException, AuthenticationFailedException, 
TimeoutException 
{ 
OriginateAction originateAction; 
ManagerResponse originateResponse; 

originateAction = new OriginateAction(); 
originateAction.setChannel("SIP/1010"); 
originateAction.setContext("default"); 
originateAction.setExten("2020"); 
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("Enter Response="+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(); 
} 
} 

例外:

run: 
Feb 06, 2014 4:04:16 PM org.asteriskjava.manager.internal.ManagerConnectionImpl connect 
INFO: Connecting to 192.168.68.173:5038 
Feb 06, 2014 4:04:17 PM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier 
INFO: Connected via Asterisk Call Manager/1.3 
Feb 06, 2014 4:04:17 PM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier 
WARNING: Unsupported protocol version 'Asterisk Call Manager/1.3'. Use at your own risk. 
Feb 06, 2014 4:04:18 PM org.asteriskjava.manager.internal.ManagerConnectionImpl disconnect 
INFO: Closing socket. 
Feb 06, 2014 4:04:18 PM org.asteriskjava.manager.internal.ManagerReaderImpl run 
INFO: Terminating reader thread: No more lines available: null 
Exception in thread "main" org.asteriskjava.manager.AuthenticationFailedException: Authentication failed 
at org.asteriskjava.manager.internal.ManagerConnectionImpl.doLogin(ManagerConnectionImpl.java:578) 
at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(ManagerConnectionImpl.java:438)
at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(ManagerConnectionImpl.java:423)
at org.asteriskjava.manager.DefaultManagerConnection.login(DefaultManagerConnection.java:294)
at asteriskjtapi.HelloManager.run(HelloManager.java:49) 
at asteriskjtapi.HelloManager.main(HelloManager.java:67) 

注意: 在这里,我使用FreePBX中的凭据。这是正确的访问ConnectionManager吗?

2 个答案:

答案 0 :(得分:1)

请在执行java程序时粘贴星号日志

获取星号日志

 tail -f /var/log/asterisk/full

要从命令行检查相同内容,请尝试使用

 telnet 192.168.68.173  5038
 Action: Login
 Username: admin
 Secret: admin

如果登录成功

 Action: Originate
 Channel: SIP/1010
 Exten: 2020
 Context: default
 Priority: 1
 Callerid: 1010
 Async: yes

试试这个,让我知道你的输出

答案 1 :(得分:0)

  1. 首先,您必须尝试通过telnet连接星号。
  2. 如果您收到“登录成功”消息,则可以继续编程。否则,如果您收到“身份验证失败”消息,请将您的IP添加到permit中的manager.conf设置。然后保存更改。

    permit:[your static ip]

  3. 再次尝试使用telnet