< prev index next >

test/jdk/java/net/httpclient/LargeResponseTest.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  * @bug 8231449
 61  * @summary This test verifies that the HttpClient works correctly when the server
 62  *          sends large amount of data. Note that this test will pass even without
 63  *          the fix for JDK-8231449, which is unfortunate.
 64  * @library /test/lib /test/jdk/java/net/httpclient/lib
 65  * @build jdk.httpclient.test.lib.common.HttpServerAdapters
 66  *        jdk.test.lib.net.SimpleSSLContext DigestEchoServer

 67  * @run main/othervm -Dtest.requiresHost=true
 68  *                   -Djdk.httpclient.HttpClient.log=headers
 69  *                   -Djdk.internal.httpclient.debug=true
 70  *                   LargeResponseTest
 71  *
 72  */
 73 public class LargeResponseTest implements HttpServerAdapters {
 74     static final byte[] DATA;
 75     static {
 76         DATA = new byte[64 * 1024];
 77         int len = 'z' - 'a';
 78         for (int i=0; i < DATA.length; i++) {
 79             DATA[i] = (byte) ('a' + (i % len));
 80         }
 81     }
 82 
 83     static final SSLContext context;
 84     static {
 85         try {
 86             context = new SimpleSSLContext().get();

119                 .sslContext(context)
120                 .executor(clientexec)
121                 .proxy(ps);
122         return builder.build();
123     }
124 
125     public void setUp() throws Exception {
126         try {
127             InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
128 
129             // HTTP/1.1
130             http1Server = HttpTestServer.create(HTTP_1_1, null, executor);
131             http1Server.addHandler(new HttpTestLargeHandler(), "/LargeResponseTest/http1/");
132             http1Server.start();
133             http1URI = new URI("http://" + http1Server.serverAuthority() + "/LargeResponseTest/http1/");
134 
135 
136             // HTTPS/1.1
137             HttpsServer sserver1 = HttpsServer.create(sa, 100);
138             sserver1.setExecutor(executor);
139             sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
140             https1Server = HttpTestServer.of(sserver1);
141             https1Server.addHandler(new HttpTestLargeHandler(), "/LargeResponseTest/https1/");
142             https1Server.start();
143             https1URI = new URI("https://" + https1Server.serverAuthority() + "/LargeResponseTest/https1/");
144 
145             // HTTP/2.0
146             http2Server = HttpTestServer.create(HTTP_2);
147             http2Server.addHandler(new HttpTestLargeHandler(), "/LargeResponseTest/http2/");
148             http2Server.start();
149             http2URI = new URI("http://" + http2Server.serverAuthority() + "/LargeResponseTest/http2/");
150 
151             // HTTPS/2.0
152             https2Server = HttpTestServer.create(HTTP_2, SSLContext.getDefault());
153             https2Server.addHandler(new HttpTestLargeHandler(), "/LargeResponseTest/https2/");
154             https2Server.start();
155             https2URI = new URI("https://" + https2Server.serverAuthority() + "/LargeResponseTest/https2/");
156 
157             proxy = DigestEchoServer.createHttpsProxyTunnel(
158                     DigestEchoServer.HttpAuthSchemeType.NONE);
159             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.time.Duration;
 41 import java.util.List;
 42 import java.util.Set;
 43 import java.util.concurrent.CompletableFuture;
 44 import java.util.concurrent.CopyOnWriteArrayList;
 45 import java.util.concurrent.CopyOnWriteArraySet;
 46 import java.util.concurrent.ExecutorService;
 47 import java.util.concurrent.LinkedBlockingQueue;
 48 import java.util.concurrent.ThreadPoolExecutor;
 49 import java.util.concurrent.TimeUnit;
 50 import java.util.concurrent.atomic.AtomicLong;
 51 import jdk.httpclient.test.lib.common.HttpServerAdapters;

 52 import static java.net.http.HttpClient.Version.HTTP_1_1;
 53 import static java.net.http.HttpClient.Version.HTTP_2;
 54 
 55 /**
 56  * @test
 57  * @bug 8231449
 58  * @summary This test verifies that the HttpClient works correctly when the server
 59  *          sends large amount of data. Note that this test will pass even without
 60  *          the fix for JDK-8231449, which is unfortunate.
 61  * @library /test/lib /test/jdk/java/net/httpclient/lib
 62  * @build jdk.httpclient.test.lib.common.HttpServerAdapters
 63  *        jdk.test.lib.net.SimpleSSLContext DigestEchoServer
 64  *        jdk.httpclient.test.lib.common.TestServerConfigurator
 65  * @run main/othervm -Dtest.requiresHost=true
 66  *                   -Djdk.httpclient.HttpClient.log=headers
 67  *                   -Djdk.internal.httpclient.debug=true
 68  *                   LargeResponseTest
 69  *
 70  */
 71 public class LargeResponseTest implements HttpServerAdapters {
 72     static final byte[] DATA;
 73     static {
 74         DATA = new byte[64 * 1024];
 75         int len = 'z' - 'a';
 76         for (int i=0; i < DATA.length; i++) {
 77             DATA[i] = (byte) ('a' + (i % len));
 78         }
 79     }
 80 
 81     static final SSLContext context;
 82     static {
 83         try {
 84             context = new SimpleSSLContext().get();

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