HI,
I started off with asterisk today, trying to integrate it in my application.
I am using "manager API"
till now I am able to connect to the asterisk server.
But I am not able to talk, as in i am able to call, but as soon as the user takes the call , the socket gets closed.
There is one more issue, that my call is getting dialled twice, to different lines on the same extension.
I am attaching my code.
Please help me with it.
Thanx in advance
package asterisk;
import java.io.IOException;
import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.ManagerEventListener;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.OriginateAction;
import org.asteriskjava.manager.action.RedirectAction;
import org.asteriskjava.manager.action.SetVarAction;
import org.asteriskjava.manager.action.StatusAction;
import org.asteriskjava.manager.event.ManagerEvent;
import org.asteriskjava.manager.response.ManagerResponse;
public class HelloEvents implements ManagerEventListener
{
private ManagerConnection managerConnection;
public HelloEvents() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"pbxindiaco.uk", "username", "password");
this.managerConnection = factory.createManagerConnection();
}
public void run() throws IOException, AuthenticationFailedException,
TimeoutException, InterruptedException
{
// register for events
managerConnection.addEventListener(this);
// connect to Asterisk and log in
managerConnection.login();
// request channel state
managerConnection.sendAction(new StatusAction());
// wait 100 seconds for events to come in
// Thread.sleep(10000);
OriginateAction originateAction;
ManagerResponse originateResponse;
originateAction = new OriginateAction();
originateAction.setChannel("SIP/3006");
originateAction.setContext("default");
originateAction.setExten("3006");
originateAction.setPriority(new Integer(1));
originateAction.setTimeout(new Integer(5000));
originateResponse = managerConnection.sendAction(originateAction, 30000);
SetVarAction setVarAction = null;
if(originateResponse.getResponse().equals("Success"))
{
System.out.println("I am coming hereeeeeeeeeeeeeee");
setVarAction.setVariable("STRING3");
setVarAction.setValue("SIP/3006");
originateResponse = managerConnection.sendAction(setVarAction, 30000);
// if(originateResponse.getResponse().equals(“Success”))
// {
//
// RedirectAction redirectAction = new RedirectAction();
// redirectAction.setChannel (“SIP/3000”);
// redirectAction.setContext(“mariaSIP”);
// redirectAction.setExten(“444”);
// redirectAction.setPriority (new
// Integer(1));
// originateResponse = managerConnection.sendAction (redirectAction,
// 30000); if (originateResponse.getResponse().equals(“Success”))
// {
// …
// }
// …
// }
// and finally log off and disconnect
}
else
{
System.out.println(" i am not takin callssssssssssssssss");
}
managerConnection.logoff();
}
public void onManagerEvent(ManagerEvent event)
{
// just print received events
System.out.println(event);
}
public static void main(String[] args) throws Exception
{
HelloEvents helloEvents;
helloEvents = new HelloEvents();
helloEvents.run();
}
}
P.S=the originateResponse always comes to be false in my case.