< prev index next >

test/jdk/java/net/httpclient/MappingResponseSubscriber.java

Print this page

  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 
 24 /*
 25  * @test
 26  * @summary Tests mapped response subscriber
 27  * @library /test/lib /test/jdk/java/net/httpclient/lib
 28  * @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer

 29  * @run testng/othervm
 30  *       -Djdk.internal.httpclient.debug=true
 31  *      MappingResponseSubscriber
 32  */
 33 
 34 import java.io.IOException;
 35 import java.io.InputStream;
 36 import java.io.OutputStream;
 37 import java.net.InetAddress;
 38 import java.net.InetSocketAddress;
 39 import java.net.URI;
 40 import java.nio.ByteBuffer;
 41 import java.util.List;
 42 import java.util.concurrent.CompletionStage;
 43 import java.util.concurrent.Executor;
 44 import java.util.concurrent.Executors;
 45 import java.util.concurrent.Flow;
 46 import com.sun.net.httpserver.HttpExchange;
 47 import com.sun.net.httpserver.HttpHandler;
 48 import com.sun.net.httpserver.HttpServer;
 49 import com.sun.net.httpserver.HttpsConfigurator;
 50 import com.sun.net.httpserver.HttpsServer;
 51 import java.net.http.HttpClient;
 52 import java.net.http.HttpHeaders;
 53 import java.net.http.HttpRequest;
 54 import java.net.http.HttpResponse;
 55 import java.net.http.HttpResponse.BodyHandler;
 56 import java.net.http.HttpResponse.BodyHandlers;
 57 import java.net.http.HttpResponse.BodySubscribers;
 58 import  java.net.http.HttpResponse.BodySubscriber;
 59 import java.util.function.Function;
 60 import javax.net.ssl.SSLContext;
 61 

 62 import jdk.internal.net.http.common.OperationTrackers.Tracker;
 63 import jdk.httpclient.test.lib.http2.Http2TestServer;
 64 import jdk.httpclient.test.lib.http2.Http2TestExchange;
 65 import jdk.httpclient.test.lib.http2.Http2Handler;
 66 import jdk.test.lib.net.SimpleSSLContext;
 67 import org.testng.annotations.AfterTest;
 68 import org.testng.annotations.BeforeTest;
 69 import org.testng.annotations.DataProvider;
 70 import org.testng.annotations.Test;
 71 import static java.lang.System.out;
 72 import static java.nio.charset.StandardCharsets.UTF_8;
 73 import static org.testng.Assert.assertEquals;
 74 import static org.testng.Assert.assertTrue;
 75 
 76 public class MappingResponseSubscriber {
 77 
 78     SSLContext sslContext;
 79     HttpServer httpTestServer;         // HTTP/1.1    [ 4 servers ]
 80     HttpsServer httpsTestServer;       // HTTPS/1.1
 81     Http2TestServer http2TestServer;   // HTTP/2 ( h2c )

213                 + server.getAddress().getPort();
214     }
215 
216     @BeforeTest
217     public void setup() throws Exception {
218         sslContext = new SimpleSSLContext().get();
219         if (sslContext == null)
220             throw new AssertionError("Unexpected null sslContext");
221 
222         // HTTP/1.1
223         HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
224         HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();
225         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
226         httpTestServer = HttpServer.create(sa, 0);
227         httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler);
228         httpTestServer.createContext("/http1/chunk", h1_chunkHandler);
229         httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed";
230         httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk";
231 
232         httpsTestServer = HttpsServer.create(sa, 0);
233         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
234         httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
235         httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
236         httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
237         httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk";
238 
239         // HTTP/2
240         Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler();
241         Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler();
242 
243         http2TestServer = new Http2TestServer("localhost", false, 0);
244         http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed");
245         http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk");
246         http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed";
247         http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk";
248 
249         https2TestServer = new Http2TestServer("localhost", true, sslContext);
250         https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed");
251         https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk");
252         https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed";
253         https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk";

  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 
 24 /*
 25  * @test
 26  * @summary Tests mapped response subscriber
 27  * @library /test/lib /test/jdk/java/net/httpclient/lib
 28  * @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer
 29  *        jdk.httpclient.test.lib.common.TestServerConfigurator
 30  * @run testng/othervm
 31  *       -Djdk.internal.httpclient.debug=true
 32  *      MappingResponseSubscriber
 33  */
 34 
 35 import java.io.IOException;
 36 import java.io.InputStream;
 37 import java.io.OutputStream;
 38 import java.net.InetAddress;
 39 import java.net.InetSocketAddress;
 40 import java.net.URI;
 41 import java.nio.ByteBuffer;
 42 import java.util.List;
 43 import java.util.concurrent.CompletionStage;
 44 import java.util.concurrent.Executor;
 45 import java.util.concurrent.Executors;
 46 import java.util.concurrent.Flow;
 47 import com.sun.net.httpserver.HttpExchange;
 48 import com.sun.net.httpserver.HttpHandler;
 49 import com.sun.net.httpserver.HttpServer;

 50 import com.sun.net.httpserver.HttpsServer;
 51 import java.net.http.HttpClient;
 52 import java.net.http.HttpHeaders;
 53 import java.net.http.HttpRequest;
 54 import java.net.http.HttpResponse;
 55 import java.net.http.HttpResponse.BodyHandler;
 56 import java.net.http.HttpResponse.BodyHandlers;
 57 import java.net.http.HttpResponse.BodySubscribers;
 58 import  java.net.http.HttpResponse.BodySubscriber;
 59 import java.util.function.Function;
 60 import javax.net.ssl.SSLContext;
 61 
 62 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 63 import jdk.internal.net.http.common.OperationTrackers.Tracker;
 64 import jdk.httpclient.test.lib.http2.Http2TestServer;
 65 import jdk.httpclient.test.lib.http2.Http2TestExchange;
 66 import jdk.httpclient.test.lib.http2.Http2Handler;
 67 import jdk.test.lib.net.SimpleSSLContext;
 68 import org.testng.annotations.AfterTest;
 69 import org.testng.annotations.BeforeTest;
 70 import org.testng.annotations.DataProvider;
 71 import org.testng.annotations.Test;
 72 import static java.lang.System.out;
 73 import static java.nio.charset.StandardCharsets.UTF_8;
 74 import static org.testng.Assert.assertEquals;
 75 import static org.testng.Assert.assertTrue;
 76 
 77 public class MappingResponseSubscriber {
 78 
 79     SSLContext sslContext;
 80     HttpServer httpTestServer;         // HTTP/1.1    [ 4 servers ]
 81     HttpsServer httpsTestServer;       // HTTPS/1.1
 82     Http2TestServer http2TestServer;   // HTTP/2 ( h2c )

214                 + server.getAddress().getPort();
215     }
216 
217     @BeforeTest
218     public void setup() throws Exception {
219         sslContext = new SimpleSSLContext().get();
220         if (sslContext == null)
221             throw new AssertionError("Unexpected null sslContext");
222 
223         // HTTP/1.1
224         HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
225         HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();
226         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
227         httpTestServer = HttpServer.create(sa, 0);
228         httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler);
229         httpTestServer.createContext("/http1/chunk", h1_chunkHandler);
230         httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed";
231         httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk";
232 
233         httpsTestServer = HttpsServer.create(sa, 0);
234         httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
235         httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
236         httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
237         httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
238         httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk";
239 
240         // HTTP/2
241         Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler();
242         Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler();
243 
244         http2TestServer = new Http2TestServer("localhost", false, 0);
245         http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed");
246         http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk");
247         http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed";
248         http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk";
249 
250         https2TestServer = new Http2TestServer("localhost", true, sslContext);
251         https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed");
252         https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk");
253         https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed";
254         https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk";
< prev index next >