Getting exception, Channel not in a Stasis application

Hello ,
I am new to asterisk, I need to make outgoing calls using java ARI API I could make a call to the extension number with the java code below I need to play the audio and get the response from the end user. could someone help me on this to move further?

package ariStandalone;

import ch.loway.oss.ari4java.ARI;
import ch.loway.oss.ari4java.tools.ARIException;
import ch.loway.oss.ari4java.AriVersion;
import ch.loway.oss.ari4java.generated.AsteriskInfo;
import ch.loway.oss.ari4java.generated.Bridge;
import ch.loway.oss.ari4java.generated.Channel;
import ch.loway.oss.ari4java.generated.Message;
import ch.loway.oss.ari4java.generated.Playback;
import ch.loway.oss.ari4java.generated.StasisStart;
import ch.loway.oss.ari4java.tools.AriCallback;
import ch.loway.oss.ari4java.tools.MessageQueue;
import ch.loway.oss.ari4java.tools.RestException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**

  • 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.

*/
public class ConnectAndDial {

public static final String ASTERISK_ADDRESS = “http://54.172.242.251:18088/”;
public static final String ASTERISK_USER = “ari4java”;
public static final String ASTERISK_PASS = “yothere”;

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, "", 
            ASTERISK_USER, ASTERISK_PASS, 
            AriVersion.ARI_1_8_0); // IM_FEELING_LUCKY

    System.out.println("Connected through ARI: " + ari.getVersion());
    
    // let's raise an exeption if the connection is not valid
    AsteriskInfo ai = ari.asterisk().getInfo("");
    System.out.println("Hey! We're connected! Asterisk Version: " + ai.getSystem().getVersion());
    List<Channel> channels = ari.channels().list();
    
    System.out.println("There are " + channels.size() + " active channels now.");
    
    for(int i = 0; i < channels.size(); i++) {
      //  System.out.println(channels.get(i).getName());
    }

}




/**
 * The new style of event processing...
 *
 * throws ARIException
 */

public void processEvents() throws ARIException {

    System.out.println( "Starting events... " );
    MessageQueue mq = ari.getWebsocketQueue();
    System.out.println( "web sockets... " );
    long start = System.currentTimeMillis();

    String dummy = "";


    
    
    Channel chan = ari.channels().originate("SIP/31813", "s", "from-internal", 1, dummy, dummy, dummy, dummy, 10000, Collections.EMPTY_MAP, dummy, dummy, dummy);
    
    Playback p=ari.channels().play(chan.getId(),"sound: tt-monkeys",chan.getLanguage(),2,2,"");

    
    System.out.println( "Channel:" + chan.getName() + " in state " + chan.getState() );
    
    while ((System.currentTimeMillis() - start) < 10 * 1000L) {
    	System.out.println("In loop");
        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(), "");
            }
        } 
    }

    System.out.println( "No more events... " );
} 

}

I was getting the following exception

ch.loway.oss.ari4java.tools.RestException: Channel not in a Stasis application
at ch.loway.oss.ari4java.tools.http.NettyHttpClient.makeException(NettyHttpClient.java:197)
at ch.loway.oss.ari4java.tools.http.NettyHttpClient.httpActionSync(NettyHttpClient.java:218)
at ch.loway.oss.ari4java.tools.BaseAriAction.httpActionSync(BaseAriAction.java:69)
at ch.loway.oss.ari4java.generated.ari_1_8_0.actions.ActionChannels_impl_ari_1_8_0.play(ActionChannels_impl_ari_1_8_0.java:443)
at ariStandalone.ConnectAndDial.processEvents(ConnectAndDial.java:146)
at ariStandalone.ConnectAndDial.start(ConnectAndDial.java:59)
at ariStandalone.ConnectAndDial.main(ConnectAndDial.java:45)

I don’t do Java, but you appear to be originating a channel and then immediately playing a sound file on it. This won’t work as the channel has to be answered before it is in your ARI application.

Can you please provide me some doc or tutorial to get into the correct process

I don’t know of any tutorials or docs for the Java stuff as I don’t use it. The actual behavior of things is documented on the wiki[1] though, and there are some guides with information[2].

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Channels+REST+API#Asterisk13ChannelsRESTAPI-originateWithId
[2] https://wiki.asterisk.org/wiki/display/AST/Introduction+to+ARI+and+Channels

Thank you
can you tell me what does the application name means in asterisk

In this context it refers to your ARI application.