You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ha...@apache.org on 2006/05/25 11:45:10 UTC

svn commit: r409349 - in /webservices/axis/trunk/c/tests/utils/monitor/org/apache/test: ChildHandler.java MockServer.java MockServerThread.java StopMockServer.java StopTCPMonitor.java TCPMonitor.java TestClientListener.java TestClientThread.java

Author: hawkeye
Date: Thu May 25 02:45:09 2006
New Revision: 409349

URL: http://svn.apache.org/viewvc?rev=409349&view=rev
Log:
Changed Monitor and MockServer to be ANT tasks. Because.. On win XP (sp2 only) the system was running out of sockets. The best way around this was for the MockServer and Monitor to limit the number of times they created server sockets per test run. So, now the MockServer and Monitor are only created once per test-run. On a per-test basis they are flushed and re-freshed. At the end of the test-run they are terminated.

Removed:
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/StopMockServer.java
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/StopTCPMonitor.java
Modified:
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ChildHandler.java
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServer.java
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServerThread.java
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ChildHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ChildHandler.java?rev=409349&r1=409348&r2=409349&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ChildHandler.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ChildHandler.java Thu May 25 02:45:09 2006
@@ -11,12 +11,12 @@
  * Connection handlers handleconnections and have a common goal of ensuring that they are 
  * all closed when they need to be
  */
-public abstract class ChildHandler
+public abstract class ChildHandler extends org.apache.tools.ant.Task
 {
     protected Vector children;
     protected ChildHandler()
     {
-        System.out.println( "Constructing "+this);
+//        System.out.println( "Constructing "+this);
         children=new Vector();
         
     }
@@ -27,7 +27,7 @@
      */
     protected void close()
     {
-        System.out.println( "Closing "+this);
+//        System.out.println( "Closing "+this);
         try 
         {
             if(children!=null)
@@ -48,7 +48,7 @@
             }
             }
             children=null;
-            System.out.println( "Closed "+this);
+//            System.out.println( "Closed "+this);
         }
         catch (Throwable exception)
         {
@@ -68,7 +68,7 @@
     }
     public void finalize()throws Throwable
     {
-        System.out.println( "Destroying: "+this);
+//        System.out.println( "Destroying: "+this);
         super.finalize();
     }
 }

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServer.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServer.java?rev=409349&r1=409348&r2=409349&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServer.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServer.java Thu May 25 02:45:09 2006
@@ -21,12 +21,11 @@
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.net.SocketException;
 import java.net.SocketTimeoutException;
-import java.rmi.server.SocketSecurityException;
 import java.util.Vector;
 
-import javax.net.SocketFactory;
+
+import org.apache.tools.ant.BuildException;
 
 /**
  * This class sits listening on a port. When a client connects to it it returns a predefined response
@@ -36,14 +35,20 @@
 
 public class MockServer extends ChildHandler implements Runnable 
 {
+    private static MockServer singleton;
+    
     private static int SOCKET_TIMEOUT = 700000;
     // The port that we will listen on for the client to connect to
     private int           port;
+    private String responseFileName;
     // File that contains the http responses that the client is expecting back.
     private File          responseFile;
     private boolean       continueToRun =true;
     ServerSocket serverSocket;
     
+    // When this is an ANT task - whether to stop the current MockServer or not.
+    private boolean stop; 
+    
     public static final void printUsage( )
     {
         System.out.println("Usage: java MockServer -p <port> -r <responseFile>");
@@ -51,7 +56,7 @@
         System.out.println("responseFile: The file to write out when a request is received");
     }
 
-    public static void main(String[] args)
+/**    public static void main(String[] args)
     {
         // check that we have the required params
         if (args.length<2)
@@ -61,9 +66,34 @@
         }
 
         // We have the params now let's run the server !
+        int port=0;
+        String fileName=null;
         try
         {
-            MockServer server=new MockServer(args);
+            for(int i=0; i<args.length; i++)
+            {
+                if (args[i].equalsIgnoreCase("-p"))
+                {
+                    String portString=args[++i];
+                    try
+                    {
+                        port = Integer.parseInt(portString);
+                        continue;
+                    }
+                    catch (NumberFormatException numberFormatException)
+                    {
+                        printUsage( );
+                        throw new NumberFormatException("port is not an integer " +portString);
+                    }
+                }
+                if (args[i].equals("-r"))
+                {
+                    fileName= args[++i];
+                    continue;
+                }
+            }
+
+            MockServer server=new MockServer(fileName, port);
             Thread serverThread=new Thread(server);
             serverThread.start( );
         }
@@ -74,52 +104,109 @@
             throw new RuntimeException("Failed to start MockServer due to IOException: "+ioException);
         }
     }
+*/
 
