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/17 17:42:21 UTC

svn commit: r407288 - in /webservices/axis/trunk/c/tests/utils/monitor/org/apache/test: ChildHandler.java ClientReturner.java MockServerThread.java TCPMonitor.java TestClientThread.java

Author: hawkeye
Date: Wed May 17 08:42:20 2006
New Revision: 407288

URL: http://svn.apache.org/viewvc?rev=407288&view=rev
Log:
Made the MockServer more flexible so other versions that use diff transports can use this one as a base

Modified:
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ChildHandler.java
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.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/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=407288&r1=407287&r2=407288&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 Wed May 17 08:42:20 2006
@@ -27,9 +27,11 @@
      */
     protected void close()
     {
-        // System.out.println( "Closing "+this);
+        System.out.println( "Closing "+this);
         try 
         {
+            if(children!=null)
+            {
             for(int i=0; i<children.size(); i++)
             {
                 ChildHandler child = (ChildHandler)children.remove(i);
@@ -44,8 +46,9 @@
                     //exception.printStackTrace( );
                 }                
             }
+            }
             children=null;
-            // System.out.println( "Closed "+this);
+            System.out.println( "Closed "+this);
         }
         catch (Throwable exception)
         {

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java?rev=407288&r1=407287&r2=407288&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java Wed May 17 08:42:20 2006
@@ -18,6 +18,7 @@
 import java.io.*;
 import java.net.*;
 
+
 /**
  * ClientReturner handles the response 
  * from the server to the original requestor.
@@ -34,7 +35,7 @@
     private Socket serviceSocket;
     // We hold on to our parent so we can tell it that the server has closed the socket and not to be alarmed when we close the socket to the client
     private TestClientThread parent;
-    boolean                  continueToRun        =true;
+    protected boolean                  continueToRun        =true;
     private static int       number               =0;
 
     // the response from the server
@@ -48,11 +49,14 @@
      * Null constructor used by anyone who overrides this class
      *
      */
-    protected ClientReturner()
-    {}
+    protected ClientReturner(TestClientThread ourParent)
+    {
+        this.parent = ourParent;
+    }
 
-    protected ClientReturner(Socket clientSocket) throws IOException
+    protected ClientReturner(Socket clientSocket, TestClientThread ourParent) throws IOException
     {
+        this(ourParent);
         number++;
         streamToClient=new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream( )));
     }
@@ -65,13 +69,13 @@
     public ClientReturner(Socket clientSocket, Socket serviceSocket, TestClientThread ourParent)
             throws IOException
     {
-        this(clientSocket);
-        parent = ourParent;
+        this(clientSocket,ourParent);
         //        System.out.println( "ClientReturner(): entry");
         // create the reader from the server
         this.serviceSocket = serviceSocket;
         serverResponseStream=new BufferedReader(new InputStreamReader(serviceSocket.getInputStream( )));
     }
+
 
     /**
      * Reads the request from the client and if of a valid format will extract

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=407288&r1=407287&r2=407288&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 Wed May 17 08:42:20 2006
@@ -238,7 +238,7 @@
         return (Response) responses[requests++];
     }
 
-    static void cacheResponseFile(File responseFile)
+    public static void cacheResponseFile(File responseFile)
             throws FileNotFoundException, IOException
     {
         // open the response file for reading in
@@ -394,6 +394,10 @@
         super.close();
     }
 
+    public static Response[] getResponses()
+    {
+        return responses;
+    }
     private void setSocketTimeouts() throws SocketException
     {
         socket.setKeepAlive(false);

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=407288&r1=407287&r2=407288&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 Wed May 17 08:42:20 2006
@@ -49,6 +49,43 @@
 
     
     /**
+     * This method is used by monitors that don't use http e.g. MQ.
+     * @param requestFile
+     * @param responseFile
+     */
+    protected TCPMonitor(String requestFile, String responseFile)throws IOException
+    {
+        state = OPENING_STATE;
+        try
+        {
+            requestFileWriter=new BufferedWriter(new FileWriter(requestFile));
+        }
+        catch (IOException exception)
+        {
+            System.err
+                    .println("IOEXCeption when creating filewriter to requestfile: "
+                            +exception);
+            throw exception;
+        }
+        if (!responseFile.equals(""))
+        {
+            try
+            {
+                responseFileWriter=new BufferedWriter(new FileWriter(
+                        responseFile));
+            }
+            catch (IOException exception)
+            {
+                System.err
+                        .println("IOException when creating writer to response file: "
+                                +exception);
+                throw exception;
+            }
+            responseFileWriterOpen=true;
+        }
+        
+    }
+    /**
      * Creates a new TCPMonitor listening on the given port for incoming
      * requests (this is always on localhost of course!)
      * 
@@ -59,34 +96,7 @@
     protected TCPMonitor(int listenerPort, String serviceHost, int servicePort,
             String requestFile, String responseFile) throws IOException
     {
-        state = OPENING_STATE;
-      try
-      {
-          requestFileWriter=new BufferedWriter(new FileWriter(requestFile));
-      }
-      catch (IOException exception)
-      {
-          System.err
-                  .println("IOEXCeption when creating filewriter to requestfile: "
-                          +exception);
-          throw exception;
-      }
-      if (!responseFile.equals(""))
-      {
-          try
-          {
-              responseFileWriter=new BufferedWriter(new FileWriter(
-                      responseFile));
-          }
-          catch (IOException exception)
-          {
-              System.err
-                      .println("IOException when creating writer to response file: "
-                              +exception);
-              throw exception;
-          }
-          responseFileWriterOpen=true;
-      }
+        this(requestFile, responseFile);
         /*
          * Create a thread which listens for incoming requests
          */
@@ -209,7 +219,7 @@
         }
     }
     
-    protected 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");

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=407288&r1=407287&r2=407288&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 Wed May 17 08:42:20 2006
@@ -98,6 +98,13 @@
         addChild(clientReturner);
         new Thread(clientReturner).start( );
     }
+    
+    /**
+     * if a class overrides this to get the lifecycle but not the function then it needs this constructor
+     *
+     */
+    protected TestClientThread()
+    {}
 
     private void IsStopMessage(Socket clientSocket) throws IOException,
             StopRequestException
@@ -181,8 +188,7 @@
         {
             try
             {
-                bytesRead=clientRequestStream.read(readBuffer, 0,
-                        READ_BUFFER_SIZE);
+                bytesRead = readBytes(readBuffer, 0, READ_BUFFER_SIZE);
                 if (bytesRead==-1)
                 {
                     continueToRun=false;
@@ -246,6 +252,18 @@
             }
         }
         //        System.out.println( "TestClientThread#run(): exit");
+    }
+
+    /**
+     * @param bufferToreadInto
+     * @param startingPointInBuffer
+     * @param sizeOfReadBuffer
+     * @return the number of bytes read
+     */
+    protected int readBytes(char[] bufferToreadInto, int startingPointInBuffer, int sizeOfReadBuffer)throws IOException
+    {
+        return clientRequestStream.read(bufferToreadInto, startingPointInBuffer,
+                sizeOfReadBuffer);
     }
 
     public Socket createSocketToServer(String serviceHostName, int servicePort)