< prev index next >

test/jdk/java/net/httpclient/ImmutableFlowItems.java

Print this page

 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 response body subscribers's onNext's Lists are unmodifiable,
 27  *          and that the buffers are read-only
 28  * @library /test/lib /test/jdk/java/net/httpclient/lib
 29  * @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer

 30  * @run testng/othervm ImmutableFlowItems
 31  */
 32 
 33 import java.io.IOException;
 34 import java.io.InputStream;
 35 import java.io.OutputStream;
 36 import java.net.InetAddress;
 37 import java.net.InetSocketAddress;
 38 import java.net.URI;
 39 import java.nio.ByteBuffer;
 40 import java.util.List;
 41 import java.util.concurrent.CompletionStage;
 42 import java.util.concurrent.Flow;
 43 import com.sun.net.httpserver.HttpExchange;
 44 import com.sun.net.httpserver.HttpHandler;
 45 import com.sun.net.httpserver.HttpServer;
 46 import com.sun.net.httpserver.HttpsConfigurator;
 47 import com.sun.net.httpserver.HttpsServer;
 48 import java.net.http.HttpClient;
 49 import java.net.http.HttpHeaders;
 50 import java.net.http.HttpRequest;
 51 import java.net.http.HttpResponse;
 52 import java.net.http.HttpResponse.BodyHandler;
 53 import java.net.http.HttpResponse.BodySubscriber;
 54 import java.net.http.HttpResponse.BodySubscribers;
 55 import javax.net.ssl.SSLContext;


 56 import jdk.httpclient.test.lib.http2.Http2TestServer;
 57 import jdk.httpclient.test.lib.http2.Http2TestExchange;
 58 import jdk.httpclient.test.lib.http2.Http2Handler;
 59 import jdk.test.lib.net.SimpleSSLContext;
 60 import org.testng.annotations.AfterTest;
 61 import org.testng.annotations.BeforeTest;
 62 import org.testng.annotations.DataProvider;
 63 import org.testng.annotations.Test;
 64 import static java.lang.System.out;
 65 import static java.nio.charset.StandardCharsets.UTF_8;
 66 import static org.testng.Assert.*;
 67 
 68 public class ImmutableFlowItems {
 69 
 70     SSLContext sslContext;
 71     HttpServer httpTestServer;         // HTTP/1.1    [ 4 servers ]
 72     HttpsServer httpsTestServer;       // HTTPS/1.1
 73     Http2TestServer http2TestServer;   // HTTP/2 ( h2c )
 74     Http2TestServer https2TestServer;  // HTTP/2 ( h2  )
 75     String httpURI_fixed;

172                 + server.getAddress().getPort();
173     }
174 
175     @BeforeTest
176     public void setup() throws Exception {
177         sslContext = new SimpleSSLContext().get();
178         if (sslContext == null)
179             throw new AssertionError("Unexpected null sslContext");
180 
181         // HTTP/1.1
182         HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
183         HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();
184         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
185         httpTestServer = HttpServer.create(sa, 0);
186         httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler);
187         httpTestServer.createContext("/http1/chunk", h1_chunkHandler);
188         httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed";
189         httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk";
190 
191         httpsTestServer = HttpsServer.create(sa, 0);
192         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
193         httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
194         httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
195         httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
196         httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk";
197 
198         // HTTP/2
199         Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler();
200         Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler();
201 
202         http2TestServer = new Http2TestServer("localhost", false, 0);
203         http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed");
204         http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk");
205         http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed";
206         http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk";
207 
208         https2TestServer = new Http2TestServer("localhost", true, sslContext);
209         https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed");
210         https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk");
211         https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed";
212         https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk";

 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 response body subscribers's onNext's Lists are unmodifiable,
 27  *          and that the buffers are read-only
 28  * @library /test/lib /test/jdk/java/net/httpclient/lib
 29  * @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer
 30  *        jdk.httpclient.test.lib.common.TestServerConfigurator
 31  * @run testng/othervm ImmutableFlowItems
 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.Flow;
 44 import com.sun.net.httpserver.HttpExchange;
 45 import com.sun.net.httpserver.HttpHandler;
 46 import com.sun.net.httpserver.HttpServer;

 47 import com.sun.net.httpserver.HttpsServer;
 48 import java.net.http.HttpClient;
 49 import java.net.http.HttpHeaders;
 50 import java.net.http.HttpRequest;
 51 import java.net.http.HttpResponse;
 52 import java.net.http.HttpResponse.BodyHandler;
 53 import java.net.http.HttpResponse.BodySubscriber;
 54 import java.net.http.HttpResponse.BodySubscribers;
 55 import javax.net.ssl.SSLContext;
 56 
 57 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 58 import jdk.httpclient.test.lib.http2.Http2TestServer;
 59 import jdk.httpclient.test.lib.http2.Http2TestExchange;
 60 import jdk.httpclient.test.lib.http2.Http2Handler;
 61 import jdk.test.lib.net.SimpleSSLContext;
 62 import org.testng.annotations.AfterTest;
 63 import org.testng.annotations.BeforeTest;
 64 import org.testng.annotations.DataProvider;
 65 import org.testng.annotations.Test;
 66 import static java.lang.System.out;
 67 import static java.nio.charset.StandardCharsets.UTF_8;
 68 import static org.testng.Assert.*;
 69 
 70 public class ImmutableFlowItems {
 71 
 72     SSLContext sslContext;
 73     HttpServer httpTestServer;         // HTTP/1.1    [ 4 servers ]
 74     HttpsServer httpsTestServer;       // HTTPS/1.1
 75     Http2TestServer http2TestServer;   // HTTP/2 ( h2c )
 76     Http2TestServer https2TestServer;  // HTTP/2 ( h2  )
 77     String httpURI_fixed;

174                 + server.getAddress().getPort();
175     }
176 
177     @BeforeTest
178     public void setup() throws Exception {
179         sslContext = new SimpleSSLContext().get();
180         if (sslContext == null)
181             throw new AssertionError("Unexpected null sslContext");
182 
183         // HTTP/1.1
184         HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
185         HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();
186         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
187         httpTestServer = HttpServer.create(sa, 0);
188         httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler);
189         httpTestServer.createContext("/http1/chunk", h1_chunkHandler);
190         httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed";
191         httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk";
192 
193         httpsTestServer = HttpsServer.create(sa, 0);
194         httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
195         httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
196         httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
197         httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
198         httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk";
199 
200         // HTTP/2
201         Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler();
202         Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler();
203 
204         http2TestServer = new Http2TestServer("localhost", false, 0);
205         http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed");
206         http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk");
207         http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed";
208         http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk";
209 
210         https2TestServer = new Http2TestServer("localhost", true, sslContext);
211         https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed");
212         https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk");
213         https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed";
214         https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk";
< prev index next >