You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by as...@netcom.no on 2002/02/20 02:12:59 UTC

Ant task bug (and fix)

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Ant task bug (and fix)

Posted by Vincent Massol <vm...@octo.com>.
Aslak,

I have applied a fix yesterday (not exactly the one you provided :-))
and I hope it will also fix your problem. I have sent several answers to
you in other emails as I wasn't sure of what exactly was your problem.

The fix is :

    static void readFully(HttpURLConnection theConnection)
        throws IOException
    {
        // 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)) {
            }
        }
    }

Can you check if it solves your problem. ?
Thanks

-Vincent



> -----Original Message-----
> From: aslak.hellesoy@netcom.no [mailto:aslak.hellesoy@netcom.no]
> Sent: 20 February 2002 01:13
> To: cactus-user@jakarta.apache.org
> Subject: Ant task bug (and fix)
> 
> 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.jav
a:
> 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(HttpURLConnec
ti
> on
> .java:506)
>    at
>
org.apache.cactus.ant.StartServerHelper.readFully(StartServerHelper.java
:1
> 99
> )
> 
> 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>
> 




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


RE: Ant task bug (and fix)

Posted by Vincent Massol <vm...@octo.com>.
Hi Aslak

> -----Original Message-----
> From: aslak.hellesoy@netcom.no [mailto:aslak.hellesoy@netcom.no]
> Sent: 20 February 2002 01:13
> To: cactus-user@jakarta.apache.org
> Subject: Ant task bug (and fix)
> 
> 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, how can you expect to test it ! ;-). The normal
sequence of events is :
1/ deploy the application to the container
2/ start the container (and check for existence for URL)

Or are you testing dynamic deployment ? :-)

> 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, 

It is a little more than that. It is to actually verify the container is
ready to serve requests for your given webapp. To be perfectly correct
the testURL should actually point to one of the cactus redirector that
you're using (using the TEST service, i.e.
http://localhost:8080/mycontext/ServletRedirector?Cactus_Service=RUN_TES
T).  Note that I haven't tested this though ... :-). I should and I will
that I'm remembering this feature ...

BTW we'll need to improve the FAQ to include this (instead of asking
users to use http://localhost:8080/mycontext/ServletRedirector which
returns a 5xx error because it is missing the needed HTTP parameter and
thus the code throws a ServletException).

> 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.

Yes, but can we tell for sure it is able to service requests ? If that
were true for all servers then we could certainly use
testURL=http://localhost:8080 for all cases, couldn't we ?

> 
> 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.jav
a:
> 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(HttpURLConnec
ti
> on
> .java:506)
>    at
>
org.apache.cactus.ant.StartServerHelper.readFully(StartServerHelper.java
:1
> 99
> )
> 
> 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.
> 

I am willing to apply the patch, although I don't fully understand your
reason to testing with an empty container (unless you're doing dynamic
deployment).


> Cheers,
> Aslak

Thanks
-Vincent

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




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