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 id="agiServer" class="org.asteriskjava.fastagi.DefaultAgiServer">
    <property name="bindPort" value="4573"/>
    <property name="mappingStrategy">
        <bean class="xxx">