test/sun/net/www/protocol/https/NewImpl/ComHTTPSConnection.java

Print this page

        

@@ -186,10 +186,21 @@
              sslSocket.close();
              serverReady = false;
         }
     }
 
+    private static class ComSunHTTPSHandlerFactory implements URLStreamHandlerFactory {
+        private static String SUPPORTED_PROTOCOL = "https";
+
+        public URLStreamHandler createURLStreamHandler(String protocol) {
+            if (!protocol.equalsIgnoreCase(SUPPORTED_PROTOCOL))
+                return null;
+
+            return new com.sun.net.ssl.internal.www.protocol.https.Handler();
+        }
+    }
+
     /*
      * Define the client side of the test.
      *
      * If the server prematurely exits, serverReady will be set to true
      * to avoid infinite hangs.

@@ -203,12 +214,11 @@
         }
 
         HostnameVerifier reservedHV =
             HttpsURLConnection.getDefaultHostnameVerifier();
         try {
-            System.setProperty("java.protocol.handler.pkgs",
-                "com.sun.net.ssl.internal.www.protocol");
+            URL.addURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());
             HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
 
             URL url = new URL("https://" + "localhost:" + serverPort +
                                     "/etc/hosts");
             URLConnection urlc = url.openConnection();