9.6.4 Plugging-in your own Web server

 


9.6.4.1 Implementing the HttpServerInterface

9.6.4.2 Handling HTTP Requests

9.6.4.3 Modifying HTML Adaptor Code


 

AdventNet HTML Adaptor uses the Tomcat 3.2.4 Web server. You can plug in any other Web server instead of the Tomcat server. This facility of plugging in a Web server has been enabled by providing the HttpServerInterface. All you have to do to plug in your own Web server is to perform the two steps given below:

  1. Write a class that implements the HttpServerInterface

  2. Call handle() method of HttpRequestHandlerImpl to handle HTTP requests

  3. Modify the agent code to use your interface

These steps are discussed below in detail.

 

9.6.4.1 Implementing the HttpServerInterface

 

The interface for plugging in your Web server must perform the functions such as starting, stopping, restarting the server and setting configuration file.

 

The following methods from the HttpServerInterface must be implemented in the interface you write:

 

startHttpServer

public void startHttpServer()

throws java.lang.Exception

Method to start the WebServer initially.

Throws:

java.lang.Exception - while error starting WebServer.

 

stopHttpServer

public void stopHttpServer()

throws java.lang.Exception

Stops the WebServer.

Throws:

java.lang.Exception - on error while stopping WebServer.

 

restartHttpServer

public void restartHttpServer()

throws java.lang.Exception

Restarts the WebServer.

Throws:

java.lang.Exception - while error trying to restart the WebServer.

 

setConfigFileName

public void setConfigFileName(java.lang.String configFileName)

Setter for the configuration file Name with location.

Parameters:

configFileName - The configuration file name with path.

 

getConfigFileName

public java.lang.String getConfigFileName()

Getter for the configFileName.

Returns:

The configuration file Name by which the Server is running.

 

The AdventNet HTML Adaptor uses HtmlAdaptorServerImpl, which is a default implementation of the HttpServerInterface.

 

9.6.4.2 Handling HTTP Requests

 

The class written in the previous step, which implements the HttpServerInterface, receives the request from the Web server and passes on the details of the request to the HTTP Connector of the agent.  Your Web server must recieve this request, process it and return the result. For this a java class that takes care of request handling for your Web server has to be written.

 

AdventNet HTTP Connector uses the Tomcat Web server. Here, com.adventnet.adaptors.http.httpRequestHandlerImpl class has been written to receive the request from the com.adventnet.adaptors.HttpConnectorServerImpl class and process it and return the result. For more details regarding the httpRequestHandlerImpl class, please refer to the javadocs.  

 

In order to pass on the request to HttpRepuestHandlerImpl, your implementation of the HttpServerInterface must do the following:

9.6.4.3 Modifying HTTP Connector Code

 

Once the class file implementing  the HttpServerInterface is available, the agent code has to be modified to replace the default HttpConnectorServerImpl class with your implementation. The default HttpConnectorServerImpl class basically provides the means to specify and modify the configurations of the Web server and to capture the HTTP requests and processing them.

 

When you plug in your Web server, your interface must perform the same function of the default implementation. To replace HttpConnectorServerImpl with your implementation, change the code (shown in bold) in the registerAdventNetAdaptors() method of the agent main file.

 

httpconnector= new HttpConnector();

httpconnector.setParentDir(agentDir);

 

httpconnector.registerAuthentication(); 

httpconnector.addHttpServerInterface(new HttpConnectorServerImpl());

name = "Adaptors:type=HTTPConnector";

server.registerMBean(httpconnector, new ObjectName(name));