test/jdk/java/net/ResponseCache/Test2.java
changeset 54314 46cf212cdcca
parent 47216 71c04702a3d5
child 55309 8081b181bba8
equal deleted inserted replaced
54313:440cbcf3b268 54314:46cf212cdcca
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 8042622
    26  * @bug 8042622
       
    27  * @library /test/lib
    27  * @summary Check for CRL results in IllegalArgumentException "white space not allowed"
    28  * @summary Check for CRL results in IllegalArgumentException "white space not allowed"
    28  * @modules jdk.httpserver
    29  * @modules jdk.httpserver
    29  * @run main/othervm Test2
    30  * @run main/othervm Test2
    30  */
    31  */
    31 
    32 
    36 import java.io.*;
    37 import java.io.*;
    37 import java.net.*;
    38 import java.net.*;
    38 import java.security.*;
    39 import java.security.*;
    39 import javax.security.auth.callback.*;
    40 import javax.security.auth.callback.*;
    40 import javax.net.ssl.*;
    41 import javax.net.ssl.*;
       
    42 import jdk.test.lib.net.URIBuilder;
    41 
    43 
    42 public class Test2 {
    44 public class Test2 {
    43 
    45 
    44     static volatile boolean failed = false;
    46     static volatile boolean failed = false;
    45 
    47 
    61         }
    63         }
    62     }
    64     }
    63 
    65 
    64     static int port;
    66     static int port;
    65 
    67 
    66     static String urlstring, redirstring;
    68     static URL url, redir;
    67 
    69 
    68     public static void main (String[] args) throws Exception {
    70     public static void main (String[] args) throws Exception {
    69         Handler handler = new Handler();
    71         Handler handler = new Handler();
    70         InetSocketAddress addr = new InetSocketAddress (0);
    72         InetSocketAddress addr = new InetSocketAddress (0);
    71         HttpServer server = HttpServer.create (addr, 0);
    73         HttpServer server = HttpServer.create (addr, 0);
    76 
    78 
    77         ExecutorService executor = Executors.newCachedThreadPool();
    79         ExecutorService executor = Executors.newCachedThreadPool();
    78         server.setExecutor (executor);
    80         server.setExecutor (executor);
    79         server.start ();
    81         server.start ();
    80 
    82 
    81         urlstring = "http://127.0.0.1:" + Integer.toString(port)+"/test/foo";
    83         url = URIBuilder.newBuilder()
    82         redirstring = urlstring + "/redirect/bar";
    84             .scheme("http")
       
    85             .loopback()
       
    86             .port(port)
       
    87             .path("/test/foo")
       
    88             .toURLUnchecked();
       
    89         System.out.println("URL: " + url);
       
    90         redir = URIBuilder.newBuilder()
       
    91             .scheme("http")
       
    92             .loopback()
       
    93             .port(port)
       
    94             .path("/test/foo/redirect/bar")
       
    95             .toURLUnchecked();
       
    96         System.out.println("Redir URL: " + redir);
    83 
    97 
    84         URL url = new URL (urlstring);
       
    85         HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
    98         HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
    86         urlc.addRequestProperty("X-Foo", "bar");
    99         urlc.addRequestProperty("X-Foo", "bar");
    87         urlc.setInstanceFollowRedirects(true);
   100         urlc.setInstanceFollowRedirects(true);
    88         System.out.println(urlc.getResponseCode());
   101         System.out.println(urlc.getResponseCode());
    89         InputStream i = urlc.getInputStream();
   102         InputStream i = urlc.getInputStream();
   112             InputStream is = t.getRequestBody();
   125             InputStream is = t.getRequestBody();
   113             Headers map = t.getRequestHeaders();
   126             Headers map = t.getRequestHeaders();
   114             Headers rmap = t.getResponseHeaders();
   127             Headers rmap = t.getResponseHeaders();
   115             invocation ++;
   128             invocation ++;
   116             if (invocation == 1) {
   129             if (invocation == 1) {
   117                 rmap.add("Location", redirstring);
   130                 rmap.add("Location", redir.toString());
   118                 while (is.read () != -1) ;
   131                 while (is.read () != -1) ;
   119                 is.close();
   132                 is.close();
   120                 System.out.println ("sending response");
   133                 System.out.println ("sending response");
   121                 t.sendResponseHeaders (301, 0);
   134                 t.sendResponseHeaders (301, 0);
   122             } else {
   135             } else {