< prev index next >

test/jdk/java/net/httpclient/ConcurrentResponses.java

Print this page

 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 
 24 /*
 25  * @test
 26  * @bug 8195823
 27  * @summary Buffers given to response body subscribers should not contain
 28  *          unprocessed HTTP data
 29  * @library /test/lib /test/jdk/java/net/httpclient/lib
 30  * @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext

 31  * @run testng/othervm
 32  *      -Djdk.tracePinnedThreads=full
 33  *      -Djdk.httpclient.HttpClient.log=headers,errors,channel
 34  *      ConcurrentResponses
 35  */
 36 
 37 import java.io.IOException;
 38 import java.io.InputStream;
 39 import java.io.OutputStream;
 40 import java.net.InetAddress;
 41 import java.net.InetSocketAddress;
 42 import java.net.URI;
 43 import java.nio.ByteBuffer;
 44 import java.util.HashMap;
 45 import java.util.List;
 46 import java.util.Map;
 47 import java.util.concurrent.CompletableFuture;
 48 import java.util.concurrent.CompletionStage;
 49 import java.util.concurrent.ExecutorService;
 50 import java.util.concurrent.Executors;
 51 import java.util.concurrent.Flow;
 52 import java.util.concurrent.atomic.AtomicInteger;
 53 import java.util.stream.IntStream;
 54 import javax.net.ssl.SSLContext;
 55 import com.sun.net.httpserver.HttpExchange;
 56 import com.sun.net.httpserver.HttpHandler;
 57 import com.sun.net.httpserver.HttpServer;
 58 import com.sun.net.httpserver.HttpsConfigurator;
 59 import com.sun.net.httpserver.HttpsServer;
 60 import java.net.http.HttpClient;
 61 import java.net.http.HttpRequest;
 62 import java.net.http.HttpResponse;
 63 import java.net.http.HttpResponse.BodyHandler;
 64 import java.net.http.HttpResponse.BodyHandlers;
 65 import java.net.http.HttpResponse.BodySubscriber;
 66 import java.net.http.HttpResponse.BodySubscribers;


 67 import jdk.httpclient.test.lib.http2.Http2TestServer;
 68 import jdk.httpclient.test.lib.http2.Http2TestExchange;
 69 import jdk.httpclient.test.lib.http2.Http2Handler;
 70 import jdk.test.lib.net.SimpleSSLContext;
 71 import org.testng.annotations.AfterTest;
 72 import org.testng.annotations.BeforeTest;
 73 import org.testng.annotations.DataProvider;
 74 import org.testng.annotations.Test;
 75 import static java.nio.charset.StandardCharsets.UTF_8;
 76 import static java.net.http.HttpResponse.BodyHandlers.discarding;
 77 import static org.testng.Assert.assertEquals;
 78 import static org.testng.Assert.assertFalse;
 79 import static org.testng.Assert.fail;
 80 
 81 public class ConcurrentResponses {
 82 
 83     SSLContext sslContext;
 84     HttpServer httpTestServer;         // HTTP/1.1    [ 4 servers ]
 85     HttpsServer httpsTestServer;       // HTTPS/1.1
 86     Http2TestServer http2TestServer;   // HTTP/2 ( h2c )

274 
275     static String serverAuthority(HttpServer server) {
276         return InetAddress.getLoopbackAddress().getHostName() + ":"
277                 + server.getAddress().getPort();
278     }
279 
280     @BeforeTest
281     public void setup() throws Exception {
282         sslContext = new SimpleSSLContext().get();
283         if (sslContext == null)
284             throw new AssertionError("Unexpected null sslContext");
285 
286         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
287         httpTestServer = HttpServer.create(sa, 0);
288         httpTestServer.createContext("/http1/fixed", new Http1FixedHandler());
289         httpFixedURI = "http://" + serverAuthority(httpTestServer) + "/http1/fixed";
290         httpTestServer.createContext("/http1/chunked", new Http1ChunkedHandler());
291         httpChunkedURI = "http://" + serverAuthority(httpTestServer) + "/http1/chunked";
292 
293         httpsTestServer = HttpsServer.create(sa, 0);
294         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
295         httpsTestServer.createContext("/https1/fixed", new Http1FixedHandler());
296         httpsFixedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
297         httpsTestServer.createContext("/https1/chunked", new Http1ChunkedHandler());
298         httpsChunkedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/chunked";
299 
300         http2TestServer = new Http2TestServer("localhost", false, 0);
301         http2TestServer.addHandler(new Http2FixedHandler(), "/http2/fixed");
302         http2FixedURI = "http://" + http2TestServer.serverAuthority()+ "/http2/fixed";
303         http2TestServer.addHandler(new Http2VariableHandler(), "/http2/variable");
304         http2VariableURI = "http://" + http2TestServer.serverAuthority() + "/http2/variable";
305 
306         https2TestServer = new Http2TestServer("localhost", true, sslContext);
307         https2TestServer.addHandler(new Http2FixedHandler(), "/https2/fixed");
308         https2FixedURI = "https://" + https2TestServer.serverAuthority() + "/https2/fixed";
309         https2TestServer.addHandler(new Http2VariableHandler(), "/https2/variable");
310         https2VariableURI = "https://" + https2TestServer.serverAuthority() + "/https2/variable";
311 
312         httpTestServer.start();
313         httpsTestServer.start();
314         http2TestServer.start();

 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 
 24 /*
 25  * @test
 26  * @bug 8195823
 27  * @summary Buffers given to response body subscribers should not contain
 28  *          unprocessed HTTP data
 29  * @library /test/lib /test/jdk/java/net/httpclient/lib
 30  * @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
 31  *        jdk.httpclient.test.lib.common.TestServerConfigurator
 32  * @run testng/othervm
 33  *      -Djdk.tracePinnedThreads=full
 34  *      -Djdk.httpclient.HttpClient.log=headers,errors,channel
 35  *      ConcurrentResponses
 36  */
 37 
 38 import java.io.IOException;
 39 import java.io.InputStream;
 40 import java.io.OutputStream;
 41 import java.net.InetAddress;
 42 import java.net.InetSocketAddress;
 43 import java.net.URI;
 44 import java.nio.ByteBuffer;
 45 import java.util.HashMap;
 46 import java.util.List;
 47 import java.util.Map;
 48 import java.util.concurrent.CompletableFuture;
 49 import java.util.concurrent.CompletionStage;
 50 import java.util.concurrent.ExecutorService;
 51 import java.util.concurrent.Executors;
 52 import java.util.concurrent.Flow;
 53 import java.util.concurrent.atomic.AtomicInteger;
 54 import java.util.stream.IntStream;
 55 import javax.net.ssl.SSLContext;
 56 import com.sun.net.httpserver.HttpExchange;
 57 import com.sun.net.httpserver.HttpHandler;
 58 import com.sun.net.httpserver.HttpServer;

 59 import com.sun.net.httpserver.HttpsServer;
 60 import java.net.http.HttpClient;
 61 import java.net.http.HttpRequest;
 62 import java.net.http.HttpResponse;
 63 import java.net.http.HttpResponse.BodyHandler;
 64 import java.net.http.HttpResponse.BodyHandlers;
 65 import java.net.http.HttpResponse.BodySubscriber;
 66 import java.net.http.HttpResponse.BodySubscribers;
 67 
 68 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 69 import jdk.httpclient.test.lib.http2.Http2TestServer;
 70 import jdk.httpclient.test.lib.http2.Http2TestExchange;
 71 import jdk.httpclient.test.lib.http2.Http2Handler;
 72 import jdk.test.lib.net.SimpleSSLContext;
 73 import org.testng.annotations.AfterTest;
 74 import org.testng.annotations.BeforeTest;
 75 import org.testng.annotations.DataProvider;
 76 import org.testng.annotations.Test;
 77 import static java.nio.charset.StandardCharsets.UTF_8;
 78 import static java.net.http.HttpResponse.BodyHandlers.discarding;
 79 import static org.testng.Assert.assertEquals;
 80 import static org.testng.Assert.assertFalse;
 81 import static org.testng.Assert.fail;
 82 
 83 public class ConcurrentResponses {
 84 
 85     SSLContext sslContext;
 86     HttpServer httpTestServer;         // HTTP/1.1    [ 4 servers ]
 87     HttpsServer httpsTestServer;       // HTTPS/1.1
 88     Http2TestServer http2TestServer;   // HTTP/2 ( h2c )

276 
277     static String serverAuthority(HttpServer server) {
278         return InetAddress.getLoopbackAddress().getHostName() + ":"
279                 + server.getAddress().getPort();
280     }
281 
282     @BeforeTest
283     public void setup() throws Exception {
284         sslContext = new SimpleSSLContext().get();
285         if (sslContext == null)
286             throw new AssertionError("Unexpected null sslContext");
287 
288         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
289         httpTestServer = HttpServer.create(sa, 0);
290         httpTestServer.createContext("/http1/fixed", new Http1FixedHandler());
291         httpFixedURI = "http://" + serverAuthority(httpTestServer) + "/http1/fixed";
292         httpTestServer.createContext("/http1/chunked", new Http1ChunkedHandler());
293         httpChunkedURI = "http://" + serverAuthority(httpTestServer) + "/http1/chunked";
294 
295         httpsTestServer = HttpsServer.create(sa, 0);
296         httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
297         httpsTestServer.createContext("/https1/fixed", new Http1FixedHandler());
298         httpsFixedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
299         httpsTestServer.createContext("/https1/chunked", new Http1ChunkedHandler());
300         httpsChunkedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/chunked";
301 
302         http2TestServer = new Http2TestServer("localhost", false, 0);
303         http2TestServer.addHandler(new Http2FixedHandler(), "/http2/fixed");
304         http2FixedURI = "http://" + http2TestServer.serverAuthority()+ "/http2/fixed";
305         http2TestServer.addHandler(new Http2VariableHandler(), "/http2/variable");
306         http2VariableURI = "http://" + http2TestServer.serverAuthority() + "/http2/variable";
307 
308         https2TestServer = new Http2TestServer("localhost", true, sslContext);
309         https2TestServer.addHandler(new Http2FixedHandler(), "/https2/fixed");
310         https2FixedURI = "https://" + https2TestServer.serverAuthority() + "/https2/fixed";
311         https2TestServer.addHandler(new Http2VariableHandler(), "/https2/variable");
312         https2VariableURI = "https://" + https2TestServer.serverAuthority() + "/https2/variable";
313 
314         httpTestServer.start();
315         httpsTestServer.start();
316         http2TestServer.start();
< prev index next >