test/jdk/java/net/httpclient/AbstractNoBody.java
branchhttp-client-branch
changeset 56265 ec34ae013fbe
parent 56089 42208b2f224e
child 56369 24a8fafec3ff
equal deleted inserted replaced
56264:c012b93297b0 56265:ec34ae013fbe
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import java.io.IOException;
    24 import java.io.IOException;
    25 import java.io.InputStream;
    25 import java.io.InputStream;
       
    26 import java.net.InetAddress;
    26 import java.net.InetSocketAddress;
    27 import java.net.InetSocketAddress;
    27 import java.util.concurrent.Executor;
    28 import java.util.concurrent.Executor;
    28 import java.util.concurrent.ExecutorService;
    29 import java.util.concurrent.ExecutorService;
    29 import java.util.concurrent.Executors;
    30 import java.util.concurrent.Executors;
    30 import com.sun.net.httpserver.HttpExchange;
    31 import com.sun.net.httpserver.HttpExchange;
    89                 .executor(executor)
    90                 .executor(executor)
    90                 .sslContext(sslContext)
    91                 .sslContext(sslContext)
    91                 .build();
    92                 .build();
    92     }
    93     }
    93 
    94 
       
    95     static String serverAuthority(HttpServer server) {
       
    96         return InetAddress.getLoopbackAddress().getHostName() + ":"
       
    97                 + server.getAddress().getPort();
       
    98     }
       
    99 
    94     @BeforeTest
   100     @BeforeTest
    95     public void setup() throws Exception {
   101     public void setup() throws Exception {
    96         printStamp(START, "setup");
   102         printStamp(START, "setup");
    97         sslContext = new SimpleSSLContext().get();
   103         sslContext = new SimpleSSLContext().get();
    98         if (sslContext == null)
   104         if (sslContext == null)
    99             throw new AssertionError("Unexpected null sslContext");
   105             throw new AssertionError("Unexpected null sslContext");
   100 
   106 
   101         // HTTP/1.1
   107         // HTTP/1.1
   102         HttpHandler h1_fixedLengthNoBodyHandler = new HTTP1_FixedLengthNoBodyHandler();
   108         HttpHandler h1_fixedLengthNoBodyHandler = new HTTP1_FixedLengthNoBodyHandler();
   103         HttpHandler h1_chunkNoBodyHandler = new HTTP1_ChunkedNoBodyHandler();
   109         HttpHandler h1_chunkNoBodyHandler = new HTTP1_ChunkedNoBodyHandler();
   104         InetSocketAddress sa = new InetSocketAddress(0);
   110         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
   105         httpTestServer = HttpServer.create(sa, 0);
   111         httpTestServer = HttpServer.create(sa, 0);
   106         httpTestServer.setExecutor(serverExecutor);
   112         httpTestServer.setExecutor(serverExecutor);
   107         httpTestServer.createContext("/http1/noBodyFixed", h1_fixedLengthNoBodyHandler);
   113         httpTestServer.createContext("/http1/noBodyFixed", h1_fixedLengthNoBodyHandler);
   108         httpTestServer.createContext("/http1/noBodyChunk", h1_chunkNoBodyHandler);
   114         httpTestServer.createContext("/http1/noBodyChunk", h1_chunkNoBodyHandler);
   109         httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/noBodyFixed";
   115         httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/noBodyFixed";
   110         httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/noBodyChunk";
   116         httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/noBodyChunk";
   111 
   117 
   112         httpsTestServer = HttpsServer.create(sa, 0);
   118         httpsTestServer = HttpsServer.create(sa, 0);
   113         httpsTestServer.setExecutor(serverExecutor);
   119         httpsTestServer.setExecutor(serverExecutor);
   114         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
   120         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
   115         httpsTestServer.createContext("/https1/noBodyFixed", h1_fixedLengthNoBodyHandler);
   121         httpsTestServer.createContext("/https1/noBodyFixed", h1_fixedLengthNoBodyHandler);
   116         httpsTestServer.createContext("/https1/noBodyChunk", h1_chunkNoBodyHandler);
   122         httpsTestServer.createContext("/https1/noBodyChunk", h1_chunkNoBodyHandler);
   117         httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/noBodyFixed";
   123         httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/noBodyFixed";
   118         httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/noBodyChunk";
   124         httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/noBodyChunk";
   119 
   125 
   120         // HTTP/2
   126         // HTTP/2
   121         Http2Handler h2_fixedLengthNoBodyHandler = new HTTP2_FixedLengthNoBodyHandler();
   127         Http2Handler h2_fixedLengthNoBodyHandler = new HTTP2_FixedLengthNoBodyHandler();
   122         Http2Handler h2_chunkedNoBodyHandler = new HTTP2_ChunkedNoBodyHandler();
   128         Http2Handler h2_chunkedNoBodyHandler = new HTTP2_ChunkedNoBodyHandler();
   123 
   129 
   124         http2TestServer = new Http2TestServer("127.0.0.1", false, 0, serverExecutor, null);
   130         http2TestServer = new Http2TestServer("localhost", false, 0, serverExecutor, null);
   125         http2TestServer.addHandler(h2_fixedLengthNoBodyHandler, "/http2/noBodyFixed");
   131         http2TestServer.addHandler(h2_fixedLengthNoBodyHandler, "/http2/noBodyFixed");
   126         http2TestServer.addHandler(h2_chunkedNoBodyHandler, "/http2/noBodyChunk");
   132         http2TestServer.addHandler(h2_chunkedNoBodyHandler, "/http2/noBodyChunk");
   127         int port = http2TestServer.getAddress().getPort();
   133         http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/noBodyFixed";
   128         http2URI_fixed = "http://127.0.0.1:" + port + "/http2/noBodyFixed";
   134         http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/noBodyChunk";
   129         http2URI_chunk = "http://127.0.0.1:" + port + "/http2/noBodyChunk";
   135 
   130 
   136         https2TestServer = new Http2TestServer("localhost", true, 0, serverExecutor, sslContext);
   131         https2TestServer = new Http2TestServer("127.0.0.1", true, 0, serverExecutor, sslContext);
       
   132         https2TestServer.addHandler(h2_fixedLengthNoBodyHandler, "/https2/noBodyFixed");
   137         https2TestServer.addHandler(h2_fixedLengthNoBodyHandler, "/https2/noBodyFixed");
   133         https2TestServer.addHandler(h2_chunkedNoBodyHandler, "/https2/noBodyChunk");
   138         https2TestServer.addHandler(h2_chunkedNoBodyHandler, "/https2/noBodyChunk");
   134         port = https2TestServer.getAddress().getPort();
   139         https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/noBodyFixed";
   135         https2URI_fixed = "https://127.0.0.1:" + port + "/https2/noBodyFixed";
   140         https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/noBodyChunk";
   136         https2URI_chunk = "https://127.0.0.1:" + port + "/https2/noBodyChunk";
       
   137 
   141 
   138         httpTestServer.start();
   142         httpTestServer.start();
   139         httpsTestServer.start();
   143         httpsTestServer.start();
   140         http2TestServer.start();
   144         http2TestServer.start();
   141         https2TestServer.start();
   145         https2TestServer.start();