test/jdk/java/net/httpclient/CustomResponseSubscriber.java
branchhttp-client-branch
changeset 56265 ec34ae013fbe
parent 56167 96fa4f49a9ff
child 56410 1b37529eaf3a
equal deleted inserted replaced
56264:c012b93297b0 56265:ec34ae013fbe
    33  * @run testng/othervm CustomResponseSubscriber
    33  * @run testng/othervm CustomResponseSubscriber
    34  */
    34  */
    35 
    35 
    36 import java.io.IOException;
    36 import java.io.IOException;
    37 import java.io.InputStream;
    37 import java.io.InputStream;
       
    38 import java.net.InetAddress;
    38 import java.net.InetSocketAddress;
    39 import java.net.InetSocketAddress;
    39 import java.net.URI;
    40 import java.net.URI;
    40 import java.nio.ByteBuffer;
    41 import java.nio.ByteBuffer;
    41 import java.util.List;
    42 import java.util.List;
    42 import java.util.concurrent.CompletionStage;
    43 import java.util.concurrent.CompletionStage;
   176         public CompletionStage<String> getBody() {
   177         public CompletionStage<String> getBody() {
   177             return ofString.getBody();
   178             return ofString.getBody();
   178         }
   179         }
   179     }
   180     }
   180 
   181 
       
   182     static String serverAuthority(HttpServer server) {
       
   183         return InetAddress.getLoopbackAddress().getHostName() + ":"
       
   184                 + server.getAddress().getPort();
       
   185     }
   181 
   186 
   182     @BeforeTest
   187     @BeforeTest
   183     public void setup() throws Exception {
   188     public void setup() throws Exception {
   184         sslContext = new SimpleSSLContext().get();
   189         sslContext = new SimpleSSLContext().get();
   185         if (sslContext == null)
   190         if (sslContext == null)
   186             throw new AssertionError("Unexpected null sslContext");
   191             throw new AssertionError("Unexpected null sslContext");
   187 
   192 
   188         // HTTP/1.1
   193         // HTTP/1.1
   189         HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
   194         HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
   190         HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();
   195         HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();
   191         InetSocketAddress sa = new InetSocketAddress(0);
   196         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
   192         httpTestServer = HttpServer.create(sa, 0);
   197         httpTestServer = HttpServer.create(sa, 0);
   193         httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler);
   198         httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler);
   194         httpTestServer.createContext("/http1/chunk", h1_chunkHandler);
   199         httpTestServer.createContext("/http1/chunk", h1_chunkHandler);
   195         httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/fixed";
   200         httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed";
   196         httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/chunk";
   201         httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk";
   197 
   202 
   198         httpsTestServer = HttpsServer.create(sa, 0);
   203         httpsTestServer = HttpsServer.create(sa, 0);
   199         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
   204         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
   200         httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
   205         httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
   201         httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
   206         httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
   202         httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/fixed";
   207         httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
   203         httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/chunk";
   208         httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk";
   204 
   209 
   205         // HTTP/2
   210         // HTTP/2
   206         Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler();
   211         Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler();
   207         Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler();
   212         Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler();
   208 
   213 
   209         http2TestServer = new Http2TestServer("127.0.0.1", false, 0);
   214         http2TestServer = new Http2TestServer("localhost", false, 0);
   210         http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed");
   215         http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed");
   211         http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk");
   216         http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk");
   212         int port = http2TestServer.getAddress().getPort();
   217         http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed";
   213         http2URI_fixed = "http://127.0.0.1:" + port + "/http2/fixed";
   218         http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk";
   214         http2URI_chunk = "http://127.0.0.1:" + port + "/http2/chunk";
   219 
   215 
   220         https2TestServer = new Http2TestServer("localhost", true, 0);
   216         https2TestServer = new Http2TestServer("127.0.0.1", true, 0);
       
   217         https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed");
   221         https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed");
   218         https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk");
   222         https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk");
   219         port = https2TestServer.getAddress().getPort();
   223         https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed";
   220         https2URI_fixed = "https://127.0.0.1:" + port + "/https2/fixed";
   224         https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk";
   221         https2URI_chunk = "https://127.0.0.1:" + port + "/https2/chunk";
       
   222 
   225 
   223         httpTestServer.start();
   226         httpTestServer.start();
   224         httpsTestServer.start();
   227         httpsTestServer.start();
   225         http2TestServer.start();
   228         http2TestServer.start();
   226         https2TestServer.start();
   229         https2TestServer.start();