Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java asterisk

 
Omar I Mohaidat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

i am new in asterisk and IVR system, there is authentication problem when run this code,

import java.io.IOException;

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(
"localhost", "manager", "pa55w0rd");

this.managerConnection = factory.createManagerConnection();
}

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();
}

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

helloManager = new HelloManager();
helloManager.run();
}
}

i can't connect to asterisk server but the strange when i use SIP phone i can connct to server using same ip, username, password, and extention.

any help please
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar, could you please use http://faq.javaranch.com/java/UseCodeTags while posting code? What does "i can't connect to asterisk server" means? Any error messages?
 
Omar I Mohaidat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Misha Ver wrote:Omar, could you please use http://faq.javaranch.com/java/UseCodeTags while posting code? What does "i can't connect to asterisk server" means? Any error messages?


i tried to connect to asterisk server, using this code :

public HelloManager() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"localhost", "manager", "pa55w0rd");

this.managerConnection = factory.createManagerConnection();
}

i got authentication fialed error message.

i tried to connect to asterisk server using SIP phone using same IP, username, and password on the same machine, it connected without problems.

i want to know why i can't connect using my java code (and got authentication failed error) and i can connect using SIP phone.


thank you in advance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic