Asterisk - java : Unable to request channel

Hi All,

I am newbie , I just want to create java application to make a call to asterisk (1.8)
by referring the asterisk java site (asterisk-java.org/0.2/tutorial.html)

the following is my code :

manager.conf

[general]
enabled = yes
port = 5038
bindaddr = 0.0.0.0

[manager]
secret=pa55w0rd
permit=0.0.0.0/0.0.0.0
read=all
write=all

sip.conf

[ivan]
type=friend
defaultuser=ivan
context=test
secret=ivan
host=dynamic
allow=all

extensions.conf

[test]
exten => 567,1,Answer()
exten => 567,2,Playback(welcome)
exten => 567,3,SayUnixTime(-1,UTC)
exten => 567,4,SayUnixTime(,CET,kMbdY)
exten => 567,5,Playback(vm-goodbye)
exten => 567,6,Hangup()

HelloManager.java

package com.asterisk.example;

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();
        System.out.println("Inside the constructor");
    }

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

        originateAction = new OriginateAction();
        originateAction.setChannel("SIP/ivan");
        originateAction.setAccount("ivan");
        originateAction.setContext("test");
        originateAction.setExten("567");
        originateAction.setPriority(new Integer(1));
        originateAction.setTimeout(new Integer(300000));
        
        // connect to Asterisk and log in
        managerConnection.login();
        System.out.println("successfully connectiong to asterisk");
        // send the originate action and wait for a maximum of 30 seconds for Asterisk
        // to send a reply
        originateResponse = managerConnection.sendAction(originateAction, 300000);

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

logs of java application

Inside the constructor
Jul 20, 2011 10:49:15 AM org.asteriskjava.manager.internal.ManagerConnectionImpl connect
INFO: Connecting to localhost:5038
Jul 20, 2011 10:49:15 AM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
INFO: Connected via Asterisk Call Manager/1.1
Jul 20, 2011 10:49:15 AM org.asteriskjava.manager.internal.EventBuilderImpl buildEvent
INFO: No event class registered for event type 'fullybooted', attributes: {privilege=system,all, event=FullyBooted, status=Fully Booted}. Please report at http://jira.reucon.org/browse/AJ
Jul 20, 2011 10:49:15 AM org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Successfully logged in
Jul 20, 2011 10:49:15 AM org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Determined Asterisk version: Asterisk 1.6
successfully connectiong to asterisk
Error
Jul 20, 2011 10:49:15 AM org.asteriskjava.manager.internal.ManagerReaderImpl run
INFO: Terminating reader thread: No more lines available: null
Jul 20, 2011 10:49:15 AM org.asteriskjava.manager.internal.ManagerConnectionImpl disconnect
INFO: Closing socket.

logs of asterisk console

== Manager 'manager' logged on from 127.0.0.1
[Jul 20 11:01:06] NOTICE[3716]: channel.c:5167 __ast_request_and_dial: Unable to request channel SIP/ivan
  == Manager 'manager' logged off from 127.0.0.1

logs /var/log/asterisk/messages

[Jul 20 09:26:19] NOTICE[2292] channel.c: Unable to request channel SIP/ivan

any one can help to fix the above error and show me how to run the above program to make call to asterisk from java application

ivan probably hasn’t registered.

thanks david55 for your reply

I have already added the following to sip.conf

[ivan] type=friend defaultuser=ivan context=test secret=ivan host=dynamic allow=all

is my above configuration is wrong ?

Depends on how you have configured the phone. I asked if you had registered, not whether it was present in sip.conf.

thanks david55 for your reply

I have registered ‘ivan’ with phone because i have tried to call without the use of java program and it works fine with me.

what i dont understand till now , is that what are the steps to let it work with java application

i do expect that the followings are the steps

1)Make sure that a user has been added to sip.conf
2)make configuration of user in softphone
3)execute the java application
4)make call from softphone

Are my above steps are right ?

I dont think so I am right , because the notice which i am getting “Unable to request channel SIP/ivan” is appearing before making call using softphone ?

I am really confused regarding the steps for making call using java application ?

Could you please correct me ? or guide me to the order of the steps to be followed ?

by the way i am using ekiga as softphone.

Failure to request a channel means a failure at the very first stage in creating an outgoing call to the phone. As it says unavailable, that suggested it was either missing from sip.conf or unregistered. If it is present and registered, I would looks for invisible characters, or ones that you didn’t copy down with the error message (excess spaces, for example).

Also, note that the phone registers with Asterisk, not Asterisk with the phone.

Also, unless you secure the system properly, it is quite possible to make an outgoing call from an unregistered phone.

What do

sip show users

and

sip show peers

show?

thanks david55 for your reply,

>sip show users Username Secret Accountcode Def.Context ACL ForcerPort ivan ivan test No No

>sip show peers Name/username Host Dyn Forcerport ACL Port Status ivan/ivan (Unspecified) D 0 Unmonitored 1 sip peers [Monitored: 0 online, 0 offline Unmonitored: 0 online, 1 offline]

It’s not registered

thanks david55 for your reply,

so how to register it ?

Configure the phone properly.

You may get a clue as to what is going wrong if you use sip set debug on.

thanks david55 for your reply,

Now i have registered ekiga softphone with asterisk

>sip show peers Name/username Host Dyn Forcerport ACL Port Status ivan/ivan 192.168.1.64 D 5061 Unmonitored 1 sip peers [Monitored: 0 online, 0 offline Unmonitored: 1 online, 0 offline]

What i have to do next ?

Re-run the Java and find if and where it breaks next. Up to the point where it tried to call the phone, it appeared to be working properly.

thanks david55 for your reply,

You mean to do the following

  1. Run java application
  2. Make call to extension 567 from ekiga softphone.

Am i Right ?

I thought the Java application did item (2).

thanks david55 for your reply

It works fine now with me .

I have did the following steps :

1)open ekiga softphone
2)run java application
3) java application sends request to ekiga ( request to make call from ekiga)
4)I have accepted the request
5) call has been made to extension 567

But am really not able to imagine how we can make use of the above java application in real time scenario

Could you please give me real time scenario example ?