Ari application

hi, i have java web application that integrate with oracle database, now i want have voip system that read my dialplane from java(i have query in this class),
i used ari4java for this.
how i can invoke this class in asterisk ?
asterisk how complie java class ?
in extention.conf i set Stasis(http://192.168.1.101:8088/ari/applications/hello-world) but this dosent work.
how can i do ?

Asterisk is the server in this relationship; it cannot invoke the class library.

Asterisk is not a compiler for Java. You use normal Java tools to compile Java code. However, if you don’t know how to compile Java, there is no good reason for using a Java class library, as against, say a PHP or Python one, which is likely to get better peer support.

The Stasis parameter is not a URL, as application is not a client. It is the short name with which the application registers with Asterisk.

I think more explanation of what you are trying to achieve is needed. You are currently asking about a specific implementation of that which is probably a completely wrong approach.

thank you,
i have java web application and i am java developer, but i read that information in asterisk that seems wrong.
actually i want have a voip system that when client call , my java get data from database and send asterisk.
how can i integrate java(or python ) with asterisk ?

That sounds like a typical Fast AGI application, although there are many other ways, e.g. you could use curl and make the Java a web server.

what is the diffrent between fastagi and ari ?

without tomcat ?
how can i set fastagi in asterisk and java ?>

better question,
how can i register ARI with asterisk?

i can run my java code with asterisk and saw logs in CIL and swagger with following code:

package com.example.demo;

import ch.loway.oss.ari4java.ARI;
import ch.loway.oss.ari4java.AriVersion;
import ch.loway.oss.ari4java.generated.models.*;
import ch.loway.oss.ari4java.tools.ARIException;
import ch.loway.oss.ari4java.tools.AriCallback;
import ch.loway.oss.ari4java.tools.MessageQueue;
import ch.loway.oss.ari4java.tools.RestException;

import java.util.List;

/**
 * This class opens up an ARI application that creates a bridge with MOH.
 * When a call enters the application, a message is printed and the call
 * is connected to the bridge.
 *
 * @author lenz
 */
public class ConnectAndDial {

    public static final String ASTERISK_ADDRESS = "http://192.168.1.101:8088/";
    public static final String ASTERISK_USER = "asterisk";
    public static final String ASTERISK_PASS = "asterisk";
    public static final String APP_NAME = "myApp";

    ARI ari = null;
    Bridge b = null;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        ConnectAndDial me = new ConnectAndDial();
        me.start();
    }

    /**
     * This is the app...
     */
    public void start() {

        try {

            connect();
            createBridge();

            processEvents();

            removeBridge();

        } catch (ARIException e) {
            e.printStackTrace();
        } finally {
            if (ari != null) {
                try {
                    ARI.sleep(500);
                    ari.cleanup();
                } catch (Throwable t) {
                }
            }
        }
    }

    public void connect() throws ARIException {

        System.out.println("Connecting to: " + ASTERISK_ADDRESS
                + " as " + ASTERISK_USER + ":" + ASTERISK_PASS);

        ari = ARI.build(ASTERISK_ADDRESS, APP_NAME,
                ASTERISK_USER, ASTERISK_PASS,
                AriVersion.ARI_7_0_0);

        System.out.println("Connected through ARI: " + ari.getVersion());

        // let's raise an exeption if the connection is not valid
        AsteriskInfo ai = ari.asterisk().getInfo().execute();
        System.out.println("Hey! We're connected! Asterisk Version: " + ai.getSystem().getVersion());
    }

    public void createBridge() throws ARIException {

        // create a bridge and start playing MOH on it
        // UGLY: we should have a constant for the allowed bridge types
        ari.sounds().get("hello_world");

        System.out.println("Creating a bridge");
        b = ari.bridges().create().setName("myBridge").execute();
        System.out.println("Bridge ID:" + b.getId() + " Name:" + b.getName() + " Tech:" + b.getTechnology() + " Creator:" + b.getCreator());

        // start MOH on the bridge
        System.out.println("Starting MOH on bridge" + "\t size:  "+ ari.bridges().list().execute().size());
        ari.bridges().startMoh(b.getId()).execute();
        ari.bridges().play(b.getId(),"sound:hello-world").execute();
        // check which bridges are available
        System.out.println("Listing bridges");
        List<Bridge> bridges = ari.bridges().list().execute();

        for (Bridge bb : bridges) {
            //printBridge(bb);
        }
    }

    /**
     * The new style of event processing...
     *
     * @throws ARIException
     */
    public void processEvents() throws ARIException {

        System.out.println("Starting events... ");
        MessageQueue mq = ari.getWebsocketQueue();
        long start = System.currentTimeMillis();
        System.out.println(ari.isWsConnected());
         while ((System.currentTimeMillis() - start) < 10 * 1000L) {

            Message m = mq.dequeueMax(100, 20);
            if (m != null) {

                long now = System.currentTimeMillis() - start;
                System.out.println(now + ": " + m);

                if (m instanceof StasisStart) {
                    StasisStart event = (StasisStart) m;
                    System.out.println("Channel found: " + event.getChannel().getId() + " State:" + event.getChannel().getState());

                    ari.bridges().addChannel(b.getId(), event.getChannel().getId()).execute();
                }
            }
        }
        System.out.println(ari.isWsConnected());
        System.out.println("No more events... ");
    }


    public void removeBridge() throws ARIException {

        System.out.println(threadName() + "Removing bridge....");

        ari.bridges().destroy(b.getId()).execute(new AriCallback<Void>() {

            @Override
            public void onSuccess(Void result) {
                // Let's do something with the returned value
                System.out.println(threadName() + "Bridge destroyed ");
            }

            @Override
            public void onFailure(RestException e) {
                System.out.println(threadName() + "Failure in removeBridge() ");
                e.printStackTrace();
            }
        });
    }

    /**
     * Dumps a bridge to string.
     * Should we have a default toString that makes more sense?
     *
     * @param b the bridge
     */
    private void printBridge(Bridge b) {
        System.out.println(". BridgeID:" + b.getId()
                + " Name:" + b.getName()
                + " Tech:" + b.getTechnology()
                + " Creator:" + b.getCreator()
                + " Class: " + b.getBridge_class()
                + " Type: " + b.getBridge_type()
                + " Chans: " + b.getChannels().size());
        for (String s : b.getChannels()) {
            System.out.println(" - ChannelID: " + s);
        }
    }

    /**
     * @return the name of the current thread
     */
    private String threadName() {
        return "[Thread:" + Thread.currentThread().getName() + "] ";
    }
}

but i cant call with softphon to java application.
in asterisk how can i do for this problem ?

11111 22222222

Decline looks reasonable for a call that is never answered, but does have a valid extension.

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