Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/net/httpserver/Test6a.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 Test6a27* @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 https POST large file via chunked encoding (unusually small chunks)39*/4041public class Test6a extends Test {4243public static void main (String[] args) throws Exception {44Handler handler = new Handler();45InetSocketAddress addr = new InetSocketAddress (0);46HttpsServer server = HttpsServer.create (addr, 0);47HttpContext ctx = server.createContext ("/test", handler);48ExecutorService executor = Executors.newCachedThreadPool();49SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();50server.setExecutor (executor);51server.setHttpsConfigurator(new HttpsConfigurator (ssl));52server.start ();5354URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");55System.out.print ("Test6a: " );56HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();57urlc.setDoOutput (true);58urlc.setRequestMethod ("POST");59urlc.setChunkedStreamingMode (32); // small chunks60urlc.setSSLSocketFactory (ssl.getSocketFactory());61urlc.setHostnameVerifier (new DummyVerifier());62OutputStream os = new BufferedOutputStream (urlc.getOutputStream());63for (int i=0; i<SIZE; i++) {64os.write (i % 100);65}66os.close();67int resp = urlc.getResponseCode();68if (resp != 200) {69throw new RuntimeException ("test failed response code");70}71if (error) {72throw new RuntimeException ("test failed error");73}74delay();75server.stop(2);76executor.shutdown();77System.out.println ("OK");7879}8081public static boolean error = false;82final static int SIZE = 999999;8384static class Handler implements HttpHandler {85int invocation = 1;86public void handle (HttpExchange t)87throws IOException88{89InputStream is = t.getRequestBody();90Headers map = t.getRequestHeaders();91Headers rmap = t.getResponseHeaders();92int c, count=0;93while ((c=is.read ()) != -1) {94if (c != (count % 100)) {95error = true;96break;97}98count ++;99}100if (count != SIZE) {101error = true;102}103is.close();104t.sendResponseHeaders (200, -1);105t.close();106}107}108}109110111