< prev index next >

test/jdk/java/net/httpclient/HttpSlowServerTest.java

Print this page

  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 import com.sun.net.httpserver.HttpServer;
 24 import com.sun.net.httpserver.HttpsConfigurator;
 25 import com.sun.net.httpserver.HttpsServer;

 26 import jdk.test.lib.net.SimpleSSLContext;
 27 
 28 import javax.net.ssl.SSLContext;
 29 import java.io.IOException;
 30 import java.io.InputStream;
 31 import java.io.OutputStream;
 32 import java.net.InetAddress;
 33 import java.net.InetSocketAddress;
 34 import java.net.Proxy;
 35 import java.net.ProxySelector;
 36 import java.net.SocketAddress;
 37 import java.net.URI;
 38 import java.net.http.HttpClient;
 39 import java.net.http.HttpRequest;
 40 import java.net.http.HttpResponse;
 41 import java.nio.charset.StandardCharsets;
 42 import java.time.Duration;
 43 import java.util.List;
 44 import java.util.Set;
 45 import java.util.concurrent.CompletableFuture;
 46 import java.util.concurrent.CopyOnWriteArrayList;
 47 import java.util.concurrent.CopyOnWriteArraySet;
 48 import java.util.concurrent.ExecutorService;
 49 import java.util.concurrent.LinkedBlockingQueue;
 50 import java.util.concurrent.ThreadPoolExecutor;
 51 import java.util.concurrent.TimeUnit;
 52 import java.util.concurrent.atomic.AtomicLong;
 53 import jdk.httpclient.test.lib.common.HttpServerAdapters;
 54 import jdk.httpclient.test.lib.http2.Http2TestServer;
 55 import static java.net.http.HttpClient.Version.HTTP_1_1;
 56 import static java.net.http.HttpClient.Version.HTTP_2;
 57 
 58 /**
 59  * @test
 60  * @summary This test verifies that the HttpClient works correctly when connected to a
 61  *          slow server.
 62  * @library /test/lib /test/jdk/java/net/httpclient/lib
 63  * @build jdk.httpclient.test.lib.common.HttpServerAdapters jdk.test.lib.net.SimpleSSLContext
 64  *        DigestEchoServer HttpSlowServerTest

 65  * @run main/othervm -Dtest.requiresHost=true
 66  *                   -Djdk.httpclient.HttpClient.log=headers
 67  *                   -Djdk.internal.httpclient.debug=false
 68  *                   HttpSlowServerTest
 69  *
 70  */
 71 public class HttpSlowServerTest implements HttpServerAdapters {
 72     static final List<String> data = List.of(
 73             "Lorem ipsum",
 74             "dolor sit amet",
 75             "consectetur adipiscing elit, sed do eiusmod tempor",
 76             "quis nostrud exercitation ullamco",
 77             "laboris nisi",
 78             "ut",
 79             "aliquip ex ea commodo consequat.",
 80             "Duis aute irure dolor in reprehenderit in voluptate velit esse",
 81             "cillum dolore eu fugiat nulla pariatur.",
 82             "Excepteur sint occaecat cupidatat non proident."
 83     );
 84 

121                 .sslContext(context)
122                 .executor(clientexec)
123                 .proxy(ps);
124         return builder.build();
125     }
126 
127     public void setUp() throws Exception {
128         try {
129             InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
130 
131             // HTTP/1.1
132             http1Server = HttpTestServer.create(HTTP_1_1, null, executor);
133             http1Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/http1/");
134             http1Server.start();
135             http1URI = new URI("http://" + http1Server.serverAuthority() + "/HttpSlowServerTest/http1/");
136 
137 
138             // HTTPS/1.1
139             HttpsServer sserver1 = HttpsServer.create(sa, 100);
140             sserver1.setExecutor(executor);
141             sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
142             https1Server = HttpTestServer.of(sserver1);
143             https1Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/https1/");
144             https1Server.start();
145             https1URI = new URI("https://" + https1Server.serverAuthority() + "/HttpSlowServerTest/https1/");
146 
147             // HTTP/2.0
148             http2Server = HttpTestServer.create(HTTP_2);
149             http2Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/http2/");
150             http2Server.start();
151             http2URI = new URI("http://" + http2Server.serverAuthority() + "/HttpSlowServerTest/http2/");
152 
153             // HTTPS/2.0
154             https2Server = HttpTestServer.create(HTTP_2, SSLContext.getDefault());
155             https2Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/https2/");
156             https2Server.start();
157             https2URI = new URI("https://" + https2Server.serverAuthority() + "/HttpSlowServerTest/https2/");
158 
159             proxy = DigestEchoServer.createHttpsProxyTunnel(
160                     DigestEchoServer.HttpAuthSchemeType.NONE);
161             proxyAddress = proxy.getProxyAddress();

  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */


 23 import com.sun.net.httpserver.HttpsServer;
 24 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 25 import jdk.test.lib.net.SimpleSSLContext;
 26 
 27 import javax.net.ssl.SSLContext;
 28 import java.io.IOException;
 29 import java.io.InputStream;
 30 import java.io.OutputStream;
 31 import java.net.InetAddress;
 32 import java.net.InetSocketAddress;
 33 import java.net.Proxy;
 34 import java.net.ProxySelector;
 35 import java.net.SocketAddress;
 36 import java.net.URI;
 37 import java.net.http.HttpClient;
 38 import java.net.http.HttpRequest;
 39 import java.net.http.HttpResponse;
 40 import java.nio.charset.StandardCharsets;
 41 import java.time.Duration;
 42 import java.util.List;
 43 import java.util.Set;
 44 import java.util.concurrent.CompletableFuture;
 45 import java.util.concurrent.CopyOnWriteArrayList;
 46 import java.util.concurrent.CopyOnWriteArraySet;
 47 import java.util.concurrent.ExecutorService;
 48 import java.util.concurrent.LinkedBlockingQueue;
 49 import java.util.concurrent.ThreadPoolExecutor;
 50 import java.util.concurrent.TimeUnit;
 51 import java.util.concurrent.atomic.AtomicLong;
 52 import jdk.httpclient.test.lib.common.HttpServerAdapters;

 53 import static java.net.http.HttpClient.Version.HTTP_1_1;
 54 import static java.net.http.HttpClient.Version.HTTP_2;
 55 
 56 /**
 57  * @test
 58  * @summary This test verifies that the HttpClient works correctly when connected to a
 59  *          slow server.
 60  * @library /test/lib /test/jdk/java/net/httpclient/lib
 61  * @build jdk.httpclient.test.lib.common.HttpServerAdapters jdk.test.lib.net.SimpleSSLContext
 62  *        DigestEchoServer HttpSlowServerTest
 63  *        jdk.httpclient.test.lib.common.TestServerConfigurator
 64  * @run main/othervm -Dtest.requiresHost=true
 65  *                   -Djdk.httpclient.HttpClient.log=headers
 66  *                   -Djdk.internal.httpclient.debug=false
 67  *                   HttpSlowServerTest
 68  *
 69  */
 70 public class HttpSlowServerTest implements HttpServerAdapters {
 71     static final List<String> data = List.of(
 72             "Lorem ipsum",
 73             "dolor sit amet",
 74             "consectetur adipiscing elit, sed do eiusmod tempor",
 75             "quis nostrud exercitation ullamco",
 76             "laboris nisi",
 77             "ut",
 78             "aliquip ex ea commodo consequat.",
 79             "Duis aute irure dolor in reprehenderit in voluptate velit esse",
 80             "cillum dolore eu fugiat nulla pariatur.",
 81             "Excepteur sint occaecat cupidatat non proident."
 82     );
 83 

120                 .sslContext(context)
121                 .executor(clientexec)
122                 .proxy(ps);
123         return builder.build();
124     }
125 
126     public void setUp() throws Exception {
127         try {
128             InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
129 
130             // HTTP/1.1
131             http1Server = HttpTestServer.create(HTTP_1_1, null, executor);
132             http1Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/http1/");
133             http1Server.start();
134             http1URI = new URI("http://" + http1Server.serverAuthority() + "/HttpSlowServerTest/http1/");
135 
136 
137             // HTTPS/1.1
138             HttpsServer sserver1 = HttpsServer.create(sa, 100);
139             sserver1.setExecutor(executor);
140             sserver1.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), context));
141             https1Server = HttpTestServer.of(sserver1);
142             https1Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/https1/");
143             https1Server.start();
144             https1URI = new URI("https://" + https1Server.serverAuthority() + "/HttpSlowServerTest/https1/");
145 
146             // HTTP/2.0
147             http2Server = HttpTestServer.create(HTTP_2);
148             http2Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/http2/");
149             http2Server.start();
150             http2URI = new URI("http://" + http2Server.serverAuthority() + "/HttpSlowServerTest/http2/");
151 
152             // HTTPS/2.0
153             https2Server = HttpTestServer.create(HTTP_2, SSLContext.getDefault());
154             https2Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/https2/");
155             https2Server.start();
156             https2URI = new URI("https://" + https2Server.serverAuthority() + "/HttpSlowServerTest/https2/");
157 
158             proxy = DigestEchoServer.createHttpsProxyTunnel(
159                     DigestEchoServer.HttpAuthSchemeType.NONE);
160             proxyAddress = proxy.getProxyAddress();
< prev index next >