Initial load
diff --git a/test/java/net/URLConnection/6212146/Test.java b/test/java/net/URLConnection/6212146/Test.java
new file mode 100644
index 0000000..3904470
--- /dev/null
+++ b/test/java/net/URLConnection/6212146/Test.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class Test {
+
+    public static void main(String[] args)
+         throws Exception {
+      String BASE_DIR = args[0];
+      String ARCHIVE_NAME = args[1];
+      String lProperty = System.getProperty( "do.iterations", "5000" );
+      int lRepetitions = new Integer( lProperty ).intValue();
+      System.out.println ( "Start creating copys of the archive, " + lRepetitions + " times" );
+      for( int i = 0; i < lRepetitions; i++ ) {
+         // Copy the given jar file and add a prefix
+         copyFile( BASE_DIR, ARCHIVE_NAME, i);
+      }
+      System.out.println ( "Start opening the archives archive, " + lRepetitions + " times" );
+      System.out.println ( "First URL is jar:file://" + BASE_DIR + "1" + ARCHIVE_NAME + "!/foo/Test.class");
+      for( int i = 0; i < lRepetitions; i++ ) {
+         // Create ULR
+         String lURLPath = "jar:file://" + BASE_DIR + i + ARCHIVE_NAME + "!/foo/Test.class";
+         URL lURL = new URL( lURLPath );
+         // Open URL Connection
+         try {
+            URLConnection lConnection = lURL.openConnection();
+            lConnection.getInputStream();
+         } catch( java.io.FileNotFoundException fnfe ) {
+            // Ignore this one because we expect this one
+         } catch( java.util.zip.ZipException ze ) {
+            throw new RuntimeException ("Test failed: " + ze.getMessage());
+         }
+      }
+      //System.out.println ( "Done testing, waiting 20 seconds for checking" );
+      //System.out.println ( "Cleaning up");
+      //for( int i = 0; i < lRepetitions; i++ ) {
+         // Copy the given jar file and add a prefix
+         //deleteFile( BASE_DIR, i, ARCHIVE_NAME);
+      ////}
+   }
+
+   private static void deleteFile (String BASE_DIR, int pIndex, String pArchiveName) {
+         java.io.File file = new java.io.File (BASE_DIR, pIndex + pArchiveName );
+         file.delete ();
+   }
+
+   private static void copyFile( String pBaseDir, String pArchiveName, int pIndex) {
+      try {
+         java.io.File lSource = new java.io.File( pBaseDir, pArchiveName );
+         java.io.File lDestination = new java.io.File( pBaseDir, pIndex + pArchiveName );
+         if( !lDestination.exists() ) {
+            lDestination.createNewFile();
+            java.io.InputStream lInput = new java.io.FileInputStream( lSource );
+            java.io.OutputStream lOutput = new java.io.FileOutputStream( lDestination );
+            byte[] lBuffer = new byte[ 1024 ];
+            int lLength = -1;
+            while( ( lLength = lInput.read( lBuffer ) ) > 0 ) {
+               lOutput.write( lBuffer, 0, lLength );
+            }
+            lInput.close();
+            lOutput.close();
+         }
+      } catch( Exception e ) {
+         e.printStackTrace();
+      }
+   }
+}
diff --git a/test/java/net/URLConnection/6212146/test.jar b/test/java/net/URLConnection/6212146/test.jar
new file mode 100644
index 0000000..8f1bc0f
--- /dev/null
+++ b/test/java/net/URLConnection/6212146/test.jar
Binary files differ
diff --git a/test/java/net/URLConnection/6212146/test.sh b/test/java/net/URLConnection/6212146/test.sh
new file mode 100644
index 0000000..29b187a
--- /dev/null
+++ b/test/java/net/URLConnection/6212146/test.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+#
+# Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+#
+#  @test
+#  @run shell/timeout=380 test.sh
+#  @bug 6212146
+#  @summary URLConnection.connect() fails on JAR Entry it creates file handler leak
+#
+# set platform-dependent variables
+
+OS=`uname -s`
+case "$OS" in
+  SunOS )
+    PS=":"
+    FS="/"
+    ;;
+  Linux )
+    PS=":"
+    FS="/"
+    ;;
+  Windows* )
+    PS=";"
+    FS="\\"
+    ;;
+  * )
+    echo "Unrecognized system!"
+    exit 1;
+    ;;
+esac
+
+if [ -d jars ]; then
+    rm -rf jars
+fi
+
+mkdir jars
+
+cp ${TESTSRC}${FS}test.jar  jars
+
+${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}Test.java
+
+WD=`pwd`
+ulimit -H -n 300
+${TESTJAVA}${FS}bin${FS}java Test ${WD}/jars/ test.jar 
+result=$?
+rm -rf jars
+exit $?
diff --git a/test/java/net/URLConnection/B5052093.java b/test/java/net/URLConnection/B5052093.java
new file mode 100644
index 0000000..c1add42
--- /dev/null
+++ b/test/java/net/URLConnection/B5052093.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 5052093
+ * @library ../../../sun/net/www/httptest/
+ * @build HttpCallback HttpServer ClosedChannelList HttpTransaction
+ * @run main B5052093
+ * @summary URLConnection doesn't support large files
+ */
+import java.net.*;
+import java.io.*;
+import sun.net.www.protocol.file.FileURLConnection;
+
+public class B5052093 implements HttpCallback {
+    private static HttpServer server;
+    private static long testSize = ((long) (Integer.MAX_VALUE)) + 2;
+
+    public static class LargeFile extends File {
+        public LargeFile() {
+            super("/dev/zero");
+        }
+
+        public long length() {
+            return testSize;
+        }
+    }
+
+    public static class LargeFileURLConnection extends FileURLConnection {
+        public LargeFileURLConnection(LargeFile f) throws IOException {
+                super(new URL("file:///dev/zero"), f);
+        }
+    }
+
+    public void request(HttpTransaction req) {
+        try {
+            req.setResponseHeader("content-length", Long.toString(testSize));
+            req.sendResponse(200, "OK");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        server = new HttpServer(new B5052093(), 1, 10, 0);
+        URL url = new URL("http://localhost:"+server.getLocalPort()+"/foo");
+        URLConnection conn = url.openConnection();
+        int i = conn.getContentLength();
+        long l = conn.getContentLengthLong();
+        if (i != -1 || l != testSize)
+            throw new RuntimeException("Wrong content-length from http");
+
+        URLConnection fu = new LargeFileURLConnection(new LargeFile());
+        i = fu.getContentLength();
+        l = fu.getContentLengthLong();
+        if (i != -1 || l != testSize)
+            throw new RuntimeException("Wrong content-length from file");
+    }
+}
diff --git a/test/java/net/URLConnection/ChunkedEncoding.java b/test/java/net/URLConnection/ChunkedEncoding.java
new file mode 100644
index 0000000..b446b57
--- /dev/null
+++ b/test/java/net/URLConnection/ChunkedEncoding.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ *
+ * @bug 4333920
+ * @bug 4394548
+ * @summary Check that chunked encoding response doesn't cause
+ *          getInputStream to block until last chunk arrives.
+ *          Also regression against NPE in ChunkedInputStream.
+ */
+import java.net.*;
+import java.io.*;
+import java.util.Random;
+
+public class ChunkedEncoding implements Runnable {
+
+    ServerSocket ss;
+
+    /*
+     * Our "http" server to return a chunked response
+     */
+    public void run() {
+        try {
+            Socket s = ss.accept();
+
+            PrintStream out = new PrintStream(
+                                 new BufferedOutputStream(
+                                    s.getOutputStream() ));
+
+            /* send the header */
+            out.print("HTTP/1.1 200\r\n");
+            out.print("Transfer-Encoding: chunked\r\n");
+            out.print("Content-Type: text/html\r\n");
+            out.print("\r\n");
+            out.flush();
+
+            /* delay the server before first chunk */
+            Thread.sleep(5000);
+
+            /*
+             * Our response will be of random length
+             * but > 32k
+             */
+            Random rand = new Random();
+
+            int len;
+            do {
+                len = rand.nextInt(128*1024);
+            } while (len < 32*1024);
+
+            /*
+             * Our chunk size will be 2-32k
+             */
+            int chunkSize;
+            do {
+                chunkSize = rand.nextInt(len / 3);
+            } while (chunkSize < 2*1024);
+
+            /*
+             * Generate random content and check sum it
+             */
+            byte buf[] = new byte[len];
+            int cs = 0;
+            for (int i=0; i<len; i++) {
+                buf[i] = (byte)('a' + rand.nextInt(26));
+                cs = (cs + buf[i]) % 65536;
+            }
+
+            /*
+             * Stream the chunks to the client
+             */
+            int remaining = len;
+            int pos = 0;
+            while (remaining > 0) {
+                int size = Math.min(remaining, chunkSize);
+                out.print( Integer.toHexString(size) );
+                out.print("\r\n");
+                out.write( buf, pos, size );
+                pos += size;
+                remaining -= size;
+                out.print("\r\n");
+                out.flush();
+            }
+
+            /* send EOF chunk */
+            out.print("0\r\n");
+            out.flush();
+
+            /*
+             * Send trailer with checksum
+             */
+            String trailer = "Checksum:" + cs + "\r\n";
+            out.print(trailer);
+            out.print("\r\n");
+            out.flush();
+
+            s.close();
+            ss.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    ChunkedEncoding() throws Exception {
+
+        /* start the server */
+        ss = new ServerSocket(0);
+        (new Thread(this)).start();
+
+        /* establish http connection to server */
+        String uri = "http://localhost:" +
+                     Integer.toString(ss.getLocalPort()) +
+                     "/foo";
+        URL url = new URL(uri);
+        HttpURLConnection http = (HttpURLConnection)url.openConnection();
+
+        /*
+         * Server should only send headers if TE:trailers
+         * specified - see updated HTTP 1.1 spec.
+         */
+        http.setRequestProperty("TE", "trailers");
+
+        /* Time how long the getInputStream takes */
+        long ts = System.currentTimeMillis();
+        InputStream in = http.getInputStream();
+        long te = System.currentTimeMillis();
+
+        /*
+         * If getInputStream takes >2 seconds it probably means
+         * that the implementation is waiting for the chunks to
+         * arrive.
+         */
+        if ( (te-ts) > 2000) {
+            throw new Exception("getInputStream didn't return immediately");
+        }
+
+        /*
+         * Read the stream and checksum it as it arrives
+         */
+        int nread;
+        int cs = 0;
+        byte b[] = new byte[1024];
+        do {
+            nread = in.read(b);
+            if (nread > 0) {
+                for (int i=0; i<nread; i++) {
+                    cs = (cs + b[i]) % 65536;
+                }
+            }
+        } while (nread > 0);
+
+        /*
+         * Verify that the checksums match
+         */
+        String trailer = http.getHeaderField("Checksum");
+        if (trailer == null) {
+            throw new Exception("Checksum trailer missing from response");
+        }
+        int rcvd_cs = Integer.parseInt(trailer);
+        if (rcvd_cs != cs) {
+            throw new Exception("Trailer checksum doesn't equal calculated checksum");
+        }
+
+        http.disconnect();
+
+    }
+
+    public static void main(String args[]) throws Exception {
+        new ChunkedEncoding();
+    }
+
+}
diff --git a/test/java/net/URLConnection/Connect.java b/test/java/net/URLConnection/Connect.java
new file mode 100644
index 0000000..3398dc5
--- /dev/null
+++ b/test/java/net/URLConnection/Connect.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 4134855
+   @summary Test for opening non existant file
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class Connect {
+    public static void main(String s[]) throws Exception {
+            try {
+                // This file does not exist.
+                URL url = new URL("file:azwe.txt");
+                URLConnection urlConnection = url.openConnection();
+                urlConnection.connect();
+                // We reach here in JDK1.2beta3.
+                throw new RuntimeException("No FileNotFoundException thrown.");
+            }
+            catch(MalformedURLException e) {
+            }
+            catch(IOException e) {
+            }
+        }
+}
diff --git a/test/java/net/URLConnection/DisconnectAfterEOF.java b/test/java/net/URLConnection/DisconnectAfterEOF.java
new file mode 100644
index 0000000..44a65f6
--- /dev/null
+++ b/test/java/net/URLConnection/DisconnectAfterEOF.java
@@ -0,0 +1,302 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4774503
+ * @summary Calling HttpURLConnection's disconnect method after the
+ *          response has been received causes havoc with persistent
+ *          connections.
+ */
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+public class DisconnectAfterEOF {
+
+    /*
+     * Worker thread to service single connection - can service
+     * multiple http requests on same connection.
+     */
+    static class Worker extends Thread {
+        Socket s;
+
+        Worker(Socket s) {
+            this.s = s;
+        }
+
+        public void run() {
+            try {
+                InputStream in = s.getInputStream();
+                PrintStream out = new PrintStream(
+                                        new BufferedOutputStream(
+                                                s.getOutputStream() ));
+                byte b[] = new byte[1024];
+                int n = -1;
+                int cl = -1;
+                int remaining = -1;
+                StringBuffer sb = new StringBuffer();
+                Random r = new Random();
+                boolean close = false;
+
+                boolean inBody = false;
+                for (;;) {
+                    boolean sendResponse = false;
+
+                    try {
+                        n = in.read(b);
+                    } catch (IOException ioe) {
+                        n = -1;
+                    }
+                    if (n <= 0) {
+                        if (inBody) {
+                            System.err.println("ERROR: Client closed before before " +
+                                "entire request received.");
+                        }
+                        return;
+                    }
+
+                    // reading entity-body
+                    if (inBody) {
+                        if (n > remaining) {
+                            System.err.println("Receiving more than expected!!!");
+                            return;
+                        }
+                        remaining -= n;
+
+                        if (remaining == 0) {
+                            sendResponse = true;
+                            n = 0;
+                        } else {
+                            continue;
+                        }
+                    }
+
+                    // reading headers
+                    for (int i=0; i<n; i++) {
+                        char c = (char)b[i];
+
+                        if (c != '\n') {
+                            sb.append(c);
+                            continue;
+                        }
+
+
+                        // Got end-of-line
+                        int len = sb.length();
+                        if (len > 0) {
+                            if (sb.charAt(len-1) != '\r') {
+                                System.err.println("Unexpected CR in header!!");
+                                return;
+                            }
+                        }
+                        sb.setLength(len-1);
+
+                        // empty line
+                        if (sb.length() == 0) {
+                            if (cl < 0) {
+                                System.err.println("Content-Length not found!!!");
+                                return;
+                            }
+
+                            // the surplus is body data
+                            int dataRead = n - (i+1);
+                            remaining = cl - dataRead;
+                            if (remaining > 0) {
+                                inBody = true;
+                                break;
+                            } else {
+                                // entire body has been read
+                                sendResponse = true;
+                            }
+                        } else {
+                            // non-empty line - check for Content-Length
+                            String line = sb.toString().toLowerCase();
+                            if (line.startsWith("content-length")) {
+                                StringTokenizer st = new StringTokenizer(line, ":");
+                                st.nextToken();
+                                cl = Integer.parseInt(st.nextToken().trim());
+                            }
+                            if (line.startsWith("connection")) {
+                                StringTokenizer st = new StringTokenizer(line, ":");
+                                st.nextToken();
+                                if (st.nextToken().trim().equals("close")) {
+                                    close =true;
+                                }
+                            }
+                        }
+                        sb = new StringBuffer();
+                    }
+
+
+                   if (sendResponse) {
+                        // send a large response
+                        int rspLen = 32000;
+
+                        out.print("HTTP/1.1 200 OK\r\n");
+                        out.print("Content-Length: " + rspLen + "\r\n");
+                        out.print("\r\n");
+
+                        if (rspLen > 0)
+                            out.write(new byte[rspLen]);
+
+                        out.flush();
+
+                        if (close)
+                            return;
+
+                        sendResponse = false;
+                        inBody = false;
+                        cl = -1;
+                   }
+                }
+
+            } catch (IOException ioe) {
+            } finally {
+                try {
+                    s.close();
+                } catch (Exception e) { }
+                System.out.println("+ Worker thread shutdown.");
+            }
+        }
+    }
+
+    /*
+     * Server thread to accept connection and create worker threads
+     * to service each connection.
+     */
+    static class Server extends Thread {
+        ServerSocket ss;
+
+        Server(ServerSocket ss) {
+            this.ss = ss;
+        }
+
+        public void run() {
+            try {
+                for (;;) {
+                    Socket s = ss.accept();
+                    Worker w = new Worker(s);
+                    w.start();
+                }
+
+            } catch (IOException ioe) {
+            }
+
+            System.out.println("+ Server shutdown.");
+        }
+
+        public void shutdown() {
+            try {
+                ss.close();
+            } catch (IOException ioe) { }
+        }
+    }
+
+    static URLConnection doRequest(String uri) throws IOException {
+        URLConnection uc = (new URL(uri)).openConnection();
+        uc.setDoOutput(true);
+        OutputStream out = uc.getOutputStream();
+        out.write(new byte[16000]);
+
+        // force the request to be sent
+        uc.getInputStream();
+        return uc;
+    }
+
+    static URLConnection doResponse(URLConnection uc) throws IOException {
+        int cl = ((HttpURLConnection)uc).getContentLength();
+        byte b[] = new byte[4096];
+        int n;
+        do {
+            n = uc.getInputStream().read(b);
+            if (n > 0) cl -= n;
+        } while (n > 0);
+        if (cl != 0) {
+            throw new RuntimeException("ERROR: content-length mismatch");
+        }
+        return uc;
+    }
+
+    public static void main(String args[]) throws Exception {
+        Random r = new Random();
+
+        // start server
+        ServerSocket ss = new ServerSocket(0);
+        Server svr = new Server(ss);
+        svr.start();
+
+        String uri = "http://localhost:" +
+                     Integer.toString(ss.getLocalPort()) +
+                     "/foo.html";
+
+        /*
+         * The following is the test scenario we create here :-
+         *
+         * 1. We do a http request/response and read the response
+         *    to EOF. As it's a persistent connection the idle
+         *    connection should go into the keep-alive cache for a
+         *    few seconds.
+         *
+         * 2. We start a second request but don't read the response.
+         *    As the request is to the same server we can assume it
+         *    (for our implementation anyway) that it will use the
+         *    same TCP connection.
+         *
+         * 3. We "disconnect" the first HttpURLConnection. This
+         *    should be no-op because the connection is in use
+         *    but another request. However with 1.3.1 and 1.4/1.4.1
+         *    this causes the TCP connection for the second request
+         *    to be closed.
+         *
+         */
+        URLConnection uc1 = doRequest(uri);
+        doResponse(uc1);
+
+        Thread.currentThread().sleep(2000);
+
+        URLConnection uc2 = doRequest(uri);
+
+        ((HttpURLConnection)uc1).disconnect();
+
+        IOException ioe = null;
+        try {
+            doResponse(uc2);
+        } catch (IOException x) {
+            ioe = x;
+        }
+
+        ((HttpURLConnection)uc2).disconnect();
+
+        /*
+         * Shutdown server as we are done. Worker threads created
+         * by the server will shutdown automatically when the
+         * client connection closes.
+         */
+        svr.shutdown();
+
+        if (ioe != null) {
+            throw ioe;
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/ExifContentGuesser.java b/test/java/net/URLConnection/ExifContentGuesser.java
new file mode 100644
index 0000000..81bc754
--- /dev/null
+++ b/test/java/net/URLConnection/ExifContentGuesser.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4639576
+ * @summary java.net.URLConnection.guessContentTypeFromStream cannot
+ * handle Exif format
+ */
+
+import java.net.URLConnection;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+
+/**
+ * This test makes sure that URLConnection.guessContentTypeFromStream
+ * recognizes Exif file format. This test uses the file:
+ * olympus.jpg for testing the same.
+ */
+
+public class ExifContentGuesser {
+
+    public static void main(String args[]) throws Exception {
+        String filename = System.getProperty("test.src", ".") +
+                          "/" + "olympus.jpg";
+        System.out.println("filename: " + filename);
+        InputStream in = null;
+
+        try {
+            in = new BufferedInputStream(new FileInputStream(filename));
+
+            String content_type = URLConnection.guessContentTypeFromStream(in);
+            if (content_type == null) {
+                throw new Exception("Test failed: Could not recognise " +
+                                "Exif image");
+            } else {
+                System.out.println("content-type: " + content_type);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/GetContentType.java b/test/java/net/URLConnection/GetContentType.java
new file mode 100644
index 0000000..652ab9a
--- /dev/null
+++ b/test/java/net/URLConnection/GetContentType.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4112524
+ * @summary check for correct implementation of getContentType for JAR urls.
+ */
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.jar.*;
+import java.util.zip.*;
+
+public class GetContentType {
+
+    static final String JAR_MIME_TYPE = "x-java/jar";
+    static final String GIF_MIME_TYPE = "image/gif";
+
+    public static void main(String[] args) throws Exception {
+        /* test JAR URLs -- NOTE: we musn't connect! */
+        URL url = new URL(getSpec());
+        URLConnection connection = url.openConnection();
+        String contentType = connection.getContentType();
+        System.out.println(url + " jar content type: " + contentType);
+        if (!contentType.equals(JAR_MIME_TYPE)) {
+            throw new RuntimeException("invalid MIME type for JAR archive");
+        }
+        url = new URL(url, "image.gif");
+        connection = url.openConnection();
+        contentType = connection.getContentType();
+        System.out.println(url + " img content type: " + contentType);
+        if (!contentType.equals(GIF_MIME_TYPE)) {
+            throw new RuntimeException("invalid MIME type for JAR entry");
+        }
+    }
+
+    static String getSpec() throws IOException {
+        File file = new File(".");
+        return "jar:file:" + file.getCanonicalPath() +
+            File.separator + "jars" + File.separator + "test.jar!/";
+    }
+
+}
diff --git a/test/java/net/URLConnection/GetFileNameMap.java b/test/java/net/URLConnection/GetFileNameMap.java
new file mode 100644
index 0000000..2cf2083
--- /dev/null
+++ b/test/java/net/URLConnection/GetFileNameMap.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4075040
+ * @summary Make sure the Mimetable is initialized
+ *    at first use.
+ */
+
+import java.net.*;
+
+public class GetFileNameMap {
+    public static void main(String[] args) throws Exception {
+        FileNameMap map = URLConnection.getFileNameMap();
+        String s = map.getContentTypeFor("test.pdf");
+    }
+}
diff --git a/test/java/net/URLConnection/GetLastModified.java b/test/java/net/URLConnection/GetLastModified.java
new file mode 100644
index 0000000..cbaec83
--- /dev/null
+++ b/test/java/net/URLConnection/GetLastModified.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4109476
+ * @summary Test that URLConnection.getLastModified returns the last
+ *          modified date on files and jar files.
+ */
+import java.net.URL;
+import java.net.URLConnection;
+import java.io.File;
+
+public class GetLastModified {
+
+    static boolean testFailed = false;
+
+    static void test(String s) throws Exception {
+        URL url = new URL(s);
+        URLConnection conn = url.openConnection();
+        if (conn.getLastModified() == 0) {
+            System.out.println("Failed: getLastModified returned 0 for URL: " + s);
+            testFailed = true;
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+
+        File file = new File(System.getProperty("test.src", "."), "jars");
+
+        String fileURL = "file:" + file.getCanonicalPath() + file.separator +
+                         "test.jar";
+        test(fileURL);
+
+        String jarURL = "jar:" + fileURL + "!/";
+        test(jarURL);
+
+        if (testFailed) {
+            throw new Exception("Test failed - getLastModified returned 0");
+        }
+    }
+
+}
diff --git a/test/java/net/URLConnection/GetResponseCode.java b/test/java/net/URLConnection/GetResponseCode.java
new file mode 100644
index 0000000..9056884
--- /dev/null
+++ b/test/java/net/URLConnection/GetResponseCode.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ *
+ * @bug 4191815
+ * @summary Check that getResponseCode doesn't throw exception if http
+ *          respone code is >= 400.
+ */
+import java.net.*;
+import java.io.*;
+
+public class GetResponseCode implements Runnable {
+
+    ServerSocket ss;
+
+    /*
+     * Our "http" server to return a 404
+     */
+    public void run() {
+        try {
+            Socket s = ss.accept();
+
+            PrintStream out = new PrintStream(
+                                 new BufferedOutputStream(
+                                    s.getOutputStream() ));
+
+            /* send the header */
+            out.print("HTTP/1.1 404 Not Found\r\n");
+            out.print("Content-Type: text/html; charset=iso-8859-1\r\n");
+            out.print("Connection: close\r\n");
+            out.print("\r\n");
+            out.print("<HTML>");
+            out.print("<HEAD><TITLE>404 Not Found</TITLE></HEAD>");
+            out.print("<BODY>The requested URL was not found.</BODY>");
+            out.print("</HTML>");
+            out.flush();
+
+            s.close();
+            ss.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    GetResponseCode() throws Exception {
+
+        /* start the server */
+        ss = new ServerSocket(0);
+        (new Thread(this)).start();
+
+        /* establish http connection to server */
+        String uri = "http://localhost:" +
+                     Integer.toString(ss.getLocalPort()) +
+                     "/missing.nothtml";
+        URL url = new URL(uri);
+
+        HttpURLConnection http = (HttpURLConnection)url.openConnection();
+
+        int respCode = http.getResponseCode();
+
+        http.disconnect();
+
+    }
+
+    public static void main(String args[]) throws Exception {
+        new GetResponseCode();
+    }
+
+}
diff --git a/test/java/net/URLConnection/GetXmlContentType.java b/test/java/net/URLConnection/GetXmlContentType.java
new file mode 100644
index 0000000..562a658
--- /dev/null
+++ b/test/java/net/URLConnection/GetXmlContentType.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4160195
+ * @summary Check for correct detection of XML content type
+ */
+
+import java.io.*;
+import java.net.*;
+
+
+public class GetXmlContentType {
+
+    static final String XML_MIME_TYPE = "application/xml";
+
+    // guess type from content and filename
+    static final String goodFiles [] = {
+        "xml1",         // US-ASCII and supersets
+        "xml2.xml",     // typed inferred from filename
+        "xml3",         // UTF-16 little endian (partial)
+        "xml4"          // UTF-16 big endian (partial)
+        };
+
+    // some common non-XML examples
+    static final String badFiles [] = {
+        "not-xml1",
+        "not-xml2"
+        };
+
+    public static void main(String[] args) throws Exception {
+        boolean sawError = false;
+
+        //
+        // POSITIVE tests:  good data --> good result
+        //
+        for (int i = 0; i < goodFiles.length; i++) {
+            String      result = getUrlContentType (goodFiles [i]);
+
+            if (!XML_MIME_TYPE.equals (result)) {
+                System.out.println ("Wrong MIME type: "
+                    + goodFiles [i]
+                    + " --> " + result
+                    );
+                sawError = true;
+            }
+        }
+
+        //
+        // NEGATIVE tests:  bad data --> correct diagnostic
+        //
+        for (int i = 0; i < badFiles.length; i++) {
+            String      result = getUrlContentType (badFiles [i]);
+
+            if (XML_MIME_TYPE.equals (result)) {
+                System.out.println ("Wrong MIME type: "
+                    + badFiles [i]
+                    + " --> " + result
+                    );
+                sawError = true;
+            }
+        }
+
+        if (sawError)
+            throw new Exception (
+                "GetXmlContentType Test failed; see diagnostics.");
+    }
+
+    static String getUrlContentType (String name) throws IOException {
+        File            file = new File(System.getProperty("test.src", "."), "xml");
+        URL             u = new URL ("file:"
+                            + file.getCanonicalPath()
+                            + file.separator
+                            + name);
+        URLConnection   conn = u.openConnection ();
+
+        return conn.getContentType ();
+    }
+
+}
diff --git a/test/java/net/URLConnection/HandleContentTypeWithAttrs.java b/test/java/net/URLConnection/HandleContentTypeWithAttrs.java
new file mode 100644
index 0000000..327aa26
--- /dev/null
+++ b/test/java/net/URLConnection/HandleContentTypeWithAttrs.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright 1998-2000 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4160200
+ * @summary Make sure URLConnection.getContnentHandler
+ *     can handle MIME types with attributes
+ */
+import java.net.*;
+import java.io.*;
+import sun.net.www.content.text.*;
+import sun.net.www.MessageHeader;
+
+public class HandleContentTypeWithAttrs {
+
+    URL url;
+
+    public HandleContentTypeWithAttrs (int port) throws Exception {
+
+        String localHostName = InetAddress.getLocalHost().getHostName();
+
+        // Request echo.html from myHttpServer.
+        // In the header of the response, we make
+        // the content type have some attributes.
+        url = new URL("http://" + localHostName + ":" + port + "/echo.html");
+        URLConnection urlConn = url.openConnection();
+
+        // the method getContent() calls the method
+        // getContentHandler(). With the fix, the method
+        // getContentHandler() gets the correct content
+        // handler for our response -  it should be the
+        // PlainText conten handler; without the fix,
+        // it gets the UnknownContent handler.
+        // So based on what the getContent()
+        // returns, we know whether getContentHandler()
+        // can handle content type with attributes or not.
+        Object obj = urlConn.getContent();
+
+        if (!(obj instanceof PlainTextInputStream))
+            throw new Exception("Cannot get the correct content handler.");
+    }
+
+    public static void main(String [] argv) throws Exception {
+        // Start myHttpServer
+        myHttpServer testServer = new myHttpServer();
+        testServer.startServer(0);
+        int serverPort = testServer.getServerLocalPort();
+        new HandleContentTypeWithAttrs(serverPort);
+    }
+}
+
+// myHttpServer is pretty much like
+// sun.net.www.httpd.BasicHttpServer.
+// But we only need it to handle one
+// simple request.
+class myHttpServer implements Runnable, Cloneable {
+
+    /** Socket for communicating with client. */
+    public Socket clientSocket = null;
+    private Thread serverInstance;
+    private ServerSocket serverSocket;
+
+    /** Stream for printing to the client. */
+    public PrintStream clientOutput;
+
+    /** Buffered stream for reading replies from client. */
+    public InputStream clientInput;
+
+    static URL defaultContext;
+
+    /** Close an open connection to the client. */
+    public void close() throws IOException {
+        clientSocket.close();
+        clientSocket = null;
+        clientInput = null;
+        clientOutput = null;
+    }
+
+    final public void run() {
+        if (serverSocket != null) {
+            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
+
+            try {
+                // wait for incoming request
+                Socket ns = serverSocket.accept();
+                myHttpServer n = (myHttpServer)clone();
+                n.serverSocket = null;
+                n.clientSocket = ns;
+                new Thread(n).start();
+            } catch(Exception e) {
+                System.out.print("Server failure\n");
+                e.printStackTrace();
+                try {
+                    serverSocket.close();
+                } catch(IOException e2) {}
+            }
+        } else {
+            try {
+                clientOutput = new PrintStream(
+                    new BufferedOutputStream(clientSocket.getOutputStream()),
+                                             false);
+                clientInput = new BufferedInputStream(
+                                             clientSocket.getInputStream());
+                serviceRequest();
+
+            } catch(Exception e) {
+                // System.out.print("Service handler failure\n");
+                // e.printStackTrace();
+            }
+            try {
+                close();
+            } catch(IOException e2) {}
+        }
+    }
+
+    /** Start a server on port <i>port</i>.  It will call serviceRequest()
+        for each new connection. */
+    final public void startServer(int port) throws IOException {
+        serverSocket = new ServerSocket(port, 50);
+        serverInstance = new Thread(this);
+        serverInstance.start();
+    }
+
+    final public int getServerLocalPort() throws Exception {
+        if (serverSocket != null) {
+            return serverSocket.getLocalPort();
+        }
+        throw new Exception("serverSocket is null");
+    }
+
+    MessageHeader mh;
+
+    final public void serviceRequest() {
+        //totalConnections++;
+        try {
+            mh = new MessageHeader(clientInput);
+            String cmd = mh.findValue(null);
+            // if (cmd == null) {
+            //  error("Missing command " + mh);
+            //  return;
+            // }
+            int fsp = cmd.indexOf(' ');
+            // if (fsp < 0) {
+            //  error("Syntax error in command: " + cmd);
+            //  return;
+            //  }
+            String k = cmd.substring(0, fsp);
+            int nsp = cmd.indexOf(' ', fsp + 1);
+            String p1, p2;
+            if (nsp > 0) {
+                p1 = cmd.substring(fsp + 1, nsp);
+                p2 = cmd.substring(nsp + 1);
+            } else {
+                p1 = cmd.substring(fsp + 1);
+                p2 = null;
+            }
+            // expectsMime = p2 != null;
+            if (k.equalsIgnoreCase("get"))
+                getRequest(new URL(defaultContext, p1), p2);
+            else {
+                //      error("Unknown command: " + k + " (" + cmd + ")");
+                return;
+            }
+        } catch(IOException e) {
+            // totally ignore IOException.  They're usually client crashes.
+        } catch(Exception e) {
+            //  error("Exception: " + e);
+            e.printStackTrace();
+        }
+    }
+
+    /** Satisfy one get request.  It is invoked with the clientInput and
+        clientOutput streams initialized.  This method handles one client
+        connection. When it is done, it can simply exit. The default
+        server just echoes it's input. */
+    protected void getRequest(URL u, String param) {
+        try {
+            if (u.getFile().equals("/echo.html")) {
+               startHtml("Echo reply");
+               clientOutput.print("<p>URL was " + u.toExternalForm() + "\n");
+               clientOutput.print("<p>Socket was " + clientSocket + "\n<p><pre>");
+               mh.print(clientOutput);
+           }
+        } catch(Exception e) {
+            System.out.print("Failed on "+u.getFile()+"\n");
+            e.printStackTrace();
+        }
+    }
+     /**
+      * Clone this object;
+     */
+    public Object clone() {
+        try {
+            return super.clone();
+        } catch (CloneNotSupportedException e) {
+            // this shouldn't happen, since we are Cloneable
+            throw new InternalError();
+        }
+    }
+
+    public myHttpServer () {
+        try {
+            defaultContext
+            = new URL("http", InetAddress.getLocalHost().getHostName(), "/");
+        } catch(Exception e) {
+            System.out.println("Failed to construct defauit URL context: "
+                               + e);
+            e.printStackTrace();
+        }
+    }
+
+    // Make the content type have some attributes
+    protected void startHtml(String title) {
+        clientOutput.print("HTTP/1.0 200 Document follows\n" +
+                           "Server: Java/" + getClass().getName() + "\n" +
+                           "Content-type: text/plain; charset=Shift_JIS \n\n");
+    }
+
+}
diff --git a/test/java/net/URLConnection/HttpContinueStackOverflow.java b/test/java/net/URLConnection/HttpContinueStackOverflow.java
new file mode 100644
index 0000000..a3ded61
--- /dev/null
+++ b/test/java/net/URLConnection/HttpContinueStackOverflow.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2000-2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4258697
+ * @summary Make sure that http CONTINUE status followed by invalid
+ * response doesn't cause HttpClient to recursively loop and
+ * eventually StackOverflow.
+ *
+ */
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URL;
+import java.net.HttpURLConnection;
+
+public class HttpContinueStackOverflow {
+
+    static class Server implements Runnable {
+        int port;
+
+        Server(int port) {
+            this.port = port;
+        }
+
+        public void run() {
+            try {
+                /* bind to port and wait for connection */
+                ServerSocket serverSock = new ServerSocket(     port );
+                serverSock.setSoTimeout(10000);
+                Socket sock = serverSock.accept();
+
+                /* setup streams and read http request */
+                BufferedReader in = new BufferedReader(
+                    new InputStreamReader(sock.getInputStream()));
+                PrintStream out = new PrintStream( sock.getOutputStream() );
+                String request = in.readLine();
+
+                /* send continue followed by invalid response */
+                out.println("HTTP/1.1 100 Continue\r");
+                out.println("\r");
+                out.println("junk junk junk");
+                out.flush();
+
+                sock.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    HttpContinueStackOverflow(int port) throws Exception {
+        /* create the server */
+        Server s = new Server(port);
+        Thread thr = new Thread(s);
+        thr.start();
+
+        /* wait for server to bind to port */
+        try {
+            Thread.currentThread().sleep(2000);
+        } catch (Exception e) { }
+
+        /* connect to server, connect to server and get response code */
+        URL url = new URL("http", "localhost", port, "anything.html");
+        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+        int respCode = conn.getResponseCode();
+        System.out.println("TEST PASSED");
+    }
+
+    public static void main(String args[]) throws Exception {
+        int port = 4090;
+        if (args.length > 0) {
+            port = Integer.parseInt(args[0]);
+        }
+        System.out.println("Testing 100-Continue");
+        new HttpContinueStackOverflow(port);
+    }
+}
diff --git a/test/java/net/URLConnection/Redirect307Test.java b/test/java/net/URLConnection/Redirect307Test.java
new file mode 100644
index 0000000..f6dc0c7
--- /dev/null
+++ b/test/java/net/URLConnection/Redirect307Test.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4380568
+ * @summary  HttpURLConnection does not support 307 redirects
+ */
+import java.io.*;
+import java.net.*;
+
+class RedirServer extends Thread {
+
+    ServerSocket s;
+    Socket   s1;
+    InputStream  is;
+    OutputStream os;
+    int port;
+
+    String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
+        "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
+        "Server: Apache/1.3.14 (Unix)\r\n" +
+        "Location: http://localhost:";
+    String reply2 = "/redirected.html\r\n" +
+        "Connection: close\r\n" +
+        "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
+        "<html>Hello</html>";
+
+    RedirServer (ServerSocket y) {
+        s = y;
+        port = s.getLocalPort();
+    }
+
+    String reply3 = "HTTP/1.1 200 Ok\r\n" +
+        "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
+        "Server: Apache/1.3.14 (Unix)\r\n" +
+        "Connection: close\r\n" +
+        "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
+        "World";
+
+    public void run () {
+        try {
+            s1 = s.accept ();
+            is = s1.getInputStream ();
+            os = s1.getOutputStream ();
+            is.read ();
+            String reply = reply1 + port + reply2;
+            os.write (reply.getBytes());
+            /* wait for redirected connection */
+            s.setSoTimeout (5000);
+            s1 = s.accept ();
+            os = s1.getOutputStream ();
+            os.write (reply3.getBytes());
+        }
+        catch (Exception e) {
+            /* Just need thread to terminate */
+        }
+    }
+};
+
+
+public class Redirect307Test {
+
+    public static final int DELAY = 10;
+
+    public static void main(String[] args) throws Exception {
+        int nLoops = 1;
+        int nSize = 10;
+        int port, n =0;
+        byte b[] = new byte[nSize];
+        RedirServer server;
+        ServerSocket sock;
+
+        try {
+            sock = new ServerSocket (0);
+            port = sock.getLocalPort ();
+        }
+        catch (Exception e) {
+            System.out.println ("Exception: " + e);
+            return;
+        }
+
+        server = new RedirServer(sock);
+        server.start ();
+
+        try  {
+
+            String s = "http://localhost:" + port;
+            URL url = new URL(s);
+            URLConnection conURL =  url.openConnection();
+
+            conURL.setDoInput(true);
+            conURL.setAllowUserInteraction(false);
+            conURL.setUseCaches(false);
+
+            InputStream in = conURL.getInputStream();
+            if ((in.read() != (int)'W') || (in.read()!=(int)'o')) {
+                throw new RuntimeException ("Unexpected string read");
+            }
+        }
+        catch(IOException e) {
+            throw new RuntimeException ("Exception caught");
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/RedirectLimit.java b/test/java/net/URLConnection/RedirectLimit.java
new file mode 100644
index 0000000..594d25f
--- /dev/null
+++ b/test/java/net/URLConnection/RedirectLimit.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4458085
+ * @summary  Redirects Limited to 5
+ */
+
+/*
+ * Simulate a server that redirects ( to a different URL) 9 times
+ * and see if the client correctly follows the trail
+ */
+
+import java.io.*;
+import java.net.*;
+
+class RedirLimitServer extends Thread {
+
+    ServerSocket s;
+    Socket   s1;
+    InputStream  is;
+    OutputStream os;
+    int port;
+    int nredirects = 9;
+
+    String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
+        "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
+        "Server: Apache/1.3.14 (Unix)\r\n" +
+        "Location: http://localhost:";
+    String reply2 = ".html\r\n" +
+        "Connection: close\r\n" +
+        "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
+        "<html>Hello</html>";
+
+    RedirLimitServer (ServerSocket y) {
+        s = y;
+        port = s.getLocalPort();
+    }
+
+    String reply3 = "HTTP/1.1 200 Ok\r\n" +
+        "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
+        "Server: Apache/1.3.14 (Unix)\r\n" +
+        "Connection: close\r\n" +
+        "Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
+        "World";
+
+    public void run () {
+        try {
+            s.setSoTimeout (2000);
+            for (int i=0; i<nredirects; i++) {
+                s1 = s.accept ();
+                s1.setSoTimeout (2000);
+                is = s1.getInputStream ();
+                os = s1.getOutputStream ();
+                is.read ();
+                String reply = reply1 + port + "/redirect" + i + reply2;
+                os.write (reply.getBytes());
+            }
+            s1 = s.accept ();
+            is = s1.getInputStream ();
+            os = s1.getOutputStream ();
+            is.read ();
+            os.write (reply3.getBytes());
+        }
+        catch (Exception e) {
+            /* Just need thread to terminate */
+        }
+    }
+};
+
+
+public class RedirectLimit {
+
+    public static final int DELAY = 10;
+
+    public static void main(String[] args) throws Exception {
+        int nLoops = 1;
+        int nSize = 10;
+        int port, n =0;
+        byte b[] = new byte[nSize];
+        RedirLimitServer server;
+        ServerSocket sock;
+
+        try {
+            sock = new ServerSocket (0);
+            port = sock.getLocalPort ();
+        }
+        catch (Exception e) {
+            System.out.println ("Exception: " + e);
+            return;
+        }
+
+        server = new RedirLimitServer(sock);
+        server.start ();
+
+        try  {
+
+            String s = "http://localhost:" + port;
+            URL url = new URL(s);
+            URLConnection conURL =  url.openConnection();
+
+            conURL.setDoInput(true);
+            conURL.setAllowUserInteraction(false);
+            conURL.setUseCaches(false);
+
+            InputStream in = conURL.getInputStream();
+            if ((in.read() != (int)'W') || (in.read()!=(int)'o')) {
+                throw new RuntimeException ("Unexpected string read");
+            }
+        }
+        catch(IOException e) {
+            throw new RuntimeException ("Exception caught " + e);
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/RequestProperties.java b/test/java/net/URLConnection/RequestProperties.java
new file mode 100644
index 0000000..9f1d089
--- /dev/null
+++ b/test/java/net/URLConnection/RequestProperties.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4485208
+ * @summary  file: and ftp: URL handlers need to throw NPE in setRequestProperty
+ */
+
+import java.net.*;
+
+public class RequestProperties {
+    public static void main (String args[]) throws Exception {
+        URL url0 = new URL ("http://foo.com/bar/");
+        URL url1 = new URL ("file:/etc/passwd");
+        URL url2 = new URL ("ftp://foo:bar@foobar.com/etc/passwd");
+        URL url3 = new URL ("jar:http://foo.com/bar.html!/foo/bar");
+        URLConnection urlc0 = url0.openConnection ();
+        URLConnection urlc1 = url1.openConnection ();
+        URLConnection urlc2 = url2.openConnection ();
+        URLConnection urlc3 = url3.openConnection ();
+        int count = 0;
+        String s = null;
+        try {
+            urlc0.setRequestProperty (null, null);
+            System.out.println ("http: setRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        try {
+            urlc0.addRequestProperty (null, null);
+            System.out.println ("http: addRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        try {
+            urlc1.setRequestProperty (null, null);
+            System.out.println ("file: setRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        try {
+            urlc1.addRequestProperty (null, null);
+            System.out.println ("file: addRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        try {
+            urlc2.setRequestProperty (null, null);
+            System.out.println ("ftp: setRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        try {
+            urlc2.addRequestProperty (null, null);
+            System.out.println ("ftp: addRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        try {
+            urlc3.setRequestProperty (null, null);
+            System.out.println ("jar: setRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        try {
+            urlc3.addRequestProperty (null, null);
+            System.out.println ("jar: addRequestProperty (null,) did not throw NPE");
+        } catch (NullPointerException e) {
+            count ++;
+        }
+        if (urlc0.getRequestProperty (null) != null) {
+            System.out.println ("http: getRequestProperty (null,) did not return null");
+        } else {
+            count ++;
+        }
+        if (urlc1.getRequestProperty (null) != null) {
+            System.out.println ("file: getRequestProperty (null,) did not return null");
+        } else {
+            count ++;
+        }
+        if (urlc2.getRequestProperty (null) != null) {
+            System.out.println ("ftp: getRequestProperty (null,) did not return null");
+        } else {
+            count ++;
+        }
+        if (urlc2.getRequestProperty (null) != null) {
+            System.out.println ("jar: getRequestProperty (null,) did not return null");
+        } else {
+            count ++;
+        }
+
+        if (count != 12) {
+            throw new RuntimeException ((12 -count) + " errors") ;
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/RequestPropertyValues.java b/test/java/net/URLConnection/RequestPropertyValues.java
new file mode 100644
index 0000000..ea6eb1a
--- /dev/null
+++ b/test/java/net/URLConnection/RequestPropertyValues.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4644775 6230836
+ * @summary Test URLConnection Request Proterties
+ */
+
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * Part1:
+ *   bug 4644775: Unexpected NPE in setRequestProperty(key, null) call
+ * Part2:
+ *   bug 6230836: A few methods of class URLConnection implemented incorrectly
+ */
+
+public class RequestPropertyValues {
+
+    public static void main(String[] args) throws Exception {
+        part1();
+        part2();
+    }
+
+    public static void part1() throws Exception {
+        URL[] urls = { new URL("http://localhost:8088"),
+                        new URL("file:/etc/passwd"),
+                        new URL("ftp://foo:bar@foobar.com/etc/passwd"),
+                        new URL("jar:http://foo.com/bar.html!/foo/bar")
+                    };
+
+        boolean failed = false;
+
+        for (int proto = 0; proto < urls.length; proto++) {
+            URLConnection uc = (URLConnection) urls[proto].openConnection();
+            try {
+                uc.setRequestProperty("TestHeader", null);
+            } catch (NullPointerException npe) {
+                System.out.println("setRequestProperty is throwing NPE" +
+                                " for url: " + urls[proto]);
+                failed = true;
+            }
+            try {
+                uc.addRequestProperty("TestHeader", null);
+            } catch (NullPointerException npe) {
+                System.out.println("addRequestProperty is throwing NPE" +
+                                " for url: " + urls[proto]);
+                failed = true;
+            }
+        }
+        if (failed) {
+            throw new Exception("RequestProperty setting/adding is" +
+                                " throwing NPE for null values");
+        }
+    }
+
+    public static void part2() throws Exception {
+        URL url = null;
+        String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
+        String[] goodValues = {"", "$", "value", "Value", " ", "    "};
+
+        URLConnection conn = getConnection(url);
+
+        for (int i = 0; i < goodKeys.length; ++i) {
+            for (int j = 0; j < goodValues.length; ++j) {
+                // If a property with the key already exists, overwrite its value with the new value
+                conn.setRequestProperty(goodKeys[i], goodValues[j]);
+                String value = conn.getRequestProperty(goodKeys[i]);
+
+                if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
+                    throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
+            }
+        }
+    }
+
+    static URLConnection getConnection(URL url) {
+        return new DummyURLConnection(url);
+    }
+
+    static class DummyURLConnection extends URLConnection {
+
+        DummyURLConnection(URL url) {
+            super(url);
+        }
+
+        public void connect() {
+            connected = true;
+        }
+    }
+
+}
diff --git a/test/java/net/URLConnection/ResendPostBody.java b/test/java/net/URLConnection/ResendPostBody.java
new file mode 100644
index 0000000..2da95ad
--- /dev/null
+++ b/test/java/net/URLConnection/ResendPostBody.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2001-2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4361492
+ * @summary HTTPUrlConnection does not receive binary data correctly
+ * @run main/timeout=20 ResendPostBody
+ */
+
+import java.io.*;
+import java.net.*;
+
+/*
+ * This test does the following:
+ * 1. client opens HTTP connection to server
+ * 2. client sends POST with a body containing "ZZZ"
+ * 3. server waits for POST and closes connection without replying
+ * 4. client should re-open the connection and re-send the POST
+ * 5. <bug>The client forgets to re-send the body with the POST
+ *    The server hangs waiting for the body</bug>
+ *
+ *    <bugfixed>The client sends the body. The server reads it and the
+ *     test terminates normally </bugfixed>
+ */
+
+public class ResendPostBody {
+
+    static class Server extends Thread {
+
+        InputStream     in;
+        OutputStream out;
+        Socket  sock;
+        StringBuffer response;
+        ServerSocket server;
+
+        Server (ServerSocket s) throws IOException
+        {
+            server = s;
+        }
+
+        void waitFor (String s) throws IOException
+        {
+            byte[] w = s.getBytes ();
+            for(int c=0; c<w.length; c++ ) {
+                byte expected = w[c];
+                int b = in.read();
+                if (b == -1) {
+                    acceptConn ();
+                }
+                if ((byte)b != expected) {
+                    c = 0;
+                }
+            }
+        }
+
+        boolean done = false;
+
+        public synchronized boolean finished () {
+            return done;
+        }
+
+        public synchronized void setFinished (boolean b) {
+            done = b;
+        }
+
+        void acceptConn () throws IOException
+        {
+            sock = server.accept ();
+            in = sock.getInputStream ();
+            out = sock.getOutputStream ();
+        }
+
+        public void run () {
+            try {
+                response = new StringBuffer (1024);
+                acceptConn ();
+                waitFor ("POST");
+                waitFor ("ZZZ");
+                Thread.sleep (500);
+                sock.close ();
+                acceptConn ();
+                waitFor ("POST");
+                waitFor ("ZZZ");
+                response.append ("HTTP/1.1 200 OK\r\n");
+                response.append ("Server: Microsoft-IIS/5.0");
+                response.append ("Date: Wed, 26 Jul 2000 14:17:04 GMT\r\n\r\n");
+                out.write (response.toString().getBytes());
+                while (!finished()) {
+                    Thread.sleep (1000);
+                }
+            } catch (Exception e) {
+                System.err.println ("Server Exception: " + e);
+            }
+        }
+    }
+
+    ServerSocket ss;
+    Server server;
+
+    public static void main(String[] args) throws Exception {
+        try {
+            if (args.length == 1 && args[0].equals ("-i")) {
+                System.out.println ("Press return when ready");
+                System.in.read ();
+                System.out.println ("Done");
+            }
+            ResendPostBody t = new ResendPostBody ();
+            t. execute ();
+        } catch (IOException  e) {
+            System.out.println ("IOException");
+        }
+    }
+
+    public void execute () throws Exception {
+
+     byte b[] = "X=ABCDEFGHZZZ".getBytes();
+
+        ss = new ServerSocket (0);
+        server = new Server (ss);
+        server.start ();
+        /* Get the URL */
+
+        String s = "http://localhost:"+ss.getLocalPort()+"/test";
+        URL url = new URL(s);
+        HttpURLConnection conURL =  (HttpURLConnection)url.openConnection();
+
+        conURL.setDoOutput(true);
+        conURL.setDoInput(true);
+        conURL.setAllowUserInteraction(false);
+        conURL.setUseCaches(false);
+        conURL.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+        conURL.setRequestProperty("Content-Length", ""+b.length);
+        conURL.setRequestProperty("Connection", "Close");
+
+        /* POST some data */
+
+        DataOutputStream OutStream = new DataOutputStream(conURL.getOutputStream());
+                          OutStream.write(b, 0, b.length);
+        OutStream.flush();
+        OutStream.close();
+
+        /* Read the response */
+
+        int resp = conURL.getResponseCode ();
+        if (resp != 200)
+            throw new RuntimeException ("Response code was not 200: " + resp);
+      server.setFinished (true);
+  }
+}
diff --git a/test/java/net/URLConnection/Responses.java b/test/java/net/URLConnection/Responses.java
new file mode 100644
index 0000000..2facb52
--- /dev/null
+++ b/test/java/net/URLConnection/Responses.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4635698
+ * @summary Check that HttpURLConnection.getResponseCode returns -1 for
+ *          malformed status-lines in the http response.
+ */
+import java.net.*;
+import java.io.*;
+
+public class Responses {
+
+    /*
+     * Test cases :-
+     *       "Response from server"     expected getResponse() and
+     *                                  getResponseMessage() results
+     */
+    static Object[][] getTests() {
+        return new Object[][] {
+            { "HTTP/1.1 200 OK",        "200",  "OK" },
+            { "HTTP/1.1 404 ",          "404",  null },
+            { "HTTP/1.1 200",           "200",  null },
+            { "HTTP/1.1",               "-1",   null },
+            { "Invalid",                "-1",   null },
+            { null,                     "-1" ,  null },
+        };
+    }
+
+    /*
+     * Simple http server used by test
+     *
+     * GET /<n> HTTP/1.x results in http response with the status line
+     * set to geTests()[<n>][0]  -- eg: GET /2 results in a response of
+     * "HTTP/1.1 404 "
+     */
+    static class HttpServer implements Runnable {
+        ServerSocket ss;
+
+        public HttpServer() {
+            try {
+                ss = new ServerSocket(0);
+            } catch (IOException ioe) {
+                throw new Error("Unable to create ServerSocket: " + ioe);
+            }
+        }
+
+        public int port() {
+            return ss.getLocalPort();
+        }
+
+        public void shutdown() throws IOException {
+            ss.close();
+        }
+
+        public void run() {
+            Object[][] tests = getTests();
+
+            try {
+                for (;;) {
+                    Socket s = ss.accept();
+
+                    BufferedReader in = new BufferedReader(
+                                              new InputStreamReader(
+                                                s.getInputStream()));
+                    String req = in.readLine();
+                    int pos1 = req.indexOf(' ');
+                    int pos2 = req.indexOf(' ', pos1+1);
+
+                    int i = Integer.parseInt(req.substring(pos1+2, pos2));
+
+                    PrintStream out = new PrintStream(
+                                        new BufferedOutputStream(
+                                          s.getOutputStream() ));
+
+                    out.print( tests[i][0] );
+                    out.print("\r\n");
+                    out.print("Content-Length: 0\r\n");
+                    out.print("Connection: close\r\n");
+                    out.print("\r\n");
+                    out.flush();
+
+                    s.shutdownOutput();
+                    s.close();
+                }
+            } catch (Exception e) {
+            }
+        }
+    }
+
+
+    public static void main(String args[]) throws Exception {
+
+        /* start the http server */
+        HttpServer svr = new HttpServer();
+        (new Thread(svr)).start();
+
+        int port = svr.port();
+
+        /*
+         * Iterate through each test case and check that getResponseCode
+         * returns the expected result.
+         */
+        int failures = 0;
+        Object tests[][] = getTests();
+        for (int i=0; i<tests.length; i++) {
+
+            System.out.println("******************");
+            System.out.println("Test with response: >" + tests[i][0] + "<");
+
+            URL url = new URL("http://localhost:" + port + "/" + i);
+            HttpURLConnection http = (HttpURLConnection)url.openConnection();
+
+            try {
+
+                // test getResponseCode
+                //
+                int expectedCode = Integer.parseInt((String)tests[i][1]);
+                int actualCode = http.getResponseCode();
+                if (actualCode != expectedCode) {
+                    System.out.println("getResponseCode returned: " + actualCode +
+                        ", expected: " + expectedCode);
+                    failures++;
+                    continue;
+                }
+
+                // test getResponseMessage
+                //
+                String expectedPhrase = (String)tests[i][2];
+                String actualPhrase = http.getResponseMessage();
+                if (actualPhrase == null && expectedPhrase == null) {
+                    continue;
+                }
+                if (!actualPhrase.equals(expectedPhrase)) {
+                    System.out.println("getResponseMessage returned: " +
+                        actualPhrase + ", expected: " + expectedPhrase);
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+                failures++;
+            }
+        }
+
+        /* shutdown http server */
+        svr.shutdown();
+
+        if (failures > 0) {
+            throw new Exception(failures + " sub-test(s) failed.");
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/SetIfModifiedSince.java b/test/java/net/URLConnection/SetIfModifiedSince.java
new file mode 100644
index 0000000..743fc50
--- /dev/null
+++ b/test/java/net/URLConnection/SetIfModifiedSince.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2000-2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4397096
+ * @run main SetIfModifiedSince
+ * @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale
+ */
+
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+public class SetIfModifiedSince {
+
+    static class XServer extends Thread {
+        ServerSocket srv;
+        Socket s;
+        InputStream is;
+        OutputStream os;
+
+        XServer (ServerSocket s) {
+            srv = s;
+        }
+
+        Socket getSocket () {
+            return (s);
+        }
+
+        public void run() {
+            try {
+                String x;
+                s = srv.accept ();
+                is = s.getInputStream ();
+                BufferedReader r = new BufferedReader(new InputStreamReader(is));
+                os = s.getOutputStream ();
+                while ((x=r.readLine()) != null) {
+                    String header = "If-Modified-Since: ";
+                    if (x.startsWith(header)) {
+                        if (x.charAt(header.length()) == '?') {
+                            s.close ();
+                            srv.close (); // or else the HTTPURLConnection will retry
+                            throw new RuntimeException
+                                    ("Invalid HTTP date specification");
+                        }
+                        break;
+                    }
+                }
+                s.close ();
+                srv.close (); // or else the HTTPURLConnection will retry
+            } catch (IOException e) {}
+        }
+    }
+
+    public static void main (String[] args) {
+        try {
+            Locale.setDefault(Locale.JAPAN);
+            ServerSocket serversocket = new ServerSocket (0);
+            int port = serversocket.getLocalPort ();
+            XServer server = new XServer (serversocket);
+            server.start ();
+            Thread.sleep (2000);
+            URL url = new URL ("http://localhost:"+port+"/index.html");
+            URLConnection urlc = url.openConnection ();
+            urlc.setIfModifiedSince (10000000);
+            InputStream is = urlc.getInputStream ();
+            int i=0, c;
+            Thread.sleep (5000);
+        } catch (Exception e) {
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/TimeoutTest.java b/test/java/net/URLConnection/TimeoutTest.java
new file mode 100644
index 0000000..d964780
--- /dev/null
+++ b/test/java/net/URLConnection/TimeoutTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2001-2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4389976
+ * @summary    can't unblock read() of InputStream from URL connection
+ * @run main/timeout=40/othervm -Dsun.net.client.defaultReadTimeout=2000 TimeoutTest
+ */
+
+import java.io.*;
+import java.net.*;
+
+public class TimeoutTest {
+
+    class Server extends Thread {
+        ServerSocket server;
+        Server (ServerSocket server) {
+            super ();
+            this.server = server;
+        }
+        public void run () {
+            try {
+                Socket s = server.accept ();
+                while (!finished ()) {
+                    Thread.sleep (2000);
+                }
+            } catch (Exception e) {
+            }
+        }
+        boolean isFinished = false;
+
+        synchronized boolean finished () {
+            return (isFinished);
+        }
+        synchronized void done () {
+            isFinished = true;
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        TimeoutTest t = new TimeoutTest ();
+        t.test ();
+    }
+
+    public void test() throws Exception {
+        ServerSocket ss = new ServerSocket(0);
+        Server s = new Server (ss);
+        try{
+            URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort());
+            URLConnection urlc = url.openConnection ();
+            InputStream is = urlc.getInputStream ();
+        } catch (SocketTimeoutException e) {
+            s.done ();
+            return;
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/UNCTest.java b/test/java/net/URLConnection/UNCTest.java
new file mode 100644
index 0000000..072eae1
--- /dev/null
+++ b/test/java/net/URLConnection/UNCTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.net.*;
+
+public class UNCTest {
+    public static void main(String args[]) throws Exception {
+        URL url = new URL( args[0] );
+        URLConnection conn = url.openConnection();
+        conn.setRequestProperty( "User-Agent", "Java" );
+    }
+}
diff --git a/test/java/net/URLConnection/UNCTest.sh b/test/java/net/URLConnection/UNCTest.sh
new file mode 100644
index 0000000..53c4fef
--- /dev/null
+++ b/test/java/net/URLConnection/UNCTest.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+#
+# Copyright 2001-2002 Sun Microsystems, Inc.  All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+
+# @test
+# @bug 4401485
+# @run shell UNCTest.sh
+# @summary Check that URL.openConnection() doesn't open connection
+#          to UNC.
+
+UNC="file://jdk/LOCAL-JAVA/jdk1.4/win/README.txt"
+
+OS=`uname -s`
+case "$OS" in
+    Windows_95 | Windows_98 | Windows_NT )
+	${TESTJAVA}/bin/javac -d . ${TESTSRC}\\UNCTest.java
+	${TESTJAVA}/bin/java UNCTest ${UNC}
+	exit
+        ;;
+
+    * )
+        echo "This test is not intended for this OS - passing test"
+	exit 0
+        ;;
+esac
diff --git a/test/java/net/URLConnection/URLConnectionHeaders.java b/test/java/net/URLConnection/URLConnectionHeaders.java
new file mode 100644
index 0000000..22d3113
--- /dev/null
+++ b/test/java/net/URLConnection/URLConnectionHeaders.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2001-2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4143541 4147035 4244362
+ * @summary URLConnection cannot enumerate request properties,
+ *          and URLConnection can neither get nor set multiple
+ *          request properties w/ same key
+ *
+ */
+
+import java.net.*;
+import java.util.*;
+import java.io.*;
+
+public class URLConnectionHeaders {
+
+    static class XServer extends Thread {
+        ServerSocket srv;
+        Socket s;
+        InputStream is;
+        OutputStream os;
+
+        XServer (ServerSocket s) {
+            srv = s;
+        }
+
+        Socket getSocket () {
+            return (s);
+        }
+
+        public void run() {
+            try {
+                String x;
+                s = srv.accept ();
+                is = s.getInputStream ();
+                BufferedReader r = new BufferedReader(new InputStreamReader(is));
+                os = s.getOutputStream ();
+                BufferedWriter w = new BufferedWriter(new OutputStreamWriter(os));
+                w.write("HTTP/1.1 200 OK\r\n");
+                w.write("Content-Type: text/plain\r\n");
+                while ((x=r.readLine()).length() != 0) {
+                    System.out.println("request: "+x);
+                    if (!x.startsWith("GET")) {
+                        w.write(x);
+                        w.newLine();
+                    }
+                }
+                w.newLine();
+                w.flush();
+                s.close ();
+                srv.close (); // or else the HTTPURLConnection will retry
+            } catch (IOException e) { e.printStackTrace();}
+        }
+    }
+
+    public static void main(String[] args) {
+        try {
+            ServerSocket serversocket = new ServerSocket (0);
+            int port = serversocket.getLocalPort ();
+            XServer server = new XServer (serversocket);
+            server.start ();
+            Thread.sleep (200);
+            URL url = new URL ("http://localhost:"+port+"/index.html");
+            URLConnection uc = url.openConnection ();
+
+            // add request properties
+            uc.addRequestProperty("Cookie", "cookie1");
+            uc.addRequestProperty("Cookie", "cookie2");
+            uc.addRequestProperty("Cookie", "cookie3");
+
+            Map e = uc.getRequestProperties();
+
+            if (!((List)e.get("Cookie")).toString().equals("[cookie3, cookie2, cookie1]")) {
+                throw new RuntimeException("getRequestProperties fails");
+            }
+
+            e = uc.getHeaderFields();
+
+            if ((e.get("Content-Type") == null) || (e.get(null) == null)) {
+                throw new RuntimeException("getHeaderFields fails");
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/UnknownContentType.java b/test/java/net/URLConnection/UnknownContentType.java
new file mode 100644
index 0000000..8ae72de
--- /dev/null
+++ b/test/java/net/URLConnection/UnknownContentType.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4975103
+ * @summary URLConnection.getContentType() does not always return content-type header field
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class UnknownContentType {
+    public static void main(String[] args) throws Exception {
+        File tmp = File.createTempFile("bug4975103", null);
+        tmp.deleteOnExit();
+        URL url = tmp.toURL();
+        URLConnection conn = url.openConnection();
+        conn.connect();
+        String s1 = conn.getContentType();
+        String s2 = conn.getHeaderField("content-type");
+        if (!s1.equals(s2))
+            throw new RuntimeException("getContentType() differs from getHeaderField(\"content-type\")");
+    }
+}
diff --git a/test/java/net/URLConnection/ZeroContentLength.java b/test/java/net/URLConnection/ZeroContentLength.java
new file mode 100644
index 0000000..58102f5
--- /dev/null
+++ b/test/java/net/URLConnection/ZeroContentLength.java
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4507412
+ * @bug 4506998
+ * @summary Check that a 304 "Not-Modified" response from a server
+ *          doesn't cause http client to close a keep-alive
+ *          connection.
+ *          Check that a content-length of 0 results in an
+ *          empty input stream.
+ */
+import java.net.*;
+import java.io.*;
+
+public class ZeroContentLength {
+
+    /*
+     * Is debugging enabled - start with -d to enable.
+     */
+    static boolean debug = false;
+
+    static void debug(String msg) {
+        if (debug)
+            System.out.println(msg);
+    }
+
+    /*
+     * The response string and content-length that
+     * the server should return;
+     */
+    static String response;
+    static int contentLength;
+
+    static synchronized void setResponse(String rsp, int cl) {
+        response = rsp;
+        contentLength = cl;
+    }
+
+    /*
+     * Worker thread to service single connection - can service
+     * multiple http requests on same connection.
+     */
+    class Worker extends Thread {
+        Socket s;
+        int id;
+
+        Worker(Socket s, int id) {
+            this.s = s;
+            this.id = id;
+        }
+
+        public void run() {
+            try {
+
+                s.setSoTimeout(2000);
+                int max = 100;
+
+                for (;;) {
+
+                    // read entire request from client
+                    byte b[] = new byte[100];
+                    InputStream in = s.getInputStream();
+                    int n, total=0;
+
+                    try {
+                        do {
+                            n = in.read(b);
+                            if (n > 0) total += n;
+                        } while (n > 0);
+                    } catch (SocketTimeoutException e) { }
+
+                    debug("worker " + id +
+                        ": Read request from client " +
+                        "(" + total + " bytes).");
+
+                    if (total == 0) {
+                        debug("worker: " + id + ": Shutdown");
+                        return;
+                    }
+
+                    // response to client
+                    PrintStream out = new PrintStream(
+                                        new BufferedOutputStream(
+                                                s.getOutputStream() ));
+
+                    out.print("HTTP/1.1 " + response + "\r\n");
+                    if (contentLength >= 0) {
+                        out.print("Content-Length: " + contentLength +
+                                    "\r\n");
+                    }
+                    out.print("\r\n");
+                    for (int i=0; i<contentLength; i++) {
+                        out.write( (byte)'.' );
+                    }
+                    out.flush();
+
+                    debug("worked " + id +
+                        ": Sent response to client, length: " + contentLength);
+
+                    if (--max == 0) {
+                        s.close();
+                        return;
+                    }
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                try {
+                    s.close();
+                } catch (Exception e) { }
+            }
+        }
+    }
+
+    /*
+     * Server thread to accept connection and create worker threads
+     * to service each connection.
+     */
+    class Server extends Thread {
+        ServerSocket ss;
+        int connectionCount;
+        boolean shutdown = false;
+
+        Server(ServerSocket ss) {
+            this.ss = ss;
+        }
+
+        public synchronized int connectionCount() {
+            return connectionCount;
+        }
+
+        public synchronized void shutdown() {
+            shutdown = true;
+        }
+
+        public void run() {
+            try {
+                ss.setSoTimeout(2000);
+
+                for (;;) {
+                    Socket s;
+                    try {
+                        debug("server: Waiting for connections");
+                        s = ss.accept();
+                    } catch (SocketTimeoutException te) {
+                        synchronized (this) {
+                            if (shutdown) {
+                                debug("server: Shuting down.");
+                                return;
+                            }
+                        }
+                        continue;
+                    }
+
+                    int id;
+                    synchronized (this) {
+                        id = connectionCount++;
+                    }
+
+                    Worker w = new Worker(s, id);
+                    w.start();
+                    debug("server: Started worker " + id);
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                try {
+                    ss.close();
+                } catch (Exception e) { }
+            }
+        }
+    }
+
+    /*
+     * Make a single http request and return the content length
+     * received. Also do sanity check to ensure that the
+     * content-length header matches the total received on
+     * the input stream.
+     */
+    int doRequest(String uri) throws Exception {
+        URL url = new URL(uri);
+        HttpURLConnection http = (HttpURLConnection)url.openConnection();
+
+        int cl = http.getContentLength();
+
+        InputStream in = http.getInputStream();
+        byte b[] = new byte[100];
+        int total = 0;
+        int n;
+        do {
+            n = in.read(b);
+            if (n > 0) total += n;
+        } while (n > 0);
+        in.close();
+
+        if (cl >= 0 && total != cl) {
+            System.err.println("content-length header indicated: " + cl);
+            System.err.println("Actual received: " + total);
+            throw new Exception("Content-length didn't match actual received");
+        }
+
+        return total;
+    }
+
+
+    /*
+     * Send http requests to "server" and check that they all
+     * use the same network connection and that the content
+     * length corresponds to the content length expected.
+     * stream.
+     */
+    ZeroContentLength() throws Exception {
+
+        /* start the server */
+        ServerSocket ss = new ServerSocket(0);
+        Server svr = new Server(ss);
+        svr.start();
+
+        String uri = "http://localhost:" +
+                     Integer.toString(ss.getLocalPort()) +
+                     "/foo.html";
+
+        int expectedTotal = 0;
+        int actualTotal = 0;
+
+        System.out.println("**********************************");
+        System.out.println("200 OK, content-length:1024 ...");
+        setResponse("200 OK", 1024);
+        for (int i=0; i<5; i++) {
+            actualTotal += doRequest(uri);
+            expectedTotal += 1024;
+        }
+
+        System.out.println("**********************************");
+        System.out.println("200 OK, content-length:0 ...");
+        setResponse("200 OK", 0);
+        for (int i=0; i<5; i++) {
+            actualTotal += doRequest(uri);
+        }
+
+        System.out.println("**********************************");
+        System.out.println("304 Not-Modified, (no content-length) ...");
+        setResponse("304 Not-Modifed", -1);
+        for (int i=0; i<5; i++) {
+            actualTotal += doRequest(uri);
+        }
+
+        System.out.println("**********************************");
+        System.out.println("204 No-Content, (no content-length) ...");
+        setResponse("204 No-Content", -1);
+        for (int i=0; i<5; i++) {
+            actualTotal += doRequest(uri);
+        }
+
+        // shutdown server - we're done.
+        svr.shutdown();
+
+        System.out.println("**********************************");
+
+        if (actualTotal == expectedTotal) {
+            System.out.println("Passed: Actual total equal to expected total");
+        } else {
+            throw new Exception("Actual total != Expected total!!!");
+        }
+
+        int cnt = svr.connectionCount();
+        if (cnt == 1) {
+            System.out.println("Passed: Only 1 connection established");
+        } else {
+            throw new Exception("Test failed: Number of connections " +
+                "established: " + cnt + " - see log for details.");
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+
+        if (args.length > 0 && args[0].equals("-d")) {
+            debug = true;
+        }
+
+        new ZeroContentLength();
+    }
+
+}
diff --git a/test/java/net/URLConnection/contentHandler/COM/foo/content/text/plain.java b/test/java/net/URLConnection/contentHandler/COM/foo/content/text/plain.java
new file mode 100644
index 0000000..68846f7
--- /dev/null
+++ b/test/java/net/URLConnection/contentHandler/COM/foo/content/text/plain.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+/**
+ * Plain text file handler
+ *
+ * This class provides an example of a a replacement content handler for
+ * the text/plain content type.  It reads the content of the URL, and prepends
+ * an additional message at the beginning.
+ *
+ * Note that the only restrictions on the package/class names are:
+ * 1) the package must end in the major type of the content type (such as
+ *    text, image, application, etc).
+ * 2) the class name must be named with the subtype of the content type (for
+ *    content type "text/plain", this would be "plain" as in this example; for
+ *    content type "image/gif", the class name would be "gif", and the package
+ *    name must end with ".image".
+ * 3) the class must be a subclass of ContentHandler.
+ * 4) It must define the getContent function.
+ */
+package COM.foo.content.text;
+
+import java.net.ContentHandler;
+import java.io.InputStream;
+import java.net.URLConnection;
+import java.io.IOException;
+
+public class plain extends ContentHandler {
+    /**
+     * Returns one of several object types (this set may change in future
+     * versions):
+     * 1) instance of Thread:
+     *    Invoke the thread to launch an external viewer.
+     * 2) instance of InputStream:
+     *    Bring up the "Save to disk" dialog page to allow the content
+     *    to be saved to disk.
+     * 3) instance of InputStreamImageSource:
+     *    Load the image into HotJava in an image viewer page.
+     * 4) instance of String:
+     *    Go to a new page with the string as the plain text content
+     *    of that page.
+     */
+    public Object getContent(URLConnection uc) {
+        try {
+            InputStream is = uc.getInputStream();
+            StringBuffer sb = new StringBuffer();
+            int c;
+
+            sb.append("[Content of " + uc.getURL() + "]\n\n");
+            sb.append("[This opening message brought to you by your plain/text\n");
+            sb.append("content handler. To remove this content handler, delete the\n");
+            sb.append("COM.foo.content.text directory from your class path and\n");
+            sb.append("the java.content.handler.pkgs property from your HotJava\n");
+            sb.append("properties file.]\n");
+            sb.append("----------------------------------------------------------------\n\n");
+
+            // Read the characters from the source, accumulate them into the string buffer.
+            // (Not the most efficient, but simplest for this example.)
+            while ((c = is.read()) >= 0) {
+                sb.append((char)c);
+            }
+
+            // Tidy up
+            is.close();
+
+            // Return the resulting string to our client (we're case 4 above)
+            return sb.toString();
+        } catch (IOException e) {
+            // For any exception, just return an indication of what went wrong.
+            return "Problem reading document: " + uc.getURL();
+        }
+    }
+}
diff --git a/test/java/net/URLConnection/contentHandler/UserContentHandler.java b/test/java/net/URLConnection/contentHandler/UserContentHandler.java
new file mode 100644
index 0000000..0a571d4
--- /dev/null
+++ b/test/java/net/URLConnection/contentHandler/UserContentHandler.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 1999-2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4191147
+ * @summary 1.2beta4 does not load user defined content handlers
+ * @build UserContentHandler
+ * @run main UserContentHandler
+ */
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+public class UserContentHandler implements Runnable {
+
+    ServerSocket ss;
+
+    public void run() {
+        try {
+
+            Socket s = ss.accept();
+            s.setTcpNoDelay(true);
+
+            PrintStream out = new PrintStream(
+                                 new BufferedOutputStream(
+                                    s.getOutputStream() ));
+
+            out.print("HTTP/1.1 200 OK\r\n");
+            out.print("Content-Length: 11\r\n");
+            out.print("Content-Type: text/plain\r\n");
+            out.print("\r\n");
+            out.print("l;ajfdjafd\n");
+            out.flush();
+
+            // don't close the connection immediately as otherwise
+            // the http headers may not have been received and the
+            // http client will re-connect.
+            Thread.currentThread().sleep(2000);
+
+            s.close();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    UserContentHandler() throws Exception {
+
+        ss = new ServerSocket(0);
+        Thread thr = new Thread(this);
+        thr.start();
+
+        try {
+            Object o = new COM.foo.content.text.plain();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        Properties props = System.getProperties();
+        props.put("java.content.handler.pkgs", "COM.foo.content");
+        System.setProperties(props);
+
+        URL u = new URL("http://localhost:" + ss.getLocalPort() +
+                        "/anything.txt");
+        if (!(u.openConnection().getContent() instanceof String)) {
+            throw new RuntimeException("Load user defined content handler failed.");
+        } else {
+            System.err.println("Load user defined content handler succeed!");
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+        new UserContentHandler();
+    }
+}
diff --git a/test/java/net/URLConnection/jars/test.jar b/test/java/net/URLConnection/jars/test.jar
new file mode 100644
index 0000000..feeadf5
--- /dev/null
+++ b/test/java/net/URLConnection/jars/test.jar
Binary files differ
diff --git a/test/java/net/URLConnection/olympus.jpg b/test/java/net/URLConnection/olympus.jpg
new file mode 100644
index 0000000..b644867
--- /dev/null
+++ b/test/java/net/URLConnection/olympus.jpg
Binary files differ
diff --git a/test/java/net/URLConnection/xml/not-xml1 b/test/java/net/URLConnection/xml/not-xml1
new file mode 100644
index 0000000..4c229b3
--- /dev/null
+++ b/test/java/net/URLConnection/xml/not-xml1
@@ -0,0 +1,7 @@
+<?XML VERSION="1.0" ENCODING="windows-1525"?>
+<doc/>
+
+<!--
+    Microsoft has been shipping "XML" that is noncompliant.
+    This must be rejected by any conforming XML processor.
+-->
diff --git a/test/java/net/URLConnection/xml/not-xml2 b/test/java/net/URLConnection/xml/not-xml2
new file mode 100644
index 0000000..631bb50
--- /dev/null
+++ b/test/java/net/URLConnection/xml/not-xml2
@@ -0,0 +1,6 @@
+<?xMl version="1.0"?>
+<doc/>
+
+<!--
+    XML declarations MUST be in lowercase.
+-->
diff --git a/test/java/net/URLConnection/xml/xml1 b/test/java/net/URLConnection/xml/xml1
new file mode 100644
index 0000000..ad62507
--- /dev/null
+++ b/test/java/net/URLConnection/xml/xml1
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<doc/>
+
+<!--
+    Most legal XML documents encoded with supersets of US-ASCII
+    will start like this document.  Includes ISO-8859-1, EUC-JP,
+    Shift_JIS, UTF-8, ISO-2022-JP, and other encodings.
+    
+    That is:  they're flagged up front with an XML declaration.
+-->
diff --git a/test/java/net/URLConnection/xml/xml2.xml b/test/java/net/URLConnection/xml/xml2.xml
new file mode 100644
index 0000000..0b15445
--- /dev/null
+++ b/test/java/net/URLConnection/xml/xml2.xml
@@ -0,0 +1,6 @@
+<!--
+    XML declarations are optional, sometimes file types
+    are used to flag things.
+-->
+
+<doc/>
diff --git a/test/java/net/URLConnection/xml/xml3 b/test/java/net/URLConnection/xml/xml3
new file mode 100644
index 0000000..12d5051
--- /dev/null
+++ b/test/java/net/URLConnection/xml/xml3
Binary files differ
diff --git a/test/java/net/URLConnection/xml/xml4 b/test/java/net/URLConnection/xml/xml4
new file mode 100644
index 0000000..94c3076
--- /dev/null
+++ b/test/java/net/URLConnection/xml/xml4
Binary files differ