-
-
-
-    /**
-     * @param the arguments as they were passed into main
-     */
-    public MockServer(String[] arguments) throws IOException ,
-            NumberFormatException
+    public MockServer()
+    {
+        System.out.println( "MockServer()");
+    }
+    public void execute() throws BuildException
     {
-        for(int i=0; i<arguments.length; i++)
+        // If we are closing then get the singleton and close it
+        if(isStop())
+        {
+            System.out.println( "Closing the mockServer in ANT");
+            if(singleton!=null)
+            {
+                singleton.close();
+            }
+            else
+            {
+                throw new RuntimeException( "Been told to close the MockServer but there isn't one");
+            }
+        }
+        else
         {
-            if (arguments[i].equalsIgnoreCase("-p"))
+            if(singleton==null)
             {
-                String portString=arguments[++i];
                 try
                 {
-                    port=Integer.parseInt(portString);
-                    continue;
+                    singleton = new MockServer(responseFileName, port);
+                    Thread serverThread=new Thread(singleton);
+                    serverThread.start( );
                 }
-                catch (NumberFormatException numberFormatException)
+                catch(IOException exception)
                 {
-                    printUsage( );
-                    throw new NumberFormatException("port is not an integer " +portString);
+                    throw new BuildException("MockServer threw IOException: "+exception);
                 }
             }
-            if (arguments[i].equals("-r"))
+            else
             {
-                responseFile=new File(arguments[++i]);
-                continue;
+                // This means we should reset the current singletons files
+                try
+                {
+                    System.out.println( "MockServer; resetting the response file");
+                    singleton.reset(responseFileName);
+                }
+                catch(IOException exception)
+                {
+                    //throw new 
+                }
             }
+        }
+                
+    }
 
-            // check the responsefile is there
-            if (!this.responseFile.canRead( ))
-            {
-                throw new IOException("Can't read the response file <"
-                        +responseFile+">");
-            }
+    /**
+     * This method closes the current response file and opens up a new one
+     * @param responseFileName
+     */
+    private void reset(String responseFileName)throws IOException
+    {
+        // close all the connections we got from the client
+        super.close();
+        // unfortunately super.close is an unnatural act so we'll have to recreate the children vector
+        children = new Vector();
+        this.responseFileName = responseFileName;
+        // deal with the responsefile first
+        responseFile=new File(responseFileName);
+        // check the responsefile is there
+        if (!this.responseFile.canRead( ))
+        {
+            throw new IOException("Can't read the response file <"
+                    +responseFile+">");
+        }
+        
+        // now deal with the port and threads
+        // cache the response file (this is a necessary optimisation - if the file is big then the connection blows)
+        MockServerThread.cacheResponseFile(responseFile);
+    }
+
+    /**
+     * 
+     */
+    private MockServer( String responseFileName, int port) throws IOException
+    {
+        System.out.println( "MockServer(responseFile, port)");
+        this.port =port;
+        this.responseFileName = responseFileName;
+        // deal with the responsefile first
+        responseFile=new File(responseFileName);
+        // check the responsefile is there
+        if (!this.responseFile.canRead( ))
+        {
+            throw new IOException("Can't read the response file <"
+                    +responseFile+">");
         }
+        
+        // now deal with the port and threads
         // cache the response file (this is a necessary optimisation - if the file is big then the connection blows)
         MockServerThread.cacheResponseFile(responseFile);
 
         // no point in going on if we can;'t create a server socket
-        serverSocket = TCPMonitor.getServerSocket(port);
-        serverSocket.setReuseAddress(true);
+        //serverSocket = TCPMonitor.getServerSocket(port);
     }
