Author: azeez Date: Mon Jan 10 16:28:28 2011 New Revision: 1057261 URL: http://svn.apache.org/viewvc?rev=1057261&view=rev Log: Fix for AXIS2-4500. Suggested by Bhushan Khardekar.
Also did some code alignment since the 1 tab = 4 spaces rule was violated Modified: axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorConstants.java axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorService.java axis/axis2/java/core/trunk/modules/webapp/conf/web.xml Modified: axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorConstants.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorConstants.java?rev=1057261&r1=1057260&r2=1057261&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorConstants.java (original) +++ axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorConstants.java Mon Jan 10 16:28:28 2011 @@ -25,19 +25,24 @@ package org.apache.axis2.soapmonitor.ser public class SOAPMonitorConstants { - /** - * SOAP message types - */ - public static final int SOAP_MONITOR_REQUEST = 0; - public static final int SOAP_MONITOR_RESPONSE = 1; + /** + * SOAP message types + */ + public static final int SOAP_MONITOR_REQUEST = 0; + public static final int SOAP_MONITOR_RESPONSE = 1; - /** - * Servlet initialization parameter names - */ - public static final String SOAP_MONITOR_PORT = "SOAPMonitorPort"; + /** + * Port Servlet initialization parameter + */ + public static final String SOAP_MONITOR_PORT = "SOAPMonitorPort"; - /** - * Unique SOAP monitor id tag - */ - public static final String SOAP_MONITOR_ID = "SOAPMonitorId"; + /** + * Host name Servlet initialization parameter + */ + public static final String SOAP_MONITOR_HOST_NAME = "SOAPMonitorHostName"; + + /** + * Unique SOAP monitor id tag + */ + public static final String SOAP_MONITOR_ID = "SOAPMonitorId"; } Modified: axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorService.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorService.java?rev=1057261&r1=1057260&r2=1057261&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorService.java (original) +++ axis/axis2/java/core/trunk/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet/SOAPMonitorService.java Mon Jan 10 16:28:28 2011 @@ -30,276 +30,291 @@ import javax.servlet.http.HttpServletRes import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.Enumeration; import java.util.Vector; /** - * 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 + * This is a SOAP Monitor Service class. + * <p/> + * 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 + * <p/> + * 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 + * 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 + * <p/> + * Each time a socket connection is established, a new + * thread is created to handle communications from the * applet. - * + * <p/> * 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 + * 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. */ public class SOAPMonitorService extends HttpServlet { - /** - * Private data - */ - private static ServerSocket server_socket = null; - private static Vector connections = null; - - private static final Log log = LogFactory.getLog(SOAPMonitorService.class); - - /** - * Constructor - */ - public SOAPMonitorService() { - } - - - /** - * Publish a SOAP message to listeners - */ - public static void publishMessage(Long id, - Integer type, - String target, - String soap) { - if (connections != null) { - Enumeration e = connections.elements(); - while (e.hasMoreElements()) { - ConnectionThread ct = (ConnectionThread) e.nextElement(); - ct.publishMessage(id,type,target,soap); - } - } - } + /** + * Private data + */ + private static ServerSocket serverSocket = null; + private static Vector connections = null; - /** - * Servlet initialiation - */ - public void init() throws ServletException { - 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) { - log.error("SOAPMonitorService can't find ServletConfig init parameter 'port'"); - port = "0"; - } - try { - // Try to open the server socket - server_socket = new ServerSocket(Integer.parseInt(port)); - } catch (Exception ex) { - // Let someone know we could not open the socket - log.error("Unable to open server socket using port: " + port); - log.error(ex.getMessage(), ex); - // Fail as loudly as possible for those without logging configured - config.getServletContext().log("Unable to open server socket using port "+port+":", ex); - server_socket = null; - } - if (server_socket != null) { - // Start the server socket thread - new Thread(new ServerSocketThread()).start(); - } - } - } + private static final Log log = LogFactory.getLog(SOAPMonitorService.class); - /** - * Servlet termination - */ - public void destroy() { - // 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; + /** + * Constructor + */ + public SOAPMonitorService() { } - } - /** - * HTTP GET request - */ - public void doGet(HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException - { - // Create HTML to load the SOAP monitor applet - int port = 0; - if (server_socket != null) { - port = server_socket.getLocalPort(); - log.debug("Sending param to SOAP monitor applet as port: " + port); - } - 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=org.apache.axis2.soapmonitor.applet.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=org.apache.axis2.soapmonitor.applet.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>"); - } - - /** - * Thread class for handling the server socket - */ - class ServerSocketThread implements Runnable { /** - * Thread for handling the server socket + * Publish a SOAP message to listeners */ - public void run() { - // Wait for socket connections - while (server_socket != null) { - try { - Socket socket = server_socket.accept(); - new Thread(new ConnectionThread(socket)).start(); - } catch (IOException ioe) {} - } + public static void publishMessage(Long id, + Integer type, + String target, + String soap) { + if (connections != null) { + Enumeration e = connections.elements(); + while (e.hasMoreElements()) { + ConnectionThread ct = (ConnectionThread) e.nextElement(); + ct.publishMessage(id, type, target, soap); + } + } } - } - /** - * Thread class for handling socket connections - */ - class ConnectionThread implements Runnable { - - private Socket socket = null; - private ObjectInputStream in = null; - private ObjectOutputStream out = null; - private boolean closed = false; + /** + * Servlet initialiation + */ + public void init() throws ServletException { + if (connections == null) { + // Create vector to hold connection information + connections = new Vector(); + } + if (serverSocket == null) { + // Get the server socket port from the init params + ServletConfig config = super.getServletConfig(); + String hostName = config.getInitParameter(SOAPMonitorConstants.SOAP_MONITOR_HOST_NAME); + String port = config.getInitParameter(SOAPMonitorConstants.SOAP_MONITOR_PORT); + if (port == null) { + log.error("SOAPMonitorService can't find ServletConfig init parameter 'port'"); + port = "0"; + } + try { + if (hostName != null) { + serverSocket = new ServerSocket(Integer.parseInt(port), + 50, + InetAddress.getByName(hostName)); + } else { + serverSocket = new ServerSocket(Integer.parseInt(port)); + } + } catch (Exception ex) { + // Let someone know we could not open the socket + log.error("Unable to open server socket using port: " + port); + log.error(ex.getMessage(), ex); + // Fail as loudly as possible for those without logging configured + config.getServletContext(). + log("Unable to open server socket using port " + port + ":", ex); + serverSocket = null; + } + if (serverSocket != null) { + // Start the server socket thread + new Thread(new ServerSocketThread()).start(); + } + } + } /** - * Constructor + * Servlet termination */ - public ConnectionThread(Socket s) { - socket = s; - try { - // Use object streams for input and output - // - // NOTE: We need to be sure to create and flush the - // output stream first because the ObjectOutputStream - // constructor writes a header to the stream that is - // needed by the ObjectInputStream on the other end - out = new ObjectOutputStream(socket.getOutputStream()); - out.flush(); - in = new ObjectInputStream(socket.getInputStream()); - } catch (Exception e) {} - // Add the connection to our list - synchronized (connections) { - connections.addElement(this); - } + public void destroy() { + // End all connection threads + Enumeration e = connections.elements(); + while (e.hasMoreElements()) { + ConnectionThread ct = (ConnectionThread) e.nextElement(); + ct.close(); + } + // End main server socket thread + if (serverSocket != null) { + try { + serverSocket.close(); + } catch (Exception x) { + } + serverSocket = null; + } } /** - * Close the socket connection + * HTTP GET request */ - public void close() { - closed = true; - try { - socket.close(); - } catch (IOException ioe) {} + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + // Create HTML to load the SOAP monitor applet + int port = 0; + if (serverSocket != null) { + port = serverSocket.getLocalPort(); + log.debug("Sending param to SOAP monitor applet as port: " + port); + } + 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=org.apache.axis2.soapmonitor.applet.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=org.apache.axis2.soapmonitor.applet.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>"); } /** - * Thread to handle the socket connection + * Thread class for handling the server socket */ - public void run() { - try { - while (!closed) { - Object o = in.readObject(); - } - } catch (Exception e) {} - // Cleanup connection list - synchronized (connections) { - connections.removeElement(this); - } - // Cleanup I/O streams - if (out != null) { - try { - out.close(); - } catch (IOException ioe) {} - out = null; - } - if (in != null) { - try { - in.close(); - } catch (IOException ioe) {} - in = null; - } - // Be sure the socket is closed - close(); + class ServerSocketThread implements Runnable { + + /** + * Thread for handling the server socket + */ + public void run() { + // Wait for socket connections + while (serverSocket != null) { + try { + Socket socket = serverSocket.accept(); + new Thread(new ConnectionThread(socket)).start(); + } catch (IOException ioe) { + } + } + } } /** - * Publish SOAP message information + * Thread class for handling socket connections */ - public synchronized void publishMessage(Long id, - Integer message_type, - String target, - String soap) { - // If we have a valid output stream, then - // send the data to the applet - if (out != null) { - try { - switch (message_type.intValue()) { - case SOAPMonitorConstants.SOAP_MONITOR_REQUEST: - out.writeObject(message_type); - out.writeObject(id); - out.writeObject(target); - out.writeObject(soap); - out.flush(); - break; - case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE: - out.writeObject(message_type); - out.writeObject(id); - out.writeObject(soap); - out.flush(); - break; - } - } catch (Exception e) {} - } + class ConnectionThread implements Runnable { + + private Socket socket = null; + private ObjectInputStream in = null; + private ObjectOutputStream out = null; + private boolean closed = false; + + /** + * Constructor + */ + public ConnectionThread(Socket s) { + socket = s; + try { + // Use object streams for input and output + // + // NOTE: We need to be sure to create and flush the + // output stream first because the ObjectOutputStream + // constructor writes a header to the stream that is + // needed by the ObjectInputStream on the other end + out = new ObjectOutputStream(socket.getOutputStream()); + out.flush(); + in = new ObjectInputStream(socket.getInputStream()); + } catch (Exception e) { + } + // Add the connection to our list + synchronized (connections) { + connections.addElement(this); + } + } + + /** + * Close the socket connection + */ + public void close() { + closed = true; + try { + socket.close(); + } catch (IOException ioe) { + } + } + + /** + * Thread to handle the socket connection + */ + public void run() { + try { + while (!closed) { + Object o = in.readObject(); + } + } catch (Exception e) { + } + // Cleanup connection list + synchronized (connections) { + connections.removeElement(this); + } + // Cleanup I/O streams + if (out != null) { + try { + out.close(); + } catch (IOException ioe) { + } + out = null; + } + if (in != null) { + try { + in.close(); + } catch (IOException ioe) { + } + in = null; + } + // Be sure the socket is closed + close(); + } + + /** + * Publish SOAP message information + */ + public synchronized void publishMessage(Long id, + Integer message_type, + String target, + String soap) { + // If we have a valid output stream, then + // send the data to the applet + if (out != null) { + try { + switch (message_type.intValue()) { + case SOAPMonitorConstants.SOAP_MONITOR_REQUEST: + out.writeObject(message_type); + out.writeObject(id); + out.writeObject(target); + out.writeObject(soap); + out.flush(); + break; + case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE: + out.writeObject(message_type); + out.writeObject(id); + out.writeObject(soap); + out.flush(); + break; + } + } catch (Exception e) { + } + } + } } - } } Modified: axis/axis2/java/core/trunk/modules/webapp/conf/web.xml URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/webapp/conf/web.xml?rev=1057261&r1=1057260&r2=1057261&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/webapp/conf/web.xml (original) +++ axis/axis2/java/core/trunk/modules/webapp/conf/web.xml Mon Jan 10 16:28:28 2011 @@ -54,6 +54,10 @@ <param-name>SOAPMonitorPort</param-name> <param-value>5001</param-value> </init-param> + <init-param> + <param-name>SOAPMonitorHostName</param-name> + <param-value>localhost</param-value> + </init-param> <load-on-startup>1</load-on-startup> </servlet -->