test/jdk/sun/net/www/protocol/http/B6296310.java
changeset 55522 b2cbe2f674f0
parent 47216 71c04702a3d5
equal deleted inserted replaced
55521:f9a2f93a0c87 55522:b2cbe2f674f0
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    26  * @bug 6296310
    26  * @bug 6296310
    27  * @modules java.base/sun.net.www
    27  * @modules java.base/sun.net.www
    28  * @library ../../httptest/
    28  * @library ../../httptest/
    29  * @build HttpCallback TestHttpServer HttpTransaction
    29  * @build HttpCallback TestHttpServer HttpTransaction
    30  * @run main/othervm B6296310
    30  * @run main/othervm B6296310
       
    31  * @run main/othervm -Djava.net.preferIPv6Addresses=true B6296310
    31  * @summary  REGRESSION: AppletClassLoader.getResourceAsStream() behaviour is wrong in some cases
    32  * @summary  REGRESSION: AppletClassLoader.getResourceAsStream() behaviour is wrong in some cases
    32  */
    33  */
    33 
    34 
    34 import java.net.*;
    35 import java.net.*;
    35 import java.io.*;
    36 import java.io.*;
    43 public class B6296310
    44 public class B6296310
    44 {
    45 {
    45    static SimpleHttpTransaction httpTrans;
    46    static SimpleHttpTransaction httpTrans;
    46    static TestHttpServer server;
    47    static TestHttpServer server;
    47 
    48 
    48    public static void main(String[] args)
    49    public static void main(String[] args) throws Exception
    49    {
    50    {
    50       ResponseCache.setDefault(new MyCacheHandler());
    51       ResponseCache.setDefault(new MyCacheHandler());
    51       startHttpServer();
    52       startHttpServer();
    52 
       
    53       makeHttpCall();
    53       makeHttpCall();
    54    }
    54    }
    55 
    55 
    56    public static void startHttpServer() {
    56    public static void startHttpServer() throws IOException {
    57       try {
    57      httpTrans = new SimpleHttpTransaction();
    58          httpTrans = new SimpleHttpTransaction();
    58      InetAddress loopback = InetAddress.getLoopbackAddress();
    59          server = new TestHttpServer(httpTrans, 1, 10, 0);
    59      server = new TestHttpServer(httpTrans, 1, 10, loopback, 0);
    60       } catch (IOException e) {
       
    61          e.printStackTrace();
       
    62       }
       
    63    }
    60    }
    64 
    61 
    65    public static void makeHttpCall() {
    62    public static void makeHttpCall() throws IOException {
    66       try {
    63       try {
    67          System.out.println("http server listen on: " + server.getLocalPort());
    64          System.out.println("http server listen on: " + server.getLocalPort());
    68          URL url = new URL("http" , InetAddress.getLocalHost().getHostAddress(),
    65          URL url = new URL("http" , InetAddress.getLoopbackAddress().getHostAddress(),
    69                             server.getLocalPort(), "/");
    66                             server.getLocalPort(), "/");
    70          HttpURLConnection uc = (HttpURLConnection)url.openConnection();
    67          HttpURLConnection uc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
    71          System.out.println(uc.getResponseCode());
    68          System.out.println(uc.getResponseCode());
    72       } catch (IOException e) {
       
    73          e.printStackTrace();
       
    74       } finally {
    69       } finally {
    75          server.terminate();
    70          server.terminate();
    76       }
    71       }
    77    }
    72    }
    78 }
    73 }