+    
 
 
     /*
@@ -131,22 +218,33 @@
      */
     public void run( )
     {
-        System.out.println("MockServer listening on port: "+port);
+        System.out.println("MockServer listening on port: "+getPort());
         System.out.println("Returning Output file: "+responseFile);
+        System.out.println( "singleton="+singleton);
         Socket incoming=null;
+        try
+        {
+            serverSocket = TCPMonitor.getServerSocket(port);
+        }
+        catch(IOException exception)
+        {
+            exception.printStackTrace();
+            continueToRun=false;
+        }
 
         do
         {
             try
             {
                 System.out.println("Mockserver#run(): About to wait for incoming client request");
+                incoming=null;
                 incoming=serverSocket.accept( );
 
                 // Set keep-alive option to ensure that if server crashes we do not 
                 // hang waiting on TCP/IP response.
-                incoming.setKeepAlive(true);
+//                incoming.setKeepAlive(true);
                 
-                System.out.println("Mockserver#run(): Got a new client request");
+//                System.out.println("Mockserver#run(): Got a new client request");
             }
             catch (SocketTimeoutException socketTimeoutException)
             {
@@ -156,11 +254,18 @@
             }
             catch (IOException exception)
             {
-                // uh oh !
-                System.err
-                        .println("IOException when accepting a client request on the serverSocket");
-                exception.printStackTrace(System.err);
-                continueToRun=false;
+                if(continueToRun)
+                {
+                    // uh oh !
+                    System.err
+                        	.println("IOException when accepting a client request on the serverSocket");
+                    exception.printStackTrace(System.err);
+                    continueToRun=false;
+                }
+                else
+                {
+                    // that's fine we're stopping
+                }
             }
             
             if (incoming!=null)
@@ -185,12 +290,13 @@
             }
         }
         while (continueToRun);
-        
-        close();
     }
     
     protected void close()
     {
+        System.out.println( "Closing MockServer");
+        continueToRun=false;
+        singleton=null;
         // clean up
         try
         {
@@ -203,6 +309,55 @@
         }
         
         super.close();
+    }
+
+    /**
+     * @param stop The stop to set.
+     */
+    public void setStop(boolean stop)
+    {
+        this.stop=stop;
+    }
+
+    /**
+     * @return Returns the stop.
+     */
+    public boolean isStop( )
+    {
+        return stop;
+    }
+
+    /**
+     * @param port The port to set.
+     */
+    public void setPort(int port)
+    {
+        this.port=port;
+    }
+
+    /**
+     * @return Returns the port.
+     */
+    public int getPort( )
+    {
+        return port;
+    }
+
+    /**
+     * @param responseFileName The responseFileName to set.
+     */
+    public void setResponseFileName(String responseFileName)
+    {
+        System.out.println( "Setting response file to "+responseFileName);
+        this.responseFileName=responseFileName;
+    }
+
+    /**
+     * @return Returns the responseFileName.
+     */
+    public String getResponseFileName( )
+    {
+        return responseFileName;
     }
 }
  

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServerThread.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServerThread.java?rev=409349&r1=409348&r2=409349&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServerThread.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServerThread.java Thu May 25 02:45:09 2006
@@ -24,7 +24,6 @@
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.net.Socket;
-import java.net.SocketException;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
@@ -35,12 +34,15 @@
  * This class is responsible for handling the socket from the client.
  */
 public class MockServerThread extends ChildHandler implements Runnable
