jdk/test/javax/net/ssl/HttpsURLConnection/Equals.java
changeset 39493 837860f3f432
parent 38327 77143af4d719
equal deleted inserted replaced
39492:697da62a538a 39493:837860f3f432
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
       
    26  * @bug 8055299
    26  * @library /lib/testlibrary
    27  * @library /lib/testlibrary
    27  * @modules jdk.httpserver
    28  * @modules jdk.httpserver
    28  * @build jdk.testlibrary.SimpleSSLContext
    29  * @build jdk.testlibrary.SimpleSSLContext
    29  * @run main Equals
    30  * @run main/othervm -Djavax.net.debug=ssl,handshake,record Equals
    30  * @bug 8055299
       
    31  */
    31  */
    32 
       
    33 import com.sun.net.httpserver.*;
    32 import com.sun.net.httpserver.*;
    34 
       
    35 import java.net.*;
    33 import java.net.*;
    36 import java.util.*;
       
    37 import java.io.*;
    34 import java.io.*;
    38 import javax.net.ssl.*;
    35 import javax.net.ssl.*;
    39 import java.util.concurrent.*;
    36 import java.util.concurrent.*;
    40 import jdk.testlibrary.SimpleSSLContext;
    37 import jdk.testlibrary.SimpleSSLContext;
    41 
    38 
    42 public class Equals {
    39 public class Equals {
    43 
    40 
    44     static SSLContext ctx;
    41     static SSLContext ctx;
    45 
    42 
    46     public static void main (String[] args) throws Exception {
    43     public static void main(String[] args) throws Exception {
    47         HttpsServer s2 = null;
    44         HttpsServer s2 = null;
    48         ExecutorService executor=null;
    45         ExecutorService executor = null;
    49         try {
    46         try {
    50             InetSocketAddress addr = new InetSocketAddress (0);
    47             InetSocketAddress addr = new InetSocketAddress(0);
    51             s2 = HttpsServer.create (addr, 0);
    48             s2 = HttpsServer.create(addr, 0);
    52             HttpHandler h = new Handler ();
    49             HttpHandler h = new Handler();
    53             HttpContext c2 = s2.createContext ("/test1", h);
    50             HttpContext c2 = s2.createContext("/test1", h);
    54             executor = Executors.newCachedThreadPool();
    51             executor = Executors.newCachedThreadPool();
    55             s2.setExecutor (executor);
    52             s2.setExecutor(executor);
    56             ctx = new SimpleSSLContext().get();
    53             ctx = new SimpleSSLContext().get();
    57             s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
    54             s2.setHttpsConfigurator(new HttpsConfigurator(ctx));
    58             s2.start();
    55             s2.start();
    59 
       
    60             int httpsport = s2.getAddress().getPort();
    56             int httpsport = s2.getAddress().getPort();
       
    57             System.out.printf("%nServer address: %s%n", s2.getAddress());
    61             test(httpsport);
    58             test(httpsport);
    62             System.out.println ("OK");
    59             System.out.println("OK");
    63         } finally {
    60         } finally {
    64             if (s2 != null)
    61             if (s2 != null) {
    65                 s2.stop(2);
    62                 s2.stop(2);
    66             if (executor != null)
    63             }
    67                 executor.shutdown ();
    64             if (executor != null) {
       
    65                 executor.shutdown();
       
    66             }
    68         }
    67         }
    69     }
    68     }
    70 
    69 
    71     static class Handler implements HttpHandler {
    70     static class Handler implements HttpHandler {
       
    71 
    72         int invocation = 1;
    72         int invocation = 1;
    73         public void handle (HttpExchange t)
    73 
    74             throws IOException
    74         public void handle(HttpExchange t)
    75         {
    75                 throws IOException {
    76             InputStream is = t.getRequestBody();
    76             InputStream is = t.getRequestBody();
    77             while (is.read () != -1) {
    77             while (is.read() != -1) {
    78             }
    78             }
    79             is.close();
    79             is.close();
    80             t.sendResponseHeaders (200, 0);
    80             t.sendResponseHeaders(200, 0);
    81             t.close();
    81             t.close();
    82         }
    82         }
    83     }
    83     }
    84 
    84 
    85     static void test (int port) throws Exception {
    85     static void test(int port) throws Exception {
    86         URL url = new URL ("https://localhost:"+port+"/test1/");
    86         System.out.printf("%nClient using port number: %s%n", port);
       
    87         String spec = String.format("https://localhost:%s/test1/", port);
       
    88         URL url = new URL(spec);
    87         HttpsURLConnection urlcs = (HttpsURLConnection) url.openConnection();
    89         HttpsURLConnection urlcs = (HttpsURLConnection) url.openConnection();
    88         urlcs.setHostnameVerifier (new HostnameVerifier () {
    90         urlcs.setHostnameVerifier(new HostnameVerifier() {
    89             public boolean verify (String s, SSLSession s1) {
    91             public boolean verify(String s, SSLSession s1) {
    90                 return true;
    92                 return true;
    91             }
    93             }
    92         });
    94         });
    93         urlcs.setSSLSocketFactory (ctx.getSocketFactory());
    95         urlcs.setSSLSocketFactory(ctx.getSocketFactory());
    94 
    96 
    95         InputStream is = urlcs.getInputStream();
    97         InputStream is = urlcs.getInputStream();
    96         while (is.read() != -1) {
    98         while (is.read() != -1) {
    97         }
    99         }
    98         is.close();
   100         is.close();