使用AsteriskNOW,从加密狗拨出给出- java.net.ConnectException:连接拒绝



要从星号进行出站呼叫,我正在尝试使用星号java库。我得到一个连接拒绝异常(接近问题的结尾)。

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。来电和短信正常。信道加密狗不支持传入呼叫的DTMF,但这是一个单独的问题。基本传入工作正常。

Dongle.conf

context=dongle-incoming

Manager.conf

[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)

NetStat输出

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

在manager.conf中增加了general部分。

[general]
enabled = yes
;webenabled = yes
port = 5038
bindaddr = 127.0.0.1

Result: Worked !!

相关内容

  • 没有找到相关文章

最新更新