test/jdk/java/net/HttpCookie/IllegalCookieNameTest.java
changeset 55522 b2cbe2f674f0
parent 47216 71c04702a3d5
--- a/test/jdk/java/net/HttpCookie/IllegalCookieNameTest.java	Fri Jun 28 17:10:22 2019 +0300
+++ b/test/jdk/java/net/HttpCookie/IllegalCookieNameTest.java	Fri Jun 28 15:58:10 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, Oracle and/or its affiliates. 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
@@ -23,25 +23,35 @@
 
 /* @test
  * @bug 7183292
+ * @library /test/lib
  * @modules jdk.httpserver
+ * @run main IllegalCookieNameTest
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true IllegalCookieNameTest
  */
 import java.net.*;
 import java.util.*;
 import java.io.*;
 import com.sun.net.httpserver.*;
+import jdk.test.lib.net.URIBuilder;
 
 public class IllegalCookieNameTest {
-    public static void main(String[] args) throws IOException {
+    public static void main(String[] args) throws Exception {
         HttpServer s = null;
         try {
-            InetSocketAddress addr = new InetSocketAddress(0);
+            InetAddress loopback = InetAddress.getLoopbackAddress();
+            InetSocketAddress addr = new InetSocketAddress(loopback, 0);
             s = HttpServer.create(addr, 10);
             s.createContext("/", new HHandler());
             s.start();
-            String u = "http://127.0.0.1:" + s.getAddress().getPort() + "/";
+            String u = URIBuilder.newBuilder()
+                .scheme("http")
+                .loopback()
+                .port(s.getAddress().getPort())
+                .path("/")
+                .build().toString();
             CookieHandler.setDefault(new TestCookieHandler());
             URL url = new URL(u);
-            HttpURLConnection c = (HttpURLConnection) url.openConnection();
+            HttpURLConnection c = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
             c.getHeaderFields();
             System.out.println ("OK");
         } finally {