1

要从星号进行出站呼叫,我正在尝试使用星号-java 库。我收到 Connection Refused 异常(接近问题的结尾)。

try {
    factory = new ManagerConnectionFactory("127.0.0.1", "loginFromManagerConf", "passwordFromManagerConf");
    outgoingCallManager = factory.createManagerConnection();
    outgoingCallManager.login();
    originateAction = new OriginateAction();
    originateAction.setChannel("Dongle/dongle0/+91XXXXXXXXXX");
    originateAction.setContext("dongle-outgoing");
    // originateAction.setExten("1300");
    originateAction.setPriority(new Integer(1));
    originateAction.setTimeout(new Integer(30000));
} catch (IllegalStateException e) {
    e.printStackTrace();
    System.out.println("Unable to connect to Asterisk");
    System.exit(0);
} catch (IOException e) {
    e.printStackTrace();
    System.out.println("Unable to connect to Asterisk");
    System.exit(0);
} catch (AuthenticationFailedException e) {
    e.printStackTrace();
    System.out.println("Unable to connect to Asterisk");
    System.exit(0);
} catch (TimeoutException e) {
    e.printStackTrace();
    System.out.println("Unable to connect to Asterisk");
    System.exit(0);
}

在 junit 测试用例中调用上述内容,eclipse 没有以 root 身份运行。

我已经在 Ubuntu 12.04 上安装了 AsteriskNOW。来电和短信正在工作。chan-dongle 不支持传入呼叫的​​ DTMF,但这是一个单独的问题。基本上传入的工作很好。

加密狗配置文件

context=dongle-incoming

管理器配置文件

[loginFromManagerConf]
secret = passwordFromManagerConf 
read=system,call,log,verbose,agent,command,user
write=system,call,log,verbose,agent,command,user

Extensions.conf

[dongle-outgoing]
exten => s,1,Playback(digits/2)
exten => s,n,Hangup()

[dongle-incoming]
exten => sms,1,Verbose(Incoming SMS from ${CALLERID(num)} ${SMS})
exten => sms,n,System(java -classpath mypath -jar myjarfile ${CALLERID(num)} ${SMS})

exten => sms,n,Hangup()

exten => ussd,1,Verbose(Incoming USSD: ${USSD})
exten => ussd,n,System(echo '${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLE}: ${USSD}' >> /var/log/asterisk/ussd.txt)
exten => ussd,n,Hangup()

exten => s,1,Answer()
exten => s,2,WaitExten()
exten => 123,1,Playback(digits/2)
exten => 234,1,Playback(digits/3)
exten => 345,1,Playback(digits/4)
exten => s,n,Goto(1)

例外

java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
    at java.net.Socket.connect(Socket.java:546)
    at org.asteriskjava.util.internal.SocketConnectionFacadeImpl.<init>(SocketConnectionFacadeImpl.java:69)
    at org.asteriskjava.manager.internal.ManagerConnectionImpl.createSocket(ManagerConnectionImpl.java:713)
    at org.asteriskjava.manager.internal.ManagerConnectionImpl.connect(ManagerConnectionImpl.java:692)
    at org.asteriskjava.manager.internal.ManagerConnectionImpl.doLogin(ManagerConnectionImpl.java:485)
    at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(ManagerConnectionImpl.java:433)
    at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(ManagerConnectionImpl.java:418)
    at org.asteriskjava.manager.DefaultManagerConnection.login(DefaultManagerConnection.java:266)
    at test.com.mcruiseon.ivr.OutgoingCallTest.test(OutgoingCallTest.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

网络统计输出

name@desktop:/var/lib/asterisk/sounds/en$ sudo netstat -anp | grep asterisk
tcp        0      0 0.0.0.0:2000            0.0.0.0:*               LISTEN      2892/asterisk   
udp        0      0 0.0.0.0:5000            0.0.0.0:*                           2892/asterisk   
udp        0      0 0.0.0.0:4520            0.0.0.0:*                           2892/asterisk   
udp        0      0 0.0.0.0:5060            0.0.0.0:*                           2892/asterisk   
udp        0      0 0.0.0.0:4569            0.0.0.0:*                           2892/asterisk   
unix  2      [ ACC ]     STREAM     LISTENING     21312    2892/asterisk       /var/run/asterisk/asterisk.ctl
4

1 回答 1

1

在 manager.conf 中添加了常规部分。

[general]
enabled = yes
;webenabled = yes

port = 5038
bindaddr = 127.0.0.1

结果:工作!

于 2013-06-19T17:16:17.350 回答