test/jdk/java/net/ResponseCache/Test2.java
changeset 55309 8081b181bba8
parent 54314 46cf212cdcca
equal deleted inserted replaced
55308:871bc449ce06 55309:8081b181bba8
     1 /*
     1 /*
     2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    26  * @bug 8042622
    26  * @bug 8042622
    27  * @library /test/lib
    27  * @library /test/lib
    28  * @summary Check for CRL results in IllegalArgumentException "white space not allowed"
    28  * @summary Check for CRL results in IllegalArgumentException "white space not allowed"
    29  * @modules jdk.httpserver
    29  * @modules jdk.httpserver
    30  * @run main/othervm Test2
    30  * @run main/othervm Test2
       
    31  * @run main/othervm -Djava.net.preferIPv6Addresses=true Test2
    31  */
    32  */
    32 
    33 
    33 import com.sun.net.httpserver.*;
    34 import com.sun.net.httpserver.*;
    34 
    35 
    35 import java.util.*;
    36 import java.util.*;
    67 
    68 
    68     static URL url, redir;
    69     static URL url, redir;
    69 
    70 
    70     public static void main (String[] args) throws Exception {
    71     public static void main (String[] args) throws Exception {
    71         Handler handler = new Handler();
    72         Handler handler = new Handler();
    72         InetSocketAddress addr = new InetSocketAddress (0);
    73         InetAddress loopback = InetAddress.getLoopbackAddress();
       
    74         InetSocketAddress addr = new InetSocketAddress(loopback, 0);
    73         HttpServer server = HttpServer.create (addr, 0);
    75         HttpServer server = HttpServer.create (addr, 0);
    74         port = server.getAddress().getPort();
    76         port = server.getAddress().getPort();
    75         HttpContext ctx = server.createContext ("/test", handler);
    77         HttpContext ctx = server.createContext ("/test", handler);
    76         System.out.println ("Server: " + server.getAddress().getPort());
    78         System.out.println ("Server: " + server.getAddress());
    77         ResponseCache.setDefault(new Cache());
    79         ResponseCache.setDefault(new Cache());
    78 
    80 
    79         ExecutorService executor = Executors.newCachedThreadPool();
    81         ExecutorService executor = Executors.newCachedThreadPool();
    80         server.setExecutor (executor);
    82         server.setExecutor (executor);
    81         server.start ();
    83         server.start ();
    93             .port(port)
    95             .port(port)
    94             .path("/test/foo/redirect/bar")
    96             .path("/test/foo/redirect/bar")
    95             .toURLUnchecked();
    97             .toURLUnchecked();
    96         System.out.println("Redir URL: " + redir);
    98         System.out.println("Redir URL: " + redir);
    97 
    99 
    98         HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
   100         HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
    99         urlc.addRequestProperty("X-Foo", "bar");
   101         urlc.addRequestProperty("X-Foo", "bar");
   100         urlc.setInstanceFollowRedirects(true);
   102         urlc.setInstanceFollowRedirects(true);
   101         System.out.println(urlc.getResponseCode());
   103         System.out.println(urlc.getResponseCode());
   102         InputStream i = urlc.getInputStream();
   104         InputStream i = urlc.getInputStream();
   103         int count=0;
   105         int count=0;