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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: 20 February 2002 01:13
> To: [EMAIL PROTECTED]
> 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-
> [EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:cactus-user-
> [EMAIL PROTECTED]>
> 




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to