Calls going to from-sip-external by default from Java code

General discussions about Asterisk.

Moderators: Moderator, Support

Calls going to from-sip-external by default from Java code

Postby manas539 » Fri Jul 17, 2015 7:15 am

Hi all,

I am a newbie to Asterisk. I am using the Asterisk-JAVA API to call Asterisk server using an extension and a setup account. Using the code and the configuration i am able to call the desired extension successfully from a softphone.But when i try to do the same using the JAVA code then the call gets processed by the "from-external-sip" extension and not by the extension i have setup in the code.Below is the code :
Code: Select all
import java.io.IOException;

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


public class TryConnect  {
    private ManagerConnection managerConnection;

    public TryConnect() throws IOException
    {
       ManagerConnectionFactory factory = new ManagerConnectionFactory("xxx.xxx.xxx.xxx", "xxx", "xxxx");
       this.managerConnection = factory.createManagerConnection();
              
    }

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

        originateAction = new OriginateAction();
         
        originateAction.setChannel("SIP/10001@xxx.xxx.xxx.xxx");
       
        originateAction.setContext("from-internal");
        originateAction.setExten("1000");
        originateAction.setCallerId("1000");
       
       
        originateAction.setPriority(new Integer(1));
        originateAction.setTimeout(new Integer(5000));
       

        // 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, 5000);

        // 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
    {
       TryConnect helloManager;

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



Below is the output in the CLI on making the call from the JAVA code :-
Code: Select all
-- Executing [10001@from-sip-external:1] NoOp("SIP/192.168.220.10-00000007", "Received incoming SIP connection from unknown peer to 10001") in new stack
    -- Executing [10001@from-sip-external:2] Set("SIP/192.168.220.10-00000007", "DID=10001") in new stack
    -- Executing [10001@from-sip-external:3] Goto("SIP/192.168.220.10-00000007", "s,1") in new stack
    -- Goto (from-sip-external,s,1)
    -- Executing [s@from-sip-external:1] GotoIf("SIP/192.168.220.10-00000007", "0?checklang:noanonymous") in new stack
    -- Goto (from-sip-external,s,5)
    -- Executing [s@from-sip-external:5] Set("SIP/192.168.220.10-00000007", "TIMEOUT(absolute)=15") in new stack
    -- Channel will hangup at 2015-07-17 00:04:16.259 CEST.
    -- Executing [s@from-sip-external:6] Log("SIP/192.168.220.10-00000007", "WARNING,"Rejecting unknown SIP connection from 192.168.220.10"") in new stack
    -- Executing [s@from-sip-external:7] Answer("SIP/192.168.220.10-00000007", "") in new stack
    -- Executing [1000@from-internal:1] Dial("SIP/192.168.220.10-00000006", "SIP/1000") in new stack
  == Everyone is busy/congested at this time (1:0/0/1)
    -- Executing [1000@from-internal:2] Answer("SIP/192.168.220.10-00000006", "") in new stack
    -- Executing [1000@from-internal:3] Playback("SIP/192.168.220.10-00000006", "pls-try-call-later") in new stack
    -- Executing [s@from-sip-external:8] Wait("SIP/192.168.220.10-00000007", "2") in new stack
    -- <SIP/192.168.220.10-00000006> Playing 'pls-try-call-later.ulaw' (language 'en')
  == Manager 'admin' logged off from 192.168.220.20
    -- Executing [s@from-sip-external:9] Playback("SIP/192.168.220.10-00000007", "ss-noservice") in new stack
    -- <SIP/192.168.220.10-00000007> Playing 'ss-noservice.ulaw' (language 'en')
    -- Executing [1000@from-internal:4] Hangup("SIP/192.168.220.10-00000006", "") in new stack
  == Spawn extension (from-internal, 1000, 4) exited non-zero on 'SIP/192.168.220.10-00000006'
    -- Executing [h@from-internal:1] Hangup("SIP/192.168.220.10-00000006", "") in new stack
  == Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/192.168.220.10-00000006'
  == Spawn extension (from-sip-external, s, 9) exited non-zero on 'SIP/192.168.220.10-00000007'
    -- Executing [h@from-sip-external:1] NoOp("SIP/192.168.220.10-00000007", "Received incoming SIP connection from unknown peer to h") in new stack
    -- Executing [h@from-sip-external:2] Set("SIP/192.168.220.10-00000007", "DID=s") in new stack
    -- Executing [h@from-sip-external:3] Goto("SIP/192.168.220.10-00000007", "s,1") in new stack
    -- Goto (from-sip-external,s,1)
    -- Executing [s@from-sip-external:1] GotoIf("SIP/192.168.220.10-00000007", "0?checklang:noanonymous") in new stack
    -- Goto (from-sip-external,s,5)
    -- Executing [s@from-sip-external:5] Set("SIP/192.168.220.10-00000007", "TIMEOUT(absolute)=15") in new stack
    -- Channel will hangup at 2015-07-17 00:04:18.584 CEST.
    -- Executing [s@from-sip-external:6] Log("SIP/192.168.220.10-00000007", "WARNING,"Rejecting unknown SIP connection from 192.168.220.10"") in new stack
    -- Executing [s@from-sip-external:7] Answer("SIP/192.168.220.10-00000007", "") in new stack
  == Spawn extension (from-sip-external, s, 7) exited non-zero on 'SIP/192.168.220.10-00000007'



Please help me out why the call is getting directed to the "from-external-sip" extension and not the "from-internal" extension as i have set up in the code.

Thanks.
manas539
Newsterisk
 
Posts: 6
Joined: Fri Jul 17, 2015 7:02 am

Re: Calls going to from-sip-external by default from Java code

Postby david55 » Fri Jul 17, 2015 12:44 pm

Looks like you have specified your own address in the destination channel address specification and the call is looped back.
david55
Moves Like Spencer
 
Posts: 12570
Joined: Fri Sep 26, 2008 5:03 am

Re: Calls going to from-sip-external by default from Java code

Postby manas539 » Fri Jul 17, 2015 1:27 pm

Hi David,

The line in the code:

originateAction.setChannel("SIP/10001@xxx.xxx.xxx.xxx");

The ip address specified is the IP address of the Asterisk Server. Earlier i had tried using no IP Address at all while setting the channel but the code compiled with an error.

And while using the softphone to add and register a new user with id 10001, i use the same string format as "10001@xxx.xxx.xxx.xxx".

So, please let me know if i am wrong in my observation or something else is wrong.

Thanks.
manas539
Newsterisk
 
Posts: 6
Joined: Fri Jul 17, 2015 7:02 am

Re: Calls going to from-sip-external by default from Java code

Postby manas539 » Sun Jul 19, 2015 1:56 am

I found out the issue to this problem. It was caused because the user 10001 as specified in the code was not explicitly registered in SIP.conf file. After registering it goes to the defined context in the code. :D
manas539
Newsterisk
 
Posts: 6
Joined: Fri Jul 17, 2015 7:02 am


Return to Asterisk General

Who is online

Users browsing this forum: No registered users and 1 guest