< prev index next >

test/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java

Print this page

        

@@ -29,22 +29,24 @@
 /*
  * @test
  * @bug 6216082
  * @summary  Redirect problem with HttpsURLConnection using a proxy
  * @modules java.base/sun.net.www
- * @library ..
+ * @library .. /lib/testlibrary
  * @build HttpCallback TestHttpsServer ClosedChannelList
- *        HttpTransaction TunnelProxy
+ *        HttpTransaction TunnelProxy jdk.testlibrary.NetworkConfiguration
  * @key intermittent
  * @run main/othervm B6216082
  */
 
 import java.io.*;
 import java.net.*;
 import javax.net.ssl.*;
 import java.util.*;
 
+import jdk.testlibrary.NetworkConfiguration;
+
 public class B6216082 {
     static SimpleHttpTransaction httpTrans;
     static TestHttpsServer server;
     static TunnelProxy proxy;
 

@@ -116,25 +118,21 @@
         HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
         return true;
     }
 
     public static InetAddress getNonLoAddress() throws Exception {
-        NetworkInterface loNIC = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost"));
-        Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
-        while (nics.hasMoreElements()) {
-            NetworkInterface nic = nics.nextElement();
-            if (!nic.getName().equalsIgnoreCase(loNIC.getName())) {
-                Enumeration<InetAddress> addrs = nic.getInetAddresses();
-                while (addrs.hasMoreElements()) {
-                    InetAddress addr = addrs.nextElement();
-                    if (!addr.isLoopbackAddress())
-                        return addr;
-                }
-            }
-        }
+        InetAddress lh = InetAddress.getByName("localhost");
+        NetworkInterface loNIC = NetworkInterface.getByInetAddress(lh);
+
+        NetworkConfiguration nc = NetworkConfiguration.probe();
+        Optional<InetAddress> oaddr = nc.interfaces()
+                .filter(nif -> !nif.getName().equalsIgnoreCase(loNIC.getName()))
+                .flatMap(nif -> nc.addresses(nif))
+                .filter(a -> !a.isLoopbackAddress())
+                .findFirst();
 
-        return null;
+        return oaddr.orElseGet(() -> null);
     }
 
     public static void startHttpServer() throws IOException {
         // Both the https server and the proxy let the
         // system pick up an ephemeral port.
< prev index next >