Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/net/httpserver/Test7a.java
38855 views
/*1* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 627001526* @run main/othervm Test7a27* @summary Light weight HTTP server28*/2930import com.sun.net.httpserver.*;3132import java.util.concurrent.*;33import java.io.*;34import java.net.*;35import javax.net.ssl.*;3637/**38* Test POST large file via chunked encoding (large chunks)39*/4041public class Test7a extends Test {4243public static void main (String[] args) throws Exception {44//Logger log = Logger.getLogger ("com.sun.net.httpserver");45//log.setLevel (Level.FINE);46//ConsoleHandler h = new ConsoleHandler();47//h.setLevel (Level.ALL);48//log.addHandler (h);49Handler handler = new Handler();50InetSocketAddress addr = new InetSocketAddress (0);51HttpsServer server = HttpsServer.create (addr, 0);52HttpContext ctx = server.createContext ("/test", handler);53ExecutorService executor = Executors.newCachedThreadPool();54SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();55server.setHttpsConfigurator(new HttpsConfigurator (ssl));56server.setExecutor (executor);57server.start ();5859URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");60System.out.print ("Test7a: " );61HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();62urlc.setDoOutput (true);63urlc.setRequestMethod ("POST");64urlc.setChunkedStreamingMode (16 * 1024); // big chunks65urlc.setHostnameVerifier (new DummyVerifier());66urlc.setSSLSocketFactory (ssl.getSocketFactory());67OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);68for (int i=0; i<SIZE; i++) {69os.write (i % 100);70}71os.close();72int resp = urlc.getResponseCode();73if (resp != 200) {74throw new RuntimeException ("test failed response code");75}76if (error) {77throw new RuntimeException ("test failed error");78}79delay();80server.stop(2);81executor.shutdown();82System.out.println ("OK");8384}8586public static boolean error = false;87final static int SIZE = 999999;8889static class Handler implements HttpHandler {90int invocation = 1;91public void handle (HttpExchange t)92throws IOException93{94InputStream is = t.getRequestBody();95Headers map = t.getRequestHeaders();96Headers rmap = t.getResponseHeaders();97int c, count=0;98while ((c=is.read ()) != -1) {99if (c != (count % 100)) {100error = true;101break;102}103count ++;104}105if (count != SIZE) {106error = true;107}108is.close();109t.sendResponseHeaders (200, -1);110t.close();111}112}113}114115116