[kaffe] HttpURLConnection CVS regression from 1.0.7

Mark Wielaard mark@klomp.org
Sun Apr 27 04:59:02 2003


Hi,

I have a little snippet of code (adapted to work standalone) that works
with kaffe 1.0.7 but not with the CVS version:

import java.io.*;
import java.net.*;
 
public class TC
{
  public static void main(String[] args) throws Exception
  {
    URL u = new URL("http://www.gnu.org/");
    URLConnection c = u.openConnection();
    c.connect();
    InputStream in = c.getInputStream();
 
    if (c instanceof HttpURLConnection)
      {
        // Check whether the page exists
        int code = ((HttpURLConnection)c).getResponseCode();
        if (code/100 != 2) // We can only handle 200 OK
          {
            System.err.println("Loading page gave error code "
                      + code + ", it probably doesn't exists");
            return;
          }
      }
 
    // Do something with the inputstream
    System.out.println("Yeah!");
  }
}

With kaffe from CVS it always gives reponse code -1.
This seems to be caused by a combination of the new proxy activation
code in
kaffe/net/www/protocol/http/HttpURLConnection.java
which precents creation of a new socket everytime which the old code did
on a connect (since the socket == null check was missing) and the fact
that connect is called from both URL.openConnection() and the above
URLConnection.connect() in my code.

It seems a good idea to not call connect() in openConnection() as done
in this patch, but I have not thought this through completely.

diff -u -r1.29 URL.java
--- libraries/javalib/java/net/URL.java 15 Apr 2002 15:10:01 -0000      1.29
+++ libraries/javalib/java/net/URL.java 27 Apr 2003 11:52:55 -0000
@@ -229,7 +229,6 @@
        // We *ALWAYS* open a new connection even if we already have
        // one open.
        conn = handler.openConnection(this);
-       conn.connect();
        return (conn);
 }

Cheers,

Mark