[Asterisk-java-users] asterisk-java integration with CSTA for asterisk
Brought to you by:
srt
From: christopher m. <cm...@mb...> - 2005-10-18 16:25:28
|
Hello, I submitted a query a week or so ago regarding connecting a problem i was having with connecting my csta implementation with asterisk with asterisk-java. I've again checked my work and i'm sure everything is how it is supposed to be. my source code at http://sourceforge.net/projects/oscsta if anyone is interested. It's messy code at the moment because I've just been hacking at it willy nilly. In the coming weeks I'll neaten it up and get the javadocs and other accompanying docs in order. it works, with the serial port code in place, on siemens hipath 3000 pbxs. There is a class in the csta.server.asterisk package called BogusAsteriskConnection.java which is copied at the bottom of the page. The problem i was having was that the connection was refused. Following is: * the error message from java * the config of manager.conf * show manager connected from asterisk CLI after telnet is done * telnet from another console * the code from BogusAsteriskConnection.java * no firewall is running ******************************* Here is the error message from java: ******************************* Oct 19, 2005 2:19:03 AM net.sf.asterisk.util.impl.JavaLoggingLog info INFO: Connecting to localhost port 5038 java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158) at java.net.Socket.connect(Socket.java:452) at java.net.Socket.connect(Socket.java:402) at java.net.Socket.<init>(Socket.java:309) at java.net.Socket.<init>(Socket.java:124) at net.sf.asterisk.io.SocketConnectionFacadeImpl.<init>(SocketConnectionFacadeImpl.java:34) at net.sf.asterisk.manager.DefaultManagerConnection.createSocket(DefaultManagerConnection.java:343) at net.sf.asterisk.manager.DefaultManagerConnection.connect(DefaultManagerConnection.java:332) at net.sf.asterisk.manager.DefaultManagerConnection.login(DefaultManagerConnection.java:253) at net.sf.asterisk.manager.DefaultManagerConnection.login(DefaultManagerConnection.java:221) at csta.server.asterisk.BogusAsteriskConnection.run(BogusAsteriskConnection.java:141) at csta.server.asterisk.BogusAsteriskConnection.<init>(BogusAsteriskConnection.java:51) at csta.server.CSTAServer.<init>(CSTAServer.java:109) at start_CSTAServer.start_application(start_CSTAServer.java:46) at start_CSTAServer.main(start_CSTAServer.java:31) ******************************** manager.conf ******************************* [general] enabled = yes port = 5038 bindaddr = 0.0.0.0 permit = 0.0.0.0/0.0.0.0 ;displayconnects = yes [mylo] secret=password permit=0.0.0.0/0.0.0.0 read = system,call,log,verbose,command,agent,user write = system,call,log,verbose,command,agent,user ******************************** show manager connected before telnet ******************************** *CLI> show manager connected Username IP Address ******************************* and after connection with telnet ******************************* *CLI> show manager connected Username IP Address 127.0.0.1 *CLI> ******************************* telnet from another console ******************************* cm@laptop:~> telnet 127.0.0.1 5038 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. Asterisk Call Manager/1.0 ***************************** the BogusAsteriskConnection.java ****************************** /* * oscsta -- Open Source CSTA. * * oscsta-j - Open Source CSTA - java. * * Copyright (C) 2003-2005, Christopher Mylonas * * Christopher Mylonas <osc...@mr...> * * This program is free software, distributed under the terms of * the GNU General Public License */ /* * BogusAsteriskConnection.java * * Created on September 10, 2005, 2:39 PM */ package csta.server.asterisk; import csta.stack.callControl.events.ServiceInitiated ; import csta.stack.callControl.events.ConnectionCleared ; import java.io.IOException ; import net.sf.asterisk.manager.AuthenticationFailedException; import net.sf.asterisk.manager.ManagerConnection; import net.sf.asterisk.manager.ManagerConnectionFactory; import net.sf.asterisk.manager.TimeoutException; import net.sf.asterisk.manager.action.OriginateAction; import net.sf.asterisk.manager.response.ManagerResponse; /** * * @author cm * What's gonna happen here is this class has the connection to asterisk. * It will receive the events from whatever channels, and fire off the * CSTA events. This class will then handover to the CSTAServer most of * the CSTA string. The remainder of the string needs to be completed by * the server from the MonitorCrossReferenceID backwards - that is, all * the administrative stuff a server has to do e.g. callid_id and wrap * the string up. */ public class BogusAsteriskConnection implements AsteriskEvents{ int callid_a, callid_b, callid_c, callid_d = 0 ; public static final int INTEGER = 0x02 ; private ManagerConnection managerConnection ; /** Creates a new instance of BogusAsteriskConnection */ public BogusAsteriskConnection() { try{ ManagerConnectionFactory factory = new ManagerConnectionFactory(); this.managerConnection = factory.getManagerConnection("localhost", "mylo", "password"); run() ; }catch(IOException e){ e.printStackTrace() ; }catch(AuthenticationFailedException e2){ e2.printStackTrace() ; }catch(TimeoutException e3){ e3.printStackTrace() ; } } //probably get an extension and a cause from asterisk. //have to get a valid call_id from CSTAServer if asterisk doesn't //provide one. public void fire_ServiceInitiated(String ext){ System.out.println("Firing asterisk service initiated") ; //get a call_id from the csta server String call_id = CallIDGeneration() ; String time = "20050922121555" ; ServiceInitiated si = new ServiceInitiated(ext, call_id,time) ; } public void fire_ConnectionCleared(String ext){ System.out.println("Firing asterisk service initiated") ; //get a call_id from the csta server String call_id = CallIDGeneration() ; String time = "20050922121555" ; ConnectionCleared cc = new ConnectionCleared(ext, call_id,time) ; } private String CallIDGeneration(){ String callid_id = new String() ; callid_a++ ; if( callid_a > 255 ){ callid_a = 0 ; callid_b++ ; if( callid_b > 255 ){ callid_b = 0 ; callid_c++ ; if( callid_c > 255 ){ callid_c = 0 ; callid_d++ ; if( callid_d > 255 ){ callid_d = 0 ; callid_a = 1 ; } } } } if( callid_d > 0 ){ char[] invID = { (char)callid_d, (char)callid_c, (char)callid_b, (char)callid_a } ; callid_id = new String(invID) ; return callid_id ; } else if( callid_c > 0 ){ char[] invID = { (char)callid_c, (char)callid_b, (char)callid_a } ; callid_id = new String(invID) ; return callid_id ; } else if( callid_b >= 0 ){ char[] invID = { (char)callid_b, (char)callid_a } ; callid_id = new String(invID) ; return callid_id ; } //commenting below ensures a call id with length of 2 is mandatory // else if( callid_a > 0 ){ // char[] invID = { (char)callid_a } ; // callid_id = new String(invID) ; // return callid_id ; // } return callid_id ; } public StringBuffer GetCallID(){ StringBuffer sb = new StringBuffer() ; String inv_id = CallIDGeneration() ; sb = sb.insert(0, inv_id).insert(0,(char)inv_id.length()).insert(0, (char)INTEGER) ; return sb ; } public void run() throws IOException, AuthenticationFailedException, TimeoutException{ OriginateAction originateAction; ManagerResponse originateResponse; originateAction = new OriginateAction(); originateAction.setChannel("SIP/John"); originateAction.setContext("default"); originateAction.setExten("1300"); 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(originateResponse.getResponse()); // and finally log off and disconnect managerConnection.logoff(); } } *********************** and i repeat no firewall running *********************** from within yast (on SuSE 9.3) whatever the message says along the lines of "firewall is not currently running Many thanks :) mylo |