Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/net/httpserver/Test10.java
38855 views
/*1* Copyright (c) 2010, 2011, 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 700501626* @summary pit jdk7 b121 sqe test jhttp/HttpServer150013 failing27* @run main/othervm -Dsun.net.httpserver.clockTick=1000 -Dsun.net.httpserver.idleInterval=3 Test1028*/2930import com.sun.net.httpserver.*;3132import java.io.*;33import java.net.*;34import java.util.concurrent.*;3536/*37* Test handling of empty Http headers38*/3940public class Test10 extends Test {41public static void main (String[] args) throws Exception {42System.out.print ("Test10: ");43Handler handler = new Handler();44InetSocketAddress addr = new InetSocketAddress (0);45HttpServer server = HttpServer.create (addr, 0);46int port = server.getAddress().getPort();47HttpContext c2 = server.createContext ("/test", handler);4849ExecutorService exec = Executors.newCachedThreadPool();50server.setExecutor (exec);51try {52server.start ();53doClient(port);54System.out.println ("OK");55} finally {56delay();57if (server != null)58server.stop(2);59if (exec != null)60exec.shutdown();61}62}6364static class Handler implements HttpHandler {65volatile int invocation = 0;66public void handle (HttpExchange t)67throws IOException68{69InputStream is = t.getRequestBody();70while (is.read() != -1);71Headers map = t.getRequestHeaders();72t.sendResponseHeaders (200, -1);73t.close();74}75}7677public static void doClient (int port) throws Exception {78String s = "GET /test/1.html HTTP/1.1\r\n\r\n";7980Socket socket = new Socket ("localhost", port);81OutputStream os = socket.getOutputStream();82os.write (s.getBytes());83socket.setSoTimeout (10 * 1000);84InputStream is = socket.getInputStream();85int c;86byte[] b = new byte [1024];87while ((c=is.read(b)) != -1) ;88is.close();89socket.close();90}91}929394