Example of using an AGI server in a container like JBoss

Hi All ,

I have found in FAQ page(asterisk-java.org/development/faq.html) of asterisk-java the following question

[quote]Can I have an example of using an AGI server in a container like JBoss?
Yes. Here’s a JBoss EJB3 MBean that creates and destroys an AGI server.[/quote]

and they have given the code for that ,

How to run the and execute the given code and what are the prerequisite steps to do ?

Hi All,
With the help of example giving at the link http://asterisk-java.org/development/faq.html (example of using an AGI server in a container like JBoss), I have created web application which contains of servlet and java class which implements BaseAgiScript.

I have run the web application , it works fine (AGI server starting at port 4573) when i deploy the war file of the web application at jboss server , but when i undeploy the war file , the AGI server will not be shutdown and the AGI server port 4573 will remain open.

Any way to help me to fix this issue ?

TestServlet.java

[code]/**
*
*/
package com.asterisk.example;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.asteriskjava.fastagi.AgiServer;
import org.asteriskjava.fastagi.DefaultAgiServer;

/**

  • @author techbrainless

*/
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
final TestAgi service = new TestAgi();
DefaultAgiServer AGIserver = new DefaultAgiServer(service);

/**
 * @see HttpServlet#HttpServlet()
 */

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */

public void init() throws ServletException {
	System.out.println("Starting the Agi Server at port : "+AGIserver.getPort());
	
	try {
		AGIserver.startup();
	} catch (IllegalStateException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
   }


@Override
public void destroy() {
	System.out.println("Stopping the Agi Server.........");
	AGIserver.shutdown();
	super.destroy();
}

}[/code]

TestAgi.java

[code]package com.asterisk.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;

public class TestAgi extends BaseAgiScript {

public void service(AgiRequest request, AgiChannel chanel)
		throws AgiException {

	// This is my AGI service implementation
	answer();

	sayDigits("1234");
	streamFile("vm-press");
	sayDateTime(1311493265);
	// ...and hangup.
	hangup();
}

}[/code]

Hi All,
Any reply , suggestions…

I doubt anyone else would think of doing it; most wouldn’t even use Java.

Thanks alot david55 for your reply,
All your replies to posts and questions are valuable and I really appreciate you.

Your last reply post encouraged me to search more and I have found a code which close the port of AGIserver once the war file is undeployed

here is the code
TestServlet.java

    package com.asterisk.example;  
      
    import java.io.IOException;  
      
    import javax.servlet.ServletException;  
    import javax.servlet.http.HttpServlet;  
      
    import org.asteriskjava.fastagi.DefaultAgiServer;  
      
      
    public class TestServlet extends HttpServlet{  
      
        /** 
         *  
         */  
        private static final long serialVersionUID = 1L;  
        private static final MyServiceAgi service = new MyServiceAgi();  
        private static final DefaultAgiServer AGIserver = new DefaultAgiServer(  
                service);  
      
      
        public void init() throws ServletException {  
            new Thread(new Runnable() {// This code must be inside a thread  
                // because it stops the owner thread to listen on a specific  
                // port  
                // and this cause your application lock on startup/deploy  
      
                public void run() {  
                    try {  
                        System.out.println("Starting AGIServer");  
                        AGIserver.startup();  
                        System.out.println("AGIServer Started successfully");  
                    } catch (IllegalStateException e) {  
                        e.printStackTrace();  
                    } catch (IOException e) {  
                        e.printStackTrace();  
                    }  
      
                }  
            }).start();  
      
        }  
      
        @Override  
        public void destroy() {  
            AGIserver.shutdown();  
            System.out.println("AGIServer Stopped successfully");  
        }  
      
    }  

Off course dont forget to mark this post as solved.