[asterisk-bugs] [JIRA] (ASTERISK-28147) Unable to connect to Asterisk from asterisk-java

Mani (JIRA) noreply at issues.asterisk.org
Fri Nov 2 15:00:47 CDT 2018


Mani created ASTERISK-28147:
-------------------------------

             Summary: Unable to connect to Asterisk from asterisk-java
                 Key: ASTERISK-28147
                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-28147
             Project: Asterisk
          Issue Type: Information Request
      Security Level: None
          Components: Configs/Basic-PBX
    Affects Versions: 13.15.0
            Reporter: Mani


Hi,

I wrote one java program using asterisk-java api for connecting configured Asterisk server.
Here is the code i wrote.


import java.io.IOException;

import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.DefaultManagerConnection;
import org.asteriskjava.manager.ManagerEventListener;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.StatusAction;
import org.asteriskjava.manager.event.ManagerEvent;

import org.asteriskjava.manager.response.ManagerResponse;

import org.asteriskjava.manager.action.OriginateAction;

public class TestDefaultManagerConnection {

private DefaultManagerConnection getDefaultManagerConnection()
{
DefaultManagerConnection dmc;

dmc = new DefaultManagerConnection();
dmc.setUsername("UserName"); 
dmc.setPassword("Pwd");
dmc.setHostname("IP Address");
dmc.setPort(5060);

return dmc;
}

	public  void testLogin() throws Exception {
		DefaultManagerConnection dmc;

		dmc = getDefaultManagerConnection();
		dmc.login();
		dmc.addEventListener(new ManagerEventListener() {
			public void handleEvent(ManagerEvent event) {
				System.out.println(event);
			}

			@Override
			public void onManagerEvent(ManagerEvent arg0) {
				System.out.println(arg0);
				
			}
		});
		dmc.sendAction(new StatusAction());

		// wait for 3 seconds to receive events
		Thread.sleep(3000);
		dmc.logoff();
	}
	
	public static void main(String[] args) throws Exception {
		TestDefaultManagerConnection connection=new TestDefaultManagerConnection();
		connection.testLogin();
	}
}


After running the above code, I am getting this exception

[main] INFO org.asteriskjava.manager.internal.ManagerConnectionImpl - Connecting to Ip Address:5060
Exception in thread "main" java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at org.asteriskjava.util.internal.SocketConnectionFacadeImpl.<init>(SocketConnectionFacadeImpl.java:140)
	at org.asteriskjava.util.internal.SocketConnectionFacadeImpl.<init>(SocketConnectionFacadeImpl.java:89)
	at org.asteriskjava.manager.internal.ManagerConnectionImpl.createSocket(ManagerConnectionImpl.java:839)
	at org.asteriskjava.manager.internal.ManagerConnectionImpl.connect(ManagerConnectionImpl.java:818)
	at org.asteriskjava.manager.internal.ManagerConnectionImpl.doLogin(ManagerConnectionImpl.java:535)
	at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(ManagerConnectionImpl.java:484)
	at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(ManagerConnectionImpl.java:469)
	at org.asteriskjava.manager.DefaultManagerConnection.login(DefaultManagerConnection.java:309)
	at voip.TestDefaultManagerConnection.testLogin(TestDefaultManagerConnection.java:36)
	at voip.TestDefaultManagerConnection.main(TestDefaultManagerConnection.java:89)

Can anyone help me out on this.

Thanks in advance



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list