Running TIBCO Enterprise Administrator Agent Library in the Servlet mode

TIBCO Enterprise Administrator provides an abstract servlet that needs to be subclassed to register object instances.

Procedure

  1. Extend the abstract servlet of TIBCO Enterprise Administrator to define the object that needs to be registered.

    The following example code defines only one object to register in the server.

    Note: In the getObjectInstances method, instances of TopLevelTeaObject and TeaObjectProvider must be passed. For example, if you have a class implementing the TeaObject interface, and you write a class that implements a TeaObjectProvider in order to provide an instance of this class, while registering the instance in servlet mode, you must pass the TeaObjectProvider instance instead of the TeaObject instance itself in addition to the TopLevelTeaObject instance.
    public class HelloWorldServlet extends TeaAgentServlet {
    
        /*
         * (non-Javadoc)
         *
         * @see com.tibco.tea.agent.server.TeaAgentServlet#getObjectInstances()
         */
        @Override
        protected Object[] getObjectInstances() throws ServletException {
            return new Object[]{new HelloWorldAgent()};
        }
    }
  2. Configure the servlet with proper parameters using web.xml. Map the agent servlet to /* as further dispatches are done by the servlet.
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4">
    
        <display-name>HelloWorld Agent</display-name>
    
        <servlet>
            <servlet-name>HelloWorldAgent</servlet-name>
            <servlet-class>HelloWorldServlet</servlet-class>
            <init-param>
                <param-name>name</param-name>
                <param-value>HelloWorldAgent</param-value>
            </init-param>
            <init-param>
                <param-name>version</param-name>
                <param-value>1.1</param-value>
            </init-param>
            <init-param>
                <param-name>agent-info</param-name>
                <param-value>HelloWorld Agent</param-value>
            </init-param>
            <init-param>
                <param-name>agent-id</param-name>
                <param-value>HelloWorldAgent</param-value>
            </init-param>
        </servlet>
        <servlet-mapping>
            <servlet-name>HelloWorldAgent</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
    
    </web-app>     
    

    If you deploy the agent as a part of an existing web application, you can have a specific URL pattern matching instead of /* for your agent servlet. For example,

        <init-param>
            <param-name>agent-contextPath</param-name>
            <param-value>/path1/path2</param-value>
        </init-param>
        <servlet-mapping>
            <servlet-name>HelloWorldAgentServlet</servlet-name>
            <url-pattern>/path1/path2/*</url-pattern>
        </servlet-mapping>
  3. Deploy the servlet using the standard servlet container mechanisms. To verify, you can start an embedded Jetty server, with the programmatically deployed servlet. For a standalone agent process, configuration through the server mode is a better approach.
    public static void main(final String[] args) throws Exception {
    							
        Server server = new Server(1234);
        ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/helloworldagent", false, false);
    
        ServletHolder servletHolder = servletContextHandler.addServlet(HelloWorldServlet.class, "/*");
        servletHolder.setInitParameter("name", "HelloWorldAgent");
        servletHolder.setInitParameter("version", "1.1");
        servletHolder.setInitParameter("agent-info", "HelloWorld Agent");
        server.start();
    
        server.join();
    }
    Note: It is recommended that you do not set the load-on-startup flag to false otherwise the servlet is not loaded on startup.