jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aslak.helle...@netcom.no
Subject Ant task bug (and fix)
Date Wed, 20 Feb 2002 01:12:59 GMT
Hi!

First, thanks for a great product!

I have discovered an issue related to the Cactus Ant task which occurs when
I'm using Cactus with a clean Container with nothing deployed. Since there
is nothing in the container I'm forced to set testURL to something that
doesn't exist, and the HTTP result is a 404. As far as I understand, the
purpose of the testURL is only to ping, and IMO, a 404 is a good enough
result for a ping. If you get a 404, at least you know the server is
running.

The problem is in the
org.apache.cactus.ant.StartServerHelper.readFully(HttpURLConnection
connection) method. If the testURL returns a 404, here is what happens:
java.lang.NullPointerException
   at
sun.net.www.http.ChunkedInputStream.readChunkSize(ChunkedInputStream.java:16
2)
   at
sun.net.www.http.ChunkedInputStream.prefill(ChunkedInputStream.java:187)
   at sun.net.www.http.ChunkedInputStream.<init>(ChunkedInputStream.java:94)
   at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:749)
   at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:613)
   at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
.java:506)
   at
org.apache.cactus.ant.StartServerHelper.readFully(StartServerHelper.java:199
)

I would consider this to be a bug in the sun libraries, but it can be worked
around in cactus:

I have modified the readFully method, and now it works as a charm:

static void readFully(HttpURLConnection connection) throws IOException
{
   // finish reading it to prevent (harmless) server-side exceptions
   try {
      BufferedInputStream is =
         new BufferedInputStream(connection.getInputStream());
   byte[] buffer = new byte[256];
   while((is.read(buffer)) > 0) {}
   is.close();
   } catch( NullPointerException e ) {
      // Server responded, but there was nothing to read. At least server is
running.
   }
}
Here is a sniplet of my Ant script:

   <target
      name="cactus.junit-report"
      description="Generates test reports with Cactus"
      depends="cactus.client-properties"
      if="junit.on"
   >
      <taskdef name="cactus"
classname="org.apache.cactus.ant.RunServerTestsTask"/>
      <cactus
         testURL="${cactus.url}"
         startTarget="weblogic.start"
         testTarget="cactus.deploy-test-delete"
         stopTarget="weblogic.stop"
      />
   </target>

   <target name="cactus.deploy-test-delete"
depends="weblogic.deploy,common.junit-report,weblogic.delete"/>

I hope this patch makes sense to you, and that you can apply it.

Cheers,
Aslak


--
To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>


Mime
View raw message