Free PBX with Asterisk AMI

I would like to initiate a call from extension number to another in LAN network. I have done this task through FreePBX GUI. Now I am trying execute this task by using Asterisk AMI with java code. Below java code shows some exception while in debugging.

import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.OriginateAction;
import org.asteriskjava.manager.response.ManagerResponse;

public class HelloManager
private ManagerConnection managerConnection;

public HelloManager() throws IOException
    ManagerConnectionFactory factory = new ManagerConnectionFactory(
            "", "admin", "admin");

    this.managerConnection = factory.createManagerConnection();

public void run() throws IOException, AuthenticationFailedException,
    OriginateAction originateAction;
    ManagerResponse originateResponse;

    originateAction = new OriginateAction();
    originateAction.setPriority(new Integer(1));
    originateAction.setTimeout(new Integer(30000));
     // connect to Asterisk and log in


    // 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("Enter Response="+originateResponse.getResponse());

    // and finally log off and disconnect

public static void main(String[] args) throws Exception
    HelloManager helloManager;

    helloManager = new HelloManager();;

Feb 06, 2014 4:04:16 PM org.asteriskjava.manager.internal.ManagerConnectionImpl connect
INFO: Connecting to
Feb 06, 2014 4:04:17 PM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
INFO: Connected via Asterisk Call Manager/1.3
Feb 06, 2014 4:04:17 PM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
WARNING: Unsupported protocol version ‘Asterisk Call Manager/1.3’. Use at your own risk.
Feb 06, 2014 4:04:18 PM org.asteriskjava.manager.internal.ManagerConnectionImpl disconnect
INFO: Closing socket.
Feb 06, 2014 4:04:18 PM org.asteriskjava.manager.internal.ManagerReaderImpl run
INFO: Terminating reader thread: No more lines available: null
Exception in thread “main” org.asteriskjava.manager.AuthenticationFailedException: Authentication failed
at org.asteriskjava.manager.internal.ManagerConnectionImpl.doLogin(
at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(
at org.asteriskjava.manager.internal.ManagerConnectionImpl.login(
at org.asteriskjava.manager.DefaultManagerConnection.login(
at asteriskjtapi.HelloManager.main(
pls help me to complete this task

I do not know how this is working in Java, but with C# I go this way

OriginateAction oa = new OriginateAction(); oa.Context = "default"; oa.Priority = "1"; oa.Exten = astExtension; // The extention where the call goes if Asterisk is able to do the call oa.CallerId = "Living Room"; // CallerID to use for the call if (direction == "outbound") // for a outbound call we do need a trunk { oa.Channel = "LOCAL" + "/" + numberToCall + "@outbound-allroutes"; } else { oa.Channel = "SIP" + "/" + numberToCall; } oa.Timeout = 30000; oa.Async = true; try { ManagerResponse mr = astCon.SendAction(oa, oa.Timeout); Console.WriteLine("OriginateAction" + "\n\tResponse:" + mr.Response + "\n\tMessage:" + mr.Message + mr.Attributes); } catch (Exception ex) { Console.WriteLine(ex.Message); }