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 na...@apache.org on 2006/03/22 02:27:07 UTC

svn commit: r387684 - in /webservices/axis/trunk/c/tests/utils/monitor/org/apache/test: ClientReturner.java MockServer.java MockServerThread.java Response.java

Author: nadiramra
Date: Tue Mar 21 17:27:04 2006
New Revision: 387684

URL: http://svn.apache.org/viewcvs?rev=387684&view=rev
Log:
Format code so more readable - align braces, etc.

Modified:
    webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.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/Response.java

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java?rev=387684&r1=387683&r2=387684&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 Tue Mar 21 17:27:04 2006
@@ -48,8 +48,7 @@
     protected ClientReturner(Socket clientSocket) throws IOException
     {
         number++;
-        streamToClient=new BufferedWriter(new OutputStreamWriter(clientSocket
-                .getOutputStream( )));
+        streamToClient=new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream( )));
     }
 
     /**
@@ -65,9 +64,7 @@
         //        System.out.println( "ClientReturner(): entry");
         // create the reader from the server
         this.serviceSocket = serviceSocket;
-        serverResponseStream=new BufferedReader(new InputStreamReader(
-                serviceSocket.getInputStream( )));
-
+        serverResponseStream=new BufferedReader(new InputStreamReader(serviceSocket.getInputStream( )));
     }
 
     /**
@@ -90,8 +87,7 @@
         {
             while (continueToRun)
             {
-                bytesRead=serverResponseStream.read(readBuffer, 0,
-                        READ_BUFFER_SIZE);
+                bytesRead=serverResponseStream.read(readBuffer, 0, READ_BUFFER_SIZE);
                 //                System.out.println( "Clientreturner got some bytes from the
                 // server "+bytesRead);
                 if (bytesRead!=-1)
@@ -107,13 +103,11 @@
                     }
                     catch (IOException exception)
                     {
-                        System.err
-                                .println("IOException when writing server response back to client");
+                        System.err.println("IOException when writing server response back to client");
                         exception.printStackTrace(System.err);
                     }
                     // System.out.println("ClientReturner#run(): flushed");
-                    TCPMonitor.getInstance( ).writeResponse(readBuffer,
-                            bytesRead);
+                    TCPMonitor.getInstance( ).writeResponse(readBuffer,bytesRead);
                     System.out.println("About to go around again");
                 }
                 else
@@ -141,8 +135,7 @@
             exception.printStackTrace();
             if(TCPMonitor.state<TCPMonitor.CLOSING_STATE)
             {
-                System.err
-                	.println("ClientReturner#run(): IOException when reading in response from server ");
+                System.err.println("ClientReturner#run(): IOException when reading in response from server ");
                 exception.printStackTrace(System.err);
             }
             else

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServer.java?rev=387684&r1=387683&r2=387684&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 Tue Mar 21 17:27:04 2006
@@ -46,11 +46,9 @@
     
     public static final void printUsage( )
     {
-        System.out
-                .println("Usage: java MockServer -p <port> -r <responseFile>");
+        System.out.println("Usage: java MockServer -p <port> -r <responseFile>");
         System.out.println("port: the port to listen for requests on");
-        System.out
-                .println("responseFile: The file to write out when a request is received");
+        System.out.println("responseFile: The file to write out when a request is received");
     }
 
     public static void main(String[] args)
@@ -99,8 +97,7 @@
                 catch (NumberFormatException numberFormatException)
                 {
                     printUsage( );
-                    throw new NumberFormatException("port is not an integer "
-                            +portString);
+                    throw new NumberFormatException("port is not an integer " +portString);
                 }
             }
             if (arguments[i].equals("-r"))
@@ -142,8 +139,7 @@
         {
             try
             {
-                System.out
-                        .println("Mockserver#run(): About to wait for incoming client request");
+                System.out.println("Mockserver#run(): About to wait for incoming client request");
                 incoming=serverSocket.accept( );
 
                 // Set keep-alive option to ensure that if server crashes we do not 
@@ -166,6 +162,7 @@
                 exception.printStackTrace(System.err);
                 continueToRun=false;
             }
+            
             if (incoming!=null)
             {
                 try

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServerThread.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/MockServerThread.java?rev=387684&r1=387683&r2=387684&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 Tue Mar 21 17:27:04 2006
@@ -57,13 +57,15 @@
             throws IOException , StopRequestException
     {
         System.out.println("MockServerThread(): entry");
+        
+        inputStream = null;
+        outputStream = null;
         this.socket = socket; 
         setSocketTimeouts();
+        
         try
         {
-            // get the input and outputstreams
-            inputStream=new BufferedReader(new InputStreamReader(socket
-                    .getInputStream( )));
+            inputStream=new BufferedReader(new InputStreamReader(socket.getInputStream( )));
         }
         catch (IOException e)
         {
@@ -72,8 +74,7 @@
         }
         try
         {
-            outputStream=new BufferedWriter(new OutputStreamWriter(socket
-                    .getOutputStream( )));
+            outputStream=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream( )));
         }
         catch (IOException e1)
         {
@@ -107,29 +108,26 @@
     {
         // 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.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------------------------");
+        System.out.println("----------------------------------MockServer Thread new Request------------------------");
 
         while (totalBytesRead<StopMockServer.STOPMOCKSERVER_STRING.length( ))
         {
             try
             {
-                bytesRead=inputStream.read(charBuffer, 0,
-                        StopMockServer.STOPMOCKSERVER_STRING.length( ));
-                System.out.println("MockServerThread#run(): Got some bytes: "
-                        +bytesRead);
+                bytesRead=inputStream.read(charBuffer, 0, StopMockServer.STOPMOCKSERVER_STRING.length( ));
+                System.out.println("MockServerThread#run(): Got some bytes: " +bytesRead);
             }
             catch (IOException exception)
             {
                 exception.printStackTrace(System.err);
                 throw exception;
             }
+            
             if (bytesRead>-1)
             {
                 message+=new String(charBuffer, 0, bytesRead);
@@ -139,17 +137,13 @@
             {
                 System.out.println("got -1 but Got message "+message);
                 return message;
-                //                throw new IOException(
-                //                        "read in -1 bytes when trying to read the initial few bytes
-                // from the client");
             }
         }
 
         if (message.equals(StopMockServer.STOPMOCKSERVER_STRING))
         {
             // we've been told to stop
-            System.out
-                    .println("--------------------------------------------------------------------");
+            System.out.println("--------------------------------------------------------------------");
             throw new StopRequestException("MockServer has been told to stop");
         }
         else
@@ -170,50 +164,36 @@
         char[] charBuffer=new char[CHARBUFFER_SIZE];
         try
         {
-            System.out
-                    .println("MockServerThread#run(): About to wait on the inputstream");
+            System.out.println("MockServerThread#run(): About to wait on the inputstream");
             while ((bytesRead=inputStream.read(charBuffer))!=-1)
             {
-                System.out
-                        .println("MockServerThread#run(): Got some more bytes "
-                                +bytesRead);
+                System.out.println("MockServerThread#run(): Got some more bytes " +bytesRead);
 
                 // See whether this ends with an envelope
                 if (bytesRead>ENVELOPE_TAG.length( )+2)
                 {
                     String envelopeString=new String(charBuffer, bytesRead
-                            -(ENVELOPE_TAG.length( )+2),
-                            ENVELOPE_TAG.length( )+2);
-                    System.out
-                            .println("MockServerThread#run():EnvelopeString = "
-                                    +envelopeString);
+                            -(ENVELOPE_TAG.length( )+2), ENVELOPE_TAG.length( )+2);
+                    System.out.println("MockServerThread#run():EnvelopeString = " +envelopeString);
                     // Check whether this is an envelope or not
                     if (envelopeString.startsWith(ENVELOPE_TAG)
                             ||envelopeString.indexOf(MIME_BOUNDARY)!=-1)
                     {
-                        System.out
-                                .println("MockServerThread#run():Got an envelope");
-                        // OK, so now output the response message to the
-                        // client
+                        System.out.println("MockServerThread#run():Got an envelope");
+
                         sendResponseToClient( );
-                        System.out
-                                .println("-------------------------------MockServer new request---------------------------------");
+                        System.out.println("-------------------------------MockServer new request---------------------------------");
                     }
                 }
-                System.out.println("MockServerThread#run(): Going round again "
-                        +inputStream);
+                System.out.println("MockServerThread#run(): Going round again " +inputStream);
             }
         }
         catch (IOException exception)
         {
             if(!closedConnection)
-            {
                 exception.printStackTrace(System.err);
-            }
             else
-            {
                 System.out.println( "MockServerThread#run(): Connection Has Been Closed");
-            }
         }
         System.out.println("MockServerThread#run(): exit");
     }
@@ -230,20 +210,17 @@
     {
         // Create a seperate thread and return
         Response responseMessage=getResponseMessage( );
-//        System.out.println( "responsemessage ======="+responseMessage);
-//        System.out.println( "===================================================");
+
         if (responseMessage!=null)
         {
-            ResponseSender responseSender=new ResponseSender(responseMessage,
-                    outputStream, this);
+            ResponseSender responseSender=new ResponseSender(responseMessage,outputStream, this);
             addChild(responseSender);
             Thread responseSenderThread=new Thread(responseSender);
             responseSenderThread.start( );
         }
         else
         {
-            System.err
-                    .println("We've run out of responses to send back to the client");
+            System.err.println("We've run out of responses to send back to the client");
             throw new IOException("No more responses to send to clients");
         }
     }
@@ -341,20 +318,15 @@
 					if( hashPos == -1)
 				    {
 					    hashPos = orgResponse.lastIndexOf( "0");
-					    
 					    eom = true;
 				    }
 	
 					int chunkLength;
 					
 		            if( System.getProperty( "os.name").toLowerCase().startsWith( "windows"))
-		            {
 		                chunkLength = hashPos - 4; // Take into account the CR+LF's that surround the chunk size, so subtract 4.
-		            }
 		            else
-		            {
 		                chunkLength = hashPos - 2; // Take into account the LF's that surround the chunk size, so subtract 2.
-		            }
 	
 					// Add the next chunk length and data from the original to the new response.
 		                
@@ -367,9 +339,7 @@
 					    orgResponse = "";
 				    }
 				    else
-				    {
 					    orgResponse = orgResponse.substring( hashPos + hash.length());
-				    }
 				}
             }
 

Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/Response.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/Response.java?rev=387684&r1=387683&r2=387684&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/Response.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/Response.java Tue Mar 21 17:27:04 2006
@@ -76,11 +76,8 @@
         this.message=message.toCharArray( );
         // parse the message to see if it has a Connection: Close in it
         if (message.toLowerCase( ).indexOf("connection: close")>-1)
-        {
             hasCloseConnectionHeader=true;
-        }
-
-        
+       
         // Find out if the message is chunked
         deriveIsChunked( );
         
@@ -102,11 +99,8 @@
         Matcher matcher=pattern.matcher(msgString);
         
         if(matcher.find())
-        {
            msgString = matcher.replaceAll(""+LF);
-        }
         message = msgString.toCharArray();
-        
     }
 
     private void deriveIsChunked( )
@@ -146,12 +140,8 @@
         }
         else
         {
-            if (System.getProperty("os.name").toLowerCase( ).startsWith(
-                    "windows"))
-            {
-                System.out
-                        .println("Windows operating system - not converting crlf's");
-            }
+            if (System.getProperty("os.name").toLowerCase( ).startsWith("windows"))
+                System.out.println("Windows operating system - not converting crlf's");
             else
             {
                 String request=new String(getMessage( ));
@@ -217,9 +207,7 @@
         Matcher matcher = pattern.matcher(response);
         
         if(!matcher.find())
-        {
             System.err.println( "ERROR: Response message does not contain a correctly formatted HTTP header:" +response);
-        }
         
         return matcher.replaceAll("$3");
     }
@@ -291,19 +279,14 @@
             // chunkFromSize is null so we can see later on that we need to guess
         }
         else
-        {
             chunkFromSize = request.substring(chunkStart, chunkStart+chunkSize);
-        }
         
         String chunk=""; 
         int endOfThisChunk;
         // Now find the end of the chunk (and while we do that we actually find the next chunk size too !
         
         if(!theNextChunkSizeMatcher.find())
-        {
-            // if there isn't one then it means that this is the last chunk
             endOfThisChunk = request.length()-1;
-        }
         else
         {
             chunkEnd = theNextChunkSizeMatcher.start();
@@ -333,9 +316,7 @@
                 chunkSizeString = ""+Integer.toHexString(chunk.length())+CRLF;
             }
             else
-            {
                 chunkSizeString = CRLF+Integer.toHexString(chunk.length())+CRLF;
-            }
         }
         
         // Check that the chunk size really is the same size as it should be.