You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2002/02/28 12:09:51 UTC

cvs commit: jakarta-cactus/anttasks/src/java/org/apache/cactus/ant StartServerHelper.java

vmassol     02/02/28 03:09:51

  Modified:    anttasks/src/java/org/apache/cactus/ant
                        StartServerHelper.java
  Log:
  corrected bug that prevented using testURL in runservertests with a URL that returned nothing. Also added some verbose logs.
  
  Revision  Changes    Path
  1.2       +33 -9     jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/StartServerHelper.java
  
  Index: StartServerHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/StartServerHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StartServerHelper.java	24 Feb 2002 23:49:05 -0000	1.1
  +++ StartServerHelper.java	28 Feb 2002 11:09:50 -0000	1.2
  @@ -56,7 +56,7 @@
    */
   package org.apache.cactus.ant;
   
  -import java.io.BufferedInputStream;
  +import java.io.InputStream;
   import java.io.IOException;
   import java.net.HttpURLConnection;
   import java.net.MalformedURLException;
  @@ -65,6 +65,7 @@
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.taskdefs.CallTarget;
  +import org.apache.tools.ant.Project;
   
   /**
    * A helper class for an Ant Task that does the following :
  @@ -78,7 +79,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: StartServerHelper.java,v 1.1 2002/02/24 23:49:05 vmassol Exp $
  + * @version $Id: StartServerHelper.java,v 1.2 2002/02/28 11:09:50 vmassol Exp $
    */
   public class StartServerHelper implements Runnable
   {
  @@ -148,11 +149,14 @@
               // don't stop it afterwards.
               this.isServerAlreadyStarted = true;
   
  +            this.task.log("Server is already running", Project.MSG_VERBOSE);
  +
               return;
   
           } catch (IOException e) {
               // An error occurred. It just means the server is not running. Do
               // nothing
  +            this.task.log("Server is not running", Project.MSG_VERBOSE);
           }
   
           // Call the target that starts the server, in another thread. The called
  @@ -172,6 +176,8 @@
           // Continuously try calling the test URL until it succeeds
           while (true) {
   
  +            this.task.log("Checking if server is up ...", Project.MSG_VERBOSE);
  +
               try {
                   HttpURLConnection connection =
                       (HttpURLConnection) this.testURL.openConnection();
  @@ -179,14 +185,21 @@
                   readFully(connection);
                   connection.disconnect();
               } catch (IOException e) {
  +
  +                this.task.log("... got error : " + e.getMessage(),
  +                    Project.MSG_VERBOSE);
  +
                   try {
                       Thread.sleep(500);
                   } catch (InterruptedException ee) {
                       throw new BuildException("Interruption during sleep", ee);
                   }
  +
                   continue;
               }
   
  +            this.task.log("Server is up !", Project.MSG_VERBOSE);
  +
               break;
           }
   
  @@ -197,7 +210,10 @@
               throw new BuildException("Interruption during sleep", e);
           }
   
  +        this.task.log("Server started", Project.MSG_VERBOSE);
  +
           // We're done ... Ant will continue processing other tasks
  +
       }
   
       /**
  @@ -207,15 +223,23 @@
        * @param theConnection the HTTP URL connection to read from
        * @exception IOException if an error happens during the read
        */
  -    static void readFully(HttpURLConnection theConnection) throws IOException
  +    static void readFully(HttpURLConnection theConnection)
  +        throws IOException
       {
  -        // finish reading it to prevent (harmless) server-side exceptions
  -        BufferedInputStream is =
  -            new BufferedInputStream(theConnection.getInputStream());
  -        byte[] buffer = new byte[256];
  -        while ((is.read(buffer)) > 0) {
  +        // Only read if there is data to read ... The problem is that not
  +        // all servers return a content-length header. If there is no header
  +        // getContentLength() returns -1. It seems to work and it seems
  +        // that all servers that return no content-length header also do
  +        // not block on read() operations !
  +
  +        if (theConnection.getContentLength() != 0) {
  +
  +            byte[] buf = new byte[256];
  +
  +            InputStream is = theConnection.getInputStream();
  +            while (-1 != is.read(buf)) {
  +            }
           }
  -        is.close();
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>