1754N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1754N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1754N/A *
1754N/A * This code is free software; you can redistribute it and/or modify it
1754N/A * under the terms of the GNU General Public License version 2 only, as
1754N/A * published by the Free Software Foundation.
1754N/A *
1754N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1754N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1754N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1754N/A * version 2 for more details (a copy is included in the LICENSE file that
1754N/A * accompanied this code).
1754N/A *
1754N/A * You should have received a copy of the GNU General Public License version
1754N/A * 2 along with this work; if not, write to the Free Software Foundation,
1754N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1754N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1754N/A */
1754N/A
1754N/A/**
1754N/A * @test
1754N/A * @bug 6886436
1754N/A * @summary
1754N/A */
1754N/A
1754N/Aimport com.sun.net.httpserver.*;
1754N/A
1754N/Aimport java.util.*;
1754N/Aimport java.util.concurrent.*;
1754N/Aimport java.util.logging.*;
1754N/Aimport java.io.*;
1754N/Aimport java.net.*;
1754N/A
1754N/Apublic class B6886436 {
1754N/A
1754N/A public static void main (String[] args) throws Exception {
1754N/A Logger logger = Logger.getLogger ("com.sun.net.httpserver");
1754N/A ConsoleHandler c = new ConsoleHandler();
1754N/A c.setLevel (Level.WARNING);
1754N/A logger.addHandler (c);
1754N/A logger.setLevel (Level.WARNING);
1754N/A Handler handler = new Handler();
1754N/A InetSocketAddress addr = new InetSocketAddress (0);
1754N/A HttpServer server = HttpServer.create (addr, 0);
1754N/A HttpContext ctx = server.createContext ("/test", handler);
1754N/A ExecutorService executor = Executors.newCachedThreadPool();
1754N/A server.setExecutor (executor);
1754N/A server.start ();
1754N/A
1754N/A URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
1754N/A HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
1754N/A try {
1754N/A InputStream is = urlc.getInputStream();
1754N/A while (is.read()!= -1) ;
1754N/A is.close ();
1754N/A urlc = (HttpURLConnection)url.openConnection ();
1754N/A urlc.setReadTimeout (3000);
1754N/A is = urlc.getInputStream();
1754N/A while (is.read()!= -1);
1754N/A is.close ();
1754N/A
1754N/A } catch (IOException e) {
1754N/A server.stop(2);
1754N/A executor.shutdown();
1754N/A throw new RuntimeException ("Test failed");
1754N/A }
1754N/A server.stop(2);
1754N/A executor.shutdown();
1754N/A System.out.println ("OK");
1754N/A }
1754N/A
1754N/A public static boolean error = false;
1754N/A
1754N/A static class Handler implements HttpHandler {
1754N/A int invocation = 1;
1754N/A public void handle (HttpExchange t)
1754N/A throws IOException
1754N/A {
1754N/A InputStream is = t.getRequestBody();
1754N/A Headers map = t.getRequestHeaders();
1754N/A Headers rmap = t.getResponseHeaders();
1754N/A while (is.read () != -1) ;
1754N/A is.close();
1754N/A // send a 204 response with an empty chunked body
1754N/A t.sendResponseHeaders (204, 0);
1754N/A t.close();
1754N/A }
1754N/A }
1754N/A}