Java Code

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 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(
            "", "username", "password");

    this.managerConnection = factory.createManagerConnection();

public void run() throws IOException, AuthenticationFailedException,
        TimeoutException, InterruptedException
    // register for events
    // connect to Asterisk and log in

    // 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.setPriority(new Integer(1));
    originateAction.setTimeout(new Integer(5000));

    originateResponse = managerConnection.sendAction(originateAction, 30000);
    SetVarAction setVarAction = null;
    	System.out.println("I am coming hereeeeeeeeeeeeeee");
       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

    	System.out.println(" i am not takin callssssssssssssssss");
public void onManagerEvent(ManagerEvent event)
    // just print received events

public static void main(String[] args) throws Exception
    HelloEvents helloEvents;

    helloEvents = new HelloEvents();;


P.S=the originateResponse always comes to be false in my case.


Can u explain to me how do i get in my directory?..Im trying to build some asterisk application with java…cheers


I have found it easier to use the AsteriskServer Interface which is in the live package and use whatever Originate command is associated with it.

Private Message me if you want more info