Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/net/www/protocol/http/B6296310.java
38867 views
/*1* Copyright (c) 2005, 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 629631026* @library ../../httptest/27* @build HttpCallback TestHttpServer HttpTransaction28* @run main/othervm B629631029* @summary REGRESSION: AppletClassLoader.getResourceAsStream() behaviour is wrong in some cases30*/3132import java.net.*;33import java.io.*;34import java.util.*;3536/*37* http server returns 200 and content-length=038* Test will throw NPE if bug still exists39*/4041public class B629631042{43static SimpleHttpTransaction httpTrans;44static TestHttpServer server;4546public static void main(String[] args)47{48ResponseCache.setDefault(new MyCacheHandler());49startHttpServer();5051makeHttpCall();52}5354public static void startHttpServer() {55try {56httpTrans = new SimpleHttpTransaction();57server = new TestHttpServer(httpTrans, 1, 10, 0);58} catch (IOException e) {59e.printStackTrace();60}61}6263public static void makeHttpCall() {64try {65System.out.println("http server listen on: " + server.getLocalPort());66URL url = new URL("http" , InetAddress.getLocalHost().getHostAddress(),67server.getLocalPort(), "/");68HttpURLConnection uc = (HttpURLConnection)url.openConnection();69System.out.println(uc.getResponseCode());70} catch (IOException e) {71e.printStackTrace();72} finally {73server.terminate();74}75}76}7778class SimpleHttpTransaction implements HttpCallback79{80/*81* Our http server which simply retruns a file with no content82*/83public void request(HttpTransaction trans) {84try {85trans.setResponseEntityBody("");86trans.sendResponse(200, "OK");87} catch (Exception e) {88e.printStackTrace();89}90}91}9293class MyCacheHandler extends ResponseCache94{95public CacheResponse get(URI uri, String rqstMethod, Map rqstHeaders)96{97return null;98}99100public CacheRequest put(URI uri, URLConnection conn)101{102return new MyCacheRequest();103}104}105106class MyCacheRequest extends CacheRequest107{108public void abort() {}109110public OutputStream getBody() throws IOException {111return null;112}113}114115116