Integrating AGI and Apache Tomcat


I’ve already described how the Spring Framework can be used to externalize your AGI configuration. That blog entry asumed you are running your AGI server as a stand alone application. What is the best way to run it within an app server or a servlet container like Tomcat however?

When you just place the snippet from here into your applicationContext.xml you will notice that Tomcat will hang on start up and that you won’t be able to shut it down properly.

The reason for this is that the AGI server is blocking Tomcat and waits for incoming AGI requests. To solve this you have to wrap your AgiServer in a thread so that it runs in the background. Asterisk-Java comes with a utility class called AgiServerThread that just does this.

So the following snippet will work as expected:

<bean class="org.asteriskjava.fastagi.AgiServerThread"
      init-method="startup" destroy-method="shutdown">
    <property name="agiServer" ref="agiServer"/>
</bean>

<bean id="agiServer" class="org.asteriskjava.fastagi.DefaultAgiServer">
    <property name="bindPort" value="4573"/>
    <property name="mappingStrategy">
        <bean class="xxx">
...
        </bean>
    </property>
</bean>

References:

Related posts:

  1. Externalize your AGI Configuration

7 thoughts on “Integrating AGI and Apache Tomcat

  1. Thanks for this great job Stefan,
    I’m voip developer working with AGI and I read your blog about connecting AGI with Tomcat using spring framework and this part is not clear for me, so, please if you could guide me what and how to do the integration with Tomcat.
    Thanks!

  2. Hello
    Thanks for this guide. When using the Spring framework, can you explain what advantages running the AGI server on Tomcat has over running it as a standalone server?

  3. Of course you can also run it as a standalone application. The advantage on using Tomcat as a container is that you can easily provide web based call statistics or integrate with existing web apps.

  4. One downfall of using a standalone FastAGI system is that it is not easily reloadable, if you have to make changes to your asterisk java dialplan then reloading the changes can not be done without restarting the entire asterisk java service. Does incorporating it into tomcat being a resolution to this issue?

  5. Been following this, and implemented this, but can’t get my asterisk server to communitcate to my tomcat server? Any thoughs? The code is exactly the same as what is written above. Do I need to do something on the asterisk side? Of course besides the call to this script?