Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/net/httpserver/bugs/B6886436.java
38867 views
/*1* Copyright (c) 2009, 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 688643626* @summary27*/2829import com.sun.net.httpserver.*;3031import java.util.*;32import java.util.concurrent.*;33import java.util.logging.*;34import java.io.*;35import java.net.*;3637public class B6886436 {3839public static void main (String[] args) throws Exception {40Logger logger = Logger.getLogger ("com.sun.net.httpserver");41ConsoleHandler c = new ConsoleHandler();42c.setLevel (Level.WARNING);43logger.addHandler (c);44logger.setLevel (Level.WARNING);45Handler handler = new Handler();46InetSocketAddress addr = new InetSocketAddress (0);47HttpServer server = HttpServer.create (addr, 0);48HttpContext ctx = server.createContext ("/test", handler);49ExecutorService executor = Executors.newCachedThreadPool();50server.setExecutor (executor);51server.start ();5253URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");54HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();55try {56InputStream is = urlc.getInputStream();57while (is.read()!= -1) ;58is.close ();59urlc = (HttpURLConnection)url.openConnection ();60urlc.setReadTimeout (3000);61is = urlc.getInputStream();62while (is.read()!= -1);63is.close ();6465} catch (IOException e) {66server.stop(2);67executor.shutdown();68throw new RuntimeException ("Test failed");69}70server.stop(2);71executor.shutdown();72System.out.println ("OK");73}7475public static boolean error = false;7677static class Handler implements HttpHandler {78int invocation = 1;79public void handle (HttpExchange t)80throws IOException81{82InputStream is = t.getRequestBody();83Headers map = t.getRequestHeaders();84Headers rmap = t.getResponseHeaders();85while (is.read () != -1) ;86is.close();87// send a 204 response with an empty chunked body88t.sendResponseHeaders (204, 0);89t.close();90}91}92}939495