FileDocCategorySizeDatePackage
SOAPMonitorService.javaAPI DocApache Axis 1.49564Sat Apr 22 18:57:28 BST 2006org.apache.axis.monitor

SOAPMonitorService

public class SOAPMonitorService extends HttpServlet
This is a SOAP Monitor Service class. During the HTTP server startup, the servlet init method is invoked. This allows the code to open a server socket that will be used to communicate with running applets. When an HTTP GET request is received, the servlet dynamically produces an HTML document to load the SOAP monitor applet and supply the port number being used by the server socket (so the applet will know how to connect back to the server). Each time a socket connection is established, a new thread is created to handle communications from the applet. The publishMethod routine is invoked by the SOAP monitor handler when a SOAP message request or response is detected. The information about the SOAP message is then forwared to all current socket connections for display by the applet.
author
Brian Price (pricebe@us.ibm.com) xdoclet tags are not active yet; keep web.xml in sync
web.servlet
name="SOAPMonitorService" display-name="SOAPMonitorService" load-on-startup="100"
web.servlet-mapping
url-pattern="/SOAPMonitor"
web.servlet-init-param
name="SOAPMonitorPort" value="5001"

Fields Summary
private static ServerSocket
server_socket
Private data
private static Vector
connections
Constructors Summary
public SOAPMonitorService()
Constructor


      
    
  
Methods Summary
public voiddestroy()
Servlet termination

    // End all connection threads
    Enumeration e = connections.elements();
    while (e.hasMoreElements()) {
      ConnectionThread ct = (ConnectionThread) e.nextElement();
      ct.close();
    }
    // End main server socket thread
    if (server_socket != null) {
      try {
        server_socket.close();
      } catch (Exception x) {}
      server_socket = null;
    }
  
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
HTTP GET request

   // Create HTML to load the SOAP monitor applet
   int port = 0;
   if (server_socket != null) {
     port = server_socket.getLocalPort();
   }
   response.setContentType("text/html");
   response.getWriter().println("<html>");
   response.getWriter().println("<head>");
   response.getWriter().println("<title>SOAP Monitor</title>");
   response.getWriter().println("</head>");
   response.getWriter().println("<body>");
   response.getWriter().println("<object classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\" width=100% height=100% codebase=\"http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0\">");
   response.getWriter().println("<param name=code value=SOAPMonitorApplet.class>");
   response.getWriter().println("<param name=\"type\" value=\"application/x-java-applet;version=1.3\">");
   response.getWriter().println("<param name=\"scriptable\" value=\"false\">");
   response.getWriter().println("<param name=\"port\" value=\""+port+"\">");
   response.getWriter().println("<comment>");
   response.getWriter().println("<embed type=\"application/x-java-applet;version=1.3\" code=SOAPMonitorApplet.class width=100% height=100% port=\""+port+"\" scriptable=false pluginspage=\"http://java.sun.com/products/plugin/1.3/plugin-install.html\">"); 
   response.getWriter().println("<noembed>"); 
   response.getWriter().println("</comment>"); 
   response.getWriter().println("</noembed>"); 
   response.getWriter().println("</embed>"); 
   response.getWriter().println("</object>");
   response.getWriter().println("</body>");
   response.getWriter().println("</html>");
  
public voidinit()
Servlet initialiation

    if (connections == null) {
      // Create vector to hold connection information
      connections = new Vector();
    }
    if (server_socket == null) {
      // Get the server socket port from the init params
      ServletConfig config = super.getServletConfig();
      String port = config.getInitParameter(SOAPMonitorConstants.SOAP_MONITOR_PORT);
      if (port == null) {
        // No port defined, so let the system assign a port
        port = "0";
      } 
      try {
        // Try to open the server socket
        server_socket = new ServerSocket(Integer.parseInt(port));
      } catch (Exception e) {
        // Let someone know we could not open the socket
        // System. out.println("Unable to open server socket using port "+port+".");
        server_socket = null;
      }
      if (server_socket != null) {
        // Start the server socket thread
        new Thread(new ServerSocketThread()).start();
      }
    }
  
public static voidpublishMessage(java.lang.Long id, java.lang.Integer type, java.lang.String target, java.lang.String soap)
Publish a SOAP message to listeners

    if (connections != null) {
      Enumeration e = connections.elements();
      while (e.hasMoreElements()) {
        ConnectionThread ct = (ConnectionThread) e.nextElement();
        ct.publishMessage(id,type,target,soap);
      }
    }