Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/net/www/protocol/http/SetChunkedStreamingMode.java
38867 views
/*1* Copyright (c) 2004, 2012, 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 504997626* @library ../../httptest/27@build HttpCallback TestHttpServer ClosedChannelList HttpTransaction28* @run main SetChunkedStreamingMode29* @summary Unspecified NPE is thrown when streaming output mode is enabled30*/3132import java.io.*;33import java.net.*;3435public class SetChunkedStreamingMode implements HttpCallback {3637void okReply (HttpTransaction req) throws IOException {38req.setResponseEntityBody ("Hello .");39req.sendResponse (200, "Ok");40System.out.println ("Server: sent response");41req.orderlyClose();42}4344public void request (HttpTransaction req) {45try {46okReply (req);47} catch (IOException e) {48e.printStackTrace();49}50}5152static void read (InputStream is) throws IOException {53int c;54System.out.println ("reading");55while ((c=is.read()) != -1) {56System.out.write (c);57}58System.out.println ("");59System.out.println ("finished reading");60}6162static TestHttpServer server;6364public static void main (String[] args) throws Exception {65try {66server = new TestHttpServer (new SetChunkedStreamingMode(), 1, 10, 0);67System.out.println ("Server: listening on port: " + server.getLocalPort());68URL url = new URL ("http://127.0.0.1:"+server.getLocalPort()+"/");69System.out.println ("Client: connecting to " + url);70HttpURLConnection urlc = (HttpURLConnection)url.openConnection();71urlc.setChunkedStreamingMode (0);72urlc.setRequestMethod("POST");73urlc.setDoOutput(true);74InputStream is = urlc.getInputStream();75} catch (Exception e) {76if (server != null) {77server.terminate();78}79throw e;80}81server.terminate();82}8384public static void except (String s) {85server.terminate();86throw new RuntimeException (s);87}88}899091