2

Trying use agi to listen asterisk.

But after startup method is running, my application is freezing. There is no error appears...

My spring bean:

@Bean(name = "agi")
public DefaultAgiServer getAsteriskAgi() throws Exception {
    DefaultAgiServer agiServer = new DefaultAgiServer();
    agiServer.startup();
    return agiServer;
}

My mapping

public class AsteriskAgi extends BaseAgiScript{
@Override
public void service(AgiRequest agiRequest, AgiChannel agiChannel) throws AgiException {
    // Answer the channel...
    answer();
    // ...say hello...
    streamFile("welcome");
    streamFile("tt-monkeys");
    // ...and hangup.
    hangup();

}

}

my properties file

fastagi-mapping.properties 

located in resources folder

Why is this happening?

UPD Last two console output:

2018-05-21 15:19:53 DEBUG DefaultAgiServer:81 - Using channelFactory org.asteriskjava.fastagi.internal.DefaultAgiChannelFactory
2018-05-21 15:19:53  INFO DefaultAgiServer:315 - Listening on *:4573.
Aleksei
  • 165
  • 8
  • Set log to debug level and show us the last lines. – Ortomala Lokni May 21 '18 at 11:49
  • Updated the question. As i understanding, agi works fine, and now starting listening 4573 port, but my application freezing... How i can achieve, that port listening and app works parallel? – Aleksei May 21 '18 at 12:27
  • How do you know the application is freezing? The DefaultAgiServer does not print anything to the console when calls are being connected, you can subclass the DefaultAgiServer and add some log statements for it to print while it runs though. From what you have shared so far, it looks like the AGI server is running without an issue. – Brandon Haugen May 22 '18 at 13:19
  • My application is a web application, so except establishing a socket connection, it should still load all data from database and open it in the browser, which does not happen – Aleksei May 24 '18 at 12:56

1 Answers1

1

Tomcat hang on startup because the AGI server is blocking it and waits for incoming AGI data from socket connection link. To solve this you should wrap your AgiServer in a separate thread so that it runs in the background or use AgiServerThread.

In result my asterisk agi configuration looks like this:

@Bean
public AgiServerThread agiServerThread(){
    AgiServerThread agiServerThread = new AgiServerThread(getDefaultAgiServer());
    agiServerThread.startup();
    return agiServerThread;
}

@Bean
public DefaultAgiServer getDefaultAgiServer(){
    return new DefaultAgiServer(getAsteriskAgiScript());
}

@Bean
public AgiScript getAsteriskAgiScript(){
    return new AsteriskAgi();
}
Aleksei
  • 165
  • 8