Trying to make a call : error originate failed

Hi,

I’m trying to make a call with my java application. Here i put the code :

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;

import java.io.IOException;

public class CallTest {

    private ManagerConnection managerConnection;


    public CallTest(String host, String user, String password) {
        ManagerConnectionFactory factory = new ManagerConnectionFactory(host,5060,user,password);
        this.managerConnection = factory.createManagerConnection();
        System.out.println(managerConnection.getHostname());
        System.out.println(managerConnection.getPassword());
        System.out.println(managerConnection.getUsername());
        System.out.println(managerConnection.getVersion());
    }

    public void serverConnexion() {
        try {
            managerConnection.login();
        } catch (IOException a) {
            a.printStackTrace();
        } catch (AuthenticationFailedException a) {
            a.printStackTrace();
        } catch (TimeoutException a) {
            a.printStackTrace();
        }
    }

    public void serverDeconnexion() {
        managerConnection.logoff();
    }

    public void call(String toCall) throws IOException, TimeoutException {
        OriginateAction originateAction;
        ManagerResponse originateResponse;


        originateAction = new OriginateAction();
        originateAction.setChannel("SIP/"  + toCall);
        originateAction.setContext("work");
        originateAction.setExten(toCall);
        originateAction.setVariable("EXTEN",toCall);
        originateAction.setPriority(new Integer(1));

        originateResponse = managerConnection.sendAction(originateAction,30000);

        System.out.println(originateResponse.getResponse());
        System.out.println(originateResponse.getMessage());
    }
}

When i try to use the function call, i get a “error” response and “originate failed” response message.

And on the asterisk console, i get an error

ERROR[4212]: chan_sip.c:30723 sip_request_call : Unable to create channel with empty destination

I tried to type this error, but I did not find any existing correction.
Please help if possible.

The problem is in your code. “toCall” is empty. Since it’s empty, chan_sip doesn’t know what to dial.

Effectively the error no longer appears, but i still get the error “originate failed”.
With “sip set debug on” i get :

Really destroying SIP dialog '7058c8f062fe73f036b1d9ee727570f6@192.168.1.54:5060' Method: OPTIONS
Reliably Transmitting (NAT) to 192.168.1.89:45055:
OPTIONS sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp SIP/2.0
Via: SIP/2.0/UDP 192.168.1.54:5060;branch=z9hG4bK5826a033;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@192.168.1.54>;tag=as2c668647
To: <sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp>
Contact: <sip:asterisk@192.168.1.54:5060>
Call-ID: 6c2be3c9375543af56e9e4234797a6e1@192.168.1.54:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 16.2.1~dfsg-2build2
Date: Mon, 27 Apr 2020 09:45:57 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0

There is no call in your SIP trace.

Well, that’s the only trace i get when i use my function call with parameter 6002.
Here’s the complete trace that the console display in a loop

Really destroying SIP dialog '0768978b7f427993752192130c39b7dd@192.168.1.54:5060' Method: OPTIONS
Reliably Transmitting (NAT) to 192.168.1.89:45055:
OPTIONS sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp SIP/2.0
Via: SIP/2.0/UDP 192.168.1.54:5060;branch=z9hG4bK3ed0b73b;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@192.168.1.54>;tag=as0167b58e
To: <sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp>
Contact: <sip:asterisk@192.168.1.54:5060>
Call-ID: 09cccdc5728426bf6df0904443498053@192.168.1.54:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 16.2.1~dfsg-2build2
Date: Mon, 27 Apr 2020 10:06:25 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0


---
Retransmitting #1 (NAT) to 192.168.1.89:45055:
OPTIONS sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp SIP/2.0
Via: SIP/2.0/UDP 192.168.1.54:5060;branch=z9hG4bK3ed0b73b;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@192.168.1.54>;tag=as0167b58e
To: <sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp>
Contact: <sip:asterisk@192.168.1.54:5060>
Call-ID: 09cccdc5728426bf6df0904443498053@192.168.1.54:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 16.2.1~dfsg-2build2
Date: Mon, 27 Apr 2020 10:06:25 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0