-{
+{    
+    public static final String STOPMOCKSERVER_STRING ="STOPMOCKSERVER";
+
     // NOTE: We read in this string plus two bytes (the end of the request)
     private static String   ENVELOPE_TAG    ="</SOAP-ENV:Envelope>";
     private static String   MIME_BOUNDARY   ="MIME_BOUNDARY";
 
     private static int      CHARBUFFER_SIZE =32768; // 32K
+    private boolean continueToRun;
 
     // Only store the socket so we can close it
     private Socket socket;
@@ -61,7 +63,7 @@
         inputStream = null;
         outputStream = null;
         this.socket = socket; 
-        setSocketTimeouts();
+//        setSocketTimeouts();
         
         try
         {
@@ -99,6 +101,9 @@
     }
 
     /**
+     * NOTE: THIS METHOD IS NOT REQUIRED ANYMORE. NOW THAT THE MOCKSERVER IS AN ANTTASK
+     * THE ANTTASK AND EXECUTE METOHDS ARE USED. HOWEVER, SO AS NOT TO REWRITE THIS
+     * CLASS I LEFT THIS METHOD IN  - IT'S STILL CALLED BUT WILL NEVER FIND THE STRING.
      * This program is made to stop when it receives a specific stop message.
      * This method checks for that message and throws a StopRequestException if
      * it finds that it's been given it
@@ -108,18 +113,18 @@
     {
         // Read in the first few bytes of the message to see if it's a stop
         // message
-        char[] charBuffer=new char[StopMockServer.STOPMOCKSERVER_STRING.length( )];
+        char[] charBuffer=new char[STOPMOCKSERVER_STRING.length( )];
         int totalBytesRead=0;
         String message="";
         int bytesRead=0;
         System.out.println("MockServerThread#run():About to wait for stop msg");
         System.out.println("----------------------------------MockServer Thread new Request------------------------");
 
-        while (totalBytesRead<StopMockServer.STOPMOCKSERVER_STRING.length( ))
+        while (totalBytesRead<STOPMOCKSERVER_STRING.length( ))
         {
             try
             {
-                bytesRead=inputStream.read(charBuffer, 0, StopMockServer.STOPMOCKSERVER_STRING.length( ));
+                bytesRead=inputStream.read(charBuffer, 0, STOPMOCKSERVER_STRING.length( ));
                 System.out.println("MockServerThread#run(): Got some bytes: " +bytesRead);
             }
             catch (IOException exception)
@@ -140,7 +145,7 @@
             }
         }
 
-        if (message.equals(StopMockServer.STOPMOCKSERVER_STRING))
+        if (message.equals(STOPMOCKSERVER_STRING))
         {
             // we've been told to stop
             System.out.println("--------------------------------------------------------------------");
@@ -160,6 +165,7 @@
      */
     public void run( )
     {
+        continueToRun=true;
         int bytesRead=0;
         char[] charBuffer=new char[CHARBUFFER_SIZE];
         try
@@ -241,6 +247,8 @@
     public static void cacheResponseFile(File responseFile)
             throws FileNotFoundException, IOException
     {
+        // If we already have a set of responses then they will be cleared later on
+        
         // open the response file for reading in
         FileReader reader=new FileReader(responseFile);
         BufferedReader responseFileStream=new BufferedReader(reader);
@@ -347,6 +355,7 @@
             responses[i - 1] = new Response( newResponse);
         }
         reader.close();
+        requests=0;
         System.out.println( "MockServer got " + (responses.length - 1) + " responses");
     }
    
@@ -362,6 +371,7 @@
     {
         try
         {
+            closedConnection=true;
             socket.close();
         }
         catch(IOException exception)
@@ -398,11 +408,11 @@
     {
         return responses;
     }
-    private void setSocketTimeouts() throws SocketException
-    {
-        socket.setKeepAlive(false);
-        socket.setReuseAddress(true);
-        socket.setSoLinger(false, 1);
-        
-    }
+//    private void setSocketTimeouts() throws SocketException
+//    {
+//        socket.setKeepAlive(false);
+//        socket.setReuseAddress(true);
+//        socket.setSoLinger(false, 1);
+//        
+//    }
 }

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java?rev=409349&r1=409348&r2=409349&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java Thu May 25 02:45:09 2006
@@ -23,39 +23,148 @@
 import java.net.Socket;
 import java.net.SocketException;
 
+import org.apache.tools.ant.BuildException;
+
 /**
- * @author perryan,hawkeye 
- * This class is designed to listen on a given port and send the
- * request received on that port to the given RequestHandler. This class
- * is meant to be used in a test suite scenario. where an instance of
- * this class is created per call to a test.
+ * @author perryan,hawkeye This class is designed to listen on a given port and
+ *         send the request received on that port to the given RequestHandler.
+ *         This class is meant to be used in a test suite scenario. where an
+ *         instance of this class is created per call to a test.
  */
 public class TCPMonitor extends ChildHandler
 {
+    private String                requestFile, responseFile;
+    private int                   listenerPort, servicePort;
+    private String                serviceHost;
+    // whether this call to execute should stop the monitor or not
+    private boolean               stop;
+
+    // Whether this call to execute should just flush and close the files
+    private boolean               flush;
+
+    protected static TCPMonitor   singleton              =null;
+    private static BufferedWriter requestFileWriter;
+    private static BufferedWriter responseFileWriter;
+    private static boolean        responseFileWriterOpen =false;
+    //  private static TestClientListener testClientListener =null;
+
+    public static final int       OPENING_STATE          =0;
+    public static final int       OPENED_STATE           =0;
+    public static final int       CLOSING_STATE          =0;
+    public static final int       CLOSED_STATE           =0;
+
+    public static int             state;
+
+    /**
+     * Standard constructor required to be an ANT task.
+     */
+    public TCPMonitor( )
+    {
+        System.out.println("TCPMonitor()");
+    }
+
+    public void execute( )
+    {
+        if (stop)
+        {
+            System.out.println("STOPping TCPMonitor");
+            getInstance( ).close( );
+        }
+        else
+        {
+            if (isFlush( ))
+            {
+                System.out.println("Flushing and closing the TCPmonitor files");
+                getInstance( ).flushAndCloseFiles( );
+            }
+            else
+            {
+                try
+                {
+                    if (getInstance( )!=null)
+                    {
+                        System.out.println( "Resetting requeest and responsefiles");
+                        getInstance( ).setRequestFile(requestFile);
+                        getInstance( ).setResponseFile(responseFile);
+                        try
+                        {
+                            getInstance().attachToFiles();
+                        }
+                        catch (IOException e)
+                        {
+                            throw new BuildException("couldn't attach to Files: ", e);
+                        }
+                    }
+                    else
+                    {
+                    }
+                }
+                catch (RuntimeException exception)
+                {
+                    // this *usually* occurs when the instance has not been
+                    // created so create a new one !
+                    try
+                    {
+                        System.out.println("Starting TCPMonitor !");
+                        getInstance(getListenerPort( ), getServiceHost( ),
+                                getServicePort( ), getRequestFile( ),
+                                getResponseFile( ));
+                        System.out.println("Executed tcpmon");
+                    }
+                    catch (IOException exception2)
+                    {
+                        exception2.printStackTrace( );
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 
+     */
+    private void flushAndCloseFiles( )
+    {
+        try
+        {
+            requestFileWriter.flush( );
+            requestFileWriter.close( );
+        }
+        catch (IOException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace( );
+        }
 
-    protected static TCPMonitor         singleton              =null;
-    private static BufferedWriter     requestFileWriter;
-    private static BufferedWriter     responseFileWriter;
-    private static boolean            responseFileWriterOpen =false;
-  //  private static TestClientListener testClientListener     =null;
-    
-    
-    public static final int OPENING_STATE=0;
-    public static final int OPENED_STATE=0;
-    public static final int CLOSING_STATE=0;
-    public static final int CLOSED_STATE=0;
-    
-    public static int state;
+        try
+        {
+            responseFileWriter.flush( );
+            responseFileWriter.close( );
+        }
+        catch (IOException e1)
+        {
+            // TODO Auto-generated catch block
+            e1.printStackTrace( );
+        }
+    }
 
-    
     /**
-     * This method is used by monitors that don't use http e.g. MQ.
+     * This constructor is used by monitors that don't use http e.g. MQ.
+     * 
      * @param requestFile
      * @param responseFile
      */
-    protected TCPMonitor(String requestFile, String responseFile)throws IOException
+    protected TCPMonitor(String requestFile, String responseFile)
+            throws IOException
+    {
+        System.out.println("TCPMonitor(req, res)");
+        state=OPENING_STATE;
+        this.requestFile = requestFile;
+        this.responseFile = responseFile;
+        attachToFiles();
+    }
+    private void attachToFiles()throws IOException
     {
-        state = OPENING_STATE;
         try
         {
             requestFileWriter=new BufferedWriter(new FileWriter(requestFile));
@@ -85,6 +194,7 @@
         }
         
     }
+
     /**
      * Creates a new TCPMonitor listening on the given port for incoming
      * requests (this is always on localhost of course!)
@@ -97,15 +207,16 @@
             String requestFile, String responseFile) throws IOException
     {
         this(requestFile, responseFile);
+        System.out.println("TCPMonitor(port, host, port, req, res)");
         /*
          * Create a thread which listens for incoming requests
          */
-        TestClientListener testClientListener= new TestClientListener(listenerPort, serviceHost,
-                servicePort);
+        TestClientListener testClientListener=new TestClientListener(
+                listenerPort, serviceHost, servicePort);
         addChild(testClientListener);
         Thread testClientListenerThread=new Thread(testClientListener);
         testClientListenerThread.start( );
-        state = OPENED_STATE;
+        state=OPENED_STATE;
     }
 
     public static TCPMonitor getInstance( )
@@ -123,13 +234,16 @@
     {
         if (singleton==null)
         {
+            System.out.println("SINGLETON==null");
             singleton=new TCPMonitor(listenerPort, serviceHost, servicePort,
                     requestFile, responseFile);
         }
+        else
+        {
+            System.out.println("SINGLETON != null");
+        }
         return singleton;
     }
-    
-    
 
     public void writeRequest(char[] buffer, int howManyChars)
     {
@@ -157,10 +271,9 @@
             e.printStackTrace( );
         }
     }
-    
+
     public static void main(String[] args)
     {
-
         try
         {
             int listener_port=0;
@@ -168,13 +281,14 @@
             String forward_host="";
             String request_file="";
             String response_file="";
-            String serverResponse_file = null;
+            String serverResponse_file=null;
             for(int i=0; i<args.length; i++)
             {
                 if (args[i].equalsIgnoreCase("-l"))
                 {
                     listener_port=Integer.parseInt(args[++i]);
-                    System.out.println( "TCPMonitor Listening on port "+listener_port);
+                    System.out.println("TCPMonitor Listening on port "
+                            +listener_port);
                     continue;
                 }
                 if (args[i].equalsIgnoreCase("-p"))
@@ -218,12 +332,13 @@
             exception.printStackTrace( );
         }
     }
-    
-    public void close()
+
+    public void close( )
     {
         // close() should flush() the streams but let's just be sure !
-        System.out.println( "TCPMonitor#close(): Flushing and closing the output files");
-        state = CLOSING_STATE;
+        System.out
+                .println("TCPMonitor#close(): Flushing and closing the output files");
+        state=CLOSING_STATE;
         IOException exception=null;
         try
         {
@@ -237,7 +352,7 @@
         {
             exception=ioException;
         }
-        catch(NullPointerException nullPointerException)
+        catch (NullPointerException nullPointerException)
         {
             nullPointerException.printStackTrace(System.err);
         }
@@ -250,50 +365,160 @@
             exception.printStackTrace(System.err);
         }
         // System.out.println( "About to call super.close");
-        super.close();
+        super.close( );
         // System.out.println( "called super.close");
-        state = CLOSED_STATE;
+        state=CLOSED_STATE;
     }
 
-
     /**
      * @param hostname
      * @param port
      * @return a connected socket
      */
-    public static Socket getClientSocket(String hostname, int port)throws SocketException, IOException
+    public static Socket getClientSocket(String hostname, int port)
+            throws SocketException, IOException
     {
-		Socket socket = new Socket();
-		InetSocketAddress remoteAddress = new InetSocketAddress(hostname, port);
-        
-        // Set keep-alive option to ensure that if server crashes we do not 
+        Socket socket=new Socket( );
+        InetSocketAddress remoteAddress=new InetSocketAddress(hostname, port);
+
+        // Set keep-alive option to ensure that if server crashes we do not
         // hang waiting on TCP/IP response.
-		socket.setKeepAlive(true);
-        
-        // No reason to set reuse-address since client sockets are not binding to 
-        // some explicit address.  Also, setting this to true causes problems on OS/400.
-		// socket.setReuseAddress(true);
-                
-		socket.connect(remoteAddress);
-		
-		return socket;
-		
-    }
+        socket.setKeepAlive(true);
 
+        // No reason to set reuse-address since client sockets are not binding
+        // to
+        // some explicit address. Also, setting this to true causes problems on
+        // OS/400.
+        socket.setReuseAddress(true);
+
+        socket.connect(remoteAddress);
+
+        return socket;
+    }
 
     /**
      * @param port
      * @return
      */
-    public static ServerSocket getServerSocket(int port)throws IOException
+    public static ServerSocket getServerSocket(int port) throws IOException
     {
-        ServerSocket socket = new ServerSocket();
-        socket.setReuseAddress(true);
-        InetSocketAddress sockAddress = new InetSocketAddress(port);
-        socket.bind(sockAddress);
+        ServerSocket socket=new ServerSocket( );
+        //socket.setReuseAddress(true);
+        InetSocketAddress sockAddress=new InetSocketAddress(port);
+        socket.bind(sockAddress, 3000);
         return socket;
     }
-    
-    
+
+    /**
+     * @param requestFile The requestFile to set.
+     */
+    public void setRequestFile(String requestFile)
+    {
+        this.requestFile=requestFile;
+    }
+
+    /**
+     * @return Returns the requestFile.
+     */
+    public String getRequestFile( )
+    {
+        return requestFile;
+    }
+
+    /**
+     * @param responseFile The responseFile to set.
+     */
+    public void setResponseFile(String responseFile)
+    {
+        this.responseFile=responseFile;
+    }
+
+    /**
+     * @return Returns the responseFile.
+     */
+    public String getResponseFile( )
+    {
+        return responseFile;
+    }
+
+    /**
+     * @param listenerPort The listenerPort to set.
+     */
+    public void setListenerPort(int listenerPort)
+    {
+        this.listenerPort=listenerPort;
+    }
+
+    /**
+     * @return Returns the listenerPort.
+     */
+    public int getListenerPort( )
+    {
+        return listenerPort;
+    }
+
+    /**
+     * @param servicePort The servicePort to set.
+     */
+    public void setServicePort(int servicePort)
+    {
+        this.servicePort=servicePort;
+    }
+
+    /**
+     * @return Returns the servicePort.
+     */
+    public int getServicePort( )
+    {
+        return servicePort;
+    }
+
+    /**
+     * @param serviceHost The serviceHost to set.
+     */
+    public void setServiceHost(String serviceHost)
+    {
+        this.serviceHost=serviceHost;
+    }
+
+    /**
+     * @return Returns the serviceHost.
+     */
+    public String getServiceHost( )
+    {
+        return serviceHost;
+    }
+
+    /**
+     * @param stop The stop to set.
+     */
+    public void setStop(boolean stop)
+    {
+        this.stop=stop;
+    }
+
+    /**
+     * @return Returns the stop.
+     */
+    public boolean isStop( )
+    {
+        return stop;
+    }
+
+    /**
+     * @param flush The flush to set.
+     */
+    public void setFlush(boolean flush)
+    {
+        this.flush=flush;
+    }
+
+    /**
+     * @return Returns the flush.
+     */
+    public boolean isFlush( )
+    {
+        return flush;
+    }
 }
 

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java?rev=409349&r1=409348&r2=409349&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java Thu May 25 02:45:09 2006
@@ -76,6 +76,8 @@
         //        }
         while (stayAlive==true)
         {
+            // ensure clientSocket is an indicator of whether we got a new connection or not
+            clientSocket=null;
             try
             {
                 System.out
@@ -96,12 +98,15 @@
             }
             catch (IOException exception)
             {
+                if(stayAlive)
+                {
                 System.err
                         .println("IOException when accepting a connection from the client: "
                                 +exception);
                 throw new RuntimeException(
                         "IOException when accepting a connection from the client: "
                                 +exception);
+                }
             }
 
             if (clientSocket!=null)
@@ -186,24 +191,24 @@
                 }
             }
         }
-        // We've been told to stop
-        // Tell the Monitor to stop writing things out and to tidy itself up
-        // the tcpmon will call our close method in a second
-        TCPMonitor.getInstance().close( );
     }
     protected void close()
     {
+        // ensure that when we close the serversocket (which causes an ioexception) that we know it was us
+        stayAlive=false;
         try
         {
             if(serverSocket!=null)
             {
+                // closing the server socket will enable us to break out of the loop with an IOException
+                // but this will be abosrbed becuase we reminded ourselves that we are closing
                 serverSocket.close();
             }
         }
         catch(IOException exception)
         {
             // swallow exceptions on close
-            // exception.printStackTrace(System.err);
+            exception.printStackTrace(System.err);
         }
         super.close();
     }

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java?rev=409349&r1=409348&r2=409349&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java Thu May 25 02:45:09 2006
@@ -27,6 +27,8 @@
  */
 public class TestClientThread extends ChildHandler implements Runnable
 {
+    public static final String STOPTCPMON_STRING ="STOPTCPMON";
+
     private boolean          continueToRun                 =true;
     private boolean serverClosedSocket;
     // the responder back to the client
@@ -118,7 +120,7 @@
         try
         {
             bytesRead=clientRequestStream.read(readBuffer, 0,
-                    StopTCPMonitor.STOPTCPMON.length( ));
+                    STOPTCPMON_STRING.length( ));
         }
         catch (ConnectException connectException)
         {
@@ -150,7 +152,7 @@
         if (bytesRead!=-1)
         {
             String inputLine=new String(readBuffer, 0, bytesRead);
-            if (inputLine.startsWith(StopTCPMonitor.STOPTCPMON))
+            if (inputLine.startsWith(STOPTCPMON_STRING))
             {
                 clientRequestStream=null;
                 throw new StopRequestException(
@@ -276,6 +278,8 @@
             try
             {
                 serviceSocket=TCPMonitor.getClientSocket(serviceHostName, servicePort);
+                System.out.println( "TestClientThread: local addr="+serviceSocket.getLocalPort());
+
             }
             catch (UnknownHostException unknownHostException)
             {
@@ -285,7 +289,7 @@
             catch (ConnectException connectException)
             {
                 System.err
-                        .println("ConnectionException when Monitor connecting to server "
+                        .println("ConnectionException when Monitor connecting to server <"+serviceHostName+":"+servicePort+">"
                                 +connectException.getMessage( ));
                 connectException.printStackTrace(System.err);
                 throw new ConnectionNotEstablishedException(connectException);



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org