---
Retransmitting #2 (NAT) to 192.168.1.89:45055:
OPTIONS sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp SIP/2.0
Via: SIP/2.0/UDP 192.168.1.54:5060;branch=z9hG4bK3ed0b73b;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@192.168.1.54>;tag=as0167b58e
To: <sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp>
Contact: <sip:asterisk@192.168.1.54:5060>
Call-ID: 09cccdc5728426bf6df0904443498053@192.168.1.54:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 16.2.1~dfsg-2build2
Date: Mon, 27 Apr 2020 10:06:25 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0


---
Retransmitting #3 (NAT) to 192.168.1.89:45055:
OPTIONS sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp SIP/2.0
Via: SIP/2.0/UDP 192.168.1.54:5060;branch=z9hG4bK3ed0b73b;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@192.168.1.54>;tag=as0167b58e
To: <sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp>
Contact: <sip:asterisk@192.168.1.54:5060>
Call-ID: 09cccdc5728426bf6df0904443498053@192.168.1.54:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 16.2.1~dfsg-2build2
Date: Mon, 27 Apr 2020 10:06:25 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0


---
Retransmitting #4 (NAT) to 192.168.1.89:45055:
OPTIONS sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp SIP/2.0
Via: SIP/2.0/UDP 192.168.1.54:5060;branch=z9hG4bK3ed0b73b;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@192.168.1.54>;tag=as0167b58e
To: <sip:6002@192.168.1.89:45055;rinstance=8ab772d0bf938f1c;transport=tcp>
Contact: <sip:asterisk@192.168.1.54:5060>
Call-ID: 09cccdc5728426bf6df0904443498053@192.168.1.54:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 16.2.1~dfsg-2build2
Date: Mon, 27 Apr 2020 10:06:25 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0

Does anyone have a solution to my problem ? I have tried a number of solutions and browsed a lot of forums and nothing works

thank you in advance

The SIP device known as “6002” is not responding, so chan_sip would mark it as unreachable and not allow calls to it. You’d need to identify why that is. For example it is showing as using TCP, but the other side is not responding. Do they not support OPTIONS? Is the connection up? What does the other side say?

What do you mean when you “Do they not support OPTIONS” ?
Nothing happen on my asterisk console when i try to send an OriginateAction, i only get error originate failed.

I also have an other question, how can i connect to my asterisk server with a user contained in sip.conf, i don’t find any informations about that in the java doc.

Thank you in advance for your answer.

They do not support the SIP OPTIONS method. More specifically, they ignore it rather than rejecting it.

The chan_sip module is trying to reach the configured endpoint named “6002”. It’s getting no response. It therefore considers it unreachable, so any call attempt to it won’t work. You could try removing the “qualify” option so it doesn’t do reachability checks.

There’s nothing really else I can add.

Hi again,

It finally worked :slight_smile: , thank you both for your help.

If it is not too much to ask, could you answer a last question that I expressed yesterday. (was : how can i connect a sip users (not manager) with the asterisk java API). I have read much of the documentation available here, but i didn’t find something to do that.
Thanks again in advance.

The project doesn’t produce the Java API you refer to, so people who have used it may not be on here or there may be only a few. You also haven’t specified what “connect” actually means. State what you actually what to use it for.

My goal is to create a sip client that will make and receive calls.
What I meant by “connect” is that I want a user to be able to connect to my Asterisk server to make calls with others user’s, like X-lite or some others SIP client.
It is not possible with the java asterisk API ?

We don’t know what the Java Asterisk API does, but assuming it is a full function front end to AMI, you seem to be trying to implement some sort of click to call arrangement, rather than a normal call setup and should google for that subject, and adapt the, likely PHP, code to the Java API.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.