test/langtools/jdk/javadoc/doclet/testLinkOption/TestRedirectLinks.java
author jjg
Fri, 21 Dec 2018 10:38:33 -0800
changeset 53097 2e82ca64b25d
parent 52687 526f5cf13972
child 53562 0d9dee001667
permissions -rw-r--r--
8215516: Move JavadocTester to a named package Reviewed-by: hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52687
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     1
/*
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     2
 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     4
 *
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     8
 *
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    13
 * accompanied this code).
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    14
 *
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    18
 *
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    21
 * questions.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    22
 */
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    23
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    24
/*
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    25
 * @test
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    26
 * @bug 8190312
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    27
 * @summary test redirected URLs for -link
53097
2e82ca64b25d 8215516: Move JavadocTester to a named package
jjg
parents: 52687
diff changeset
    28
 * @library /tools/lib ../../lib
52687
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    31
 *          jdk.javadoc/jdk.javadoc.internal.api
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    32
 *          jdk.javadoc/jdk.javadoc.internal.tool
53097
2e82ca64b25d 8215516: Move JavadocTester to a named package
jjg
parents: 52687
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JavacTask javadoc.tester.*
52687
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    34
 * @run main TestRedirectLinks
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    35
 */
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    36
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    37
import java.io.File;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    38
import java.io.IOException;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    39
import java.io.InputStream;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    40
import java.io.OutputStream;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    41
import java.net.HttpURLConnection;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    42
import java.net.InetAddress;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    43
import java.net.InetSocketAddress;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    44
import java.net.URL;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    45
import java.net.URLConnection;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    46
import java.nio.file.Files;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    47
import java.nio.file.Path;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    48
import java.security.KeyStore;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    49
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    50
import javax.net.ssl.HostnameVerifier;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    51
import javax.net.ssl.HttpsURLConnection;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    52
import javax.net.ssl.KeyManagerFactory;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    53
import javax.net.ssl.SSLContext;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    54
import javax.net.ssl.SSLSocketFactory;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    55
import javax.net.ssl.TrustManagerFactory;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    56
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    57
import com.sun.net.httpserver.HttpExchange;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    58
import com.sun.net.httpserver.HttpServer;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    59
import com.sun.net.httpserver.HttpsConfigurator;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    60
import com.sun.net.httpserver.HttpsServer;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    61
53097
2e82ca64b25d 8215516: Move JavadocTester to a named package
jjg
parents: 52687
diff changeset
    62
import javadoc.tester.JavadocTester;
52687
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    63
import toolbox.JavacTask;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    64
import toolbox.ToolBox;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    65
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    66
public class TestRedirectLinks extends JavadocTester {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    67
    /**
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    68
     * The entry point of the test.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    69
     * @param args the array of command line arguments.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    70
     */
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    71
    public static void main(String... args) throws Exception {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    72
        TestRedirectLinks tester = new TestRedirectLinks();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    73
        tester.runTests();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    74
    }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    75
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    76
    private ToolBox tb = new ToolBox();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    77
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    78
    /*
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    79
     * This test requires access to a URL that is redirected
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    80
     * from http: to https:.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    81
     * For now, we use the main JDK API on docs.oracle.com.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    82
     * The test is skipped if access to the server is not available.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    83
     * (A better solution is to use a local testing web server.)
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    84
     */
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    85
    @Test
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    86
    public void testRedirects() throws Exception {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    87
        // first, test to see if access to external URLs is available
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    88
        URL testURL = new URL("http://docs.oracle.com/en/java/javase/11/docs/api/element-list");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    89
        boolean haveRedirectURL = false;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    90
        try {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    91
            URLConnection conn = testURL.openConnection();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    92
            conn.connect();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    93
            out.println("Opened connection to " + testURL);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    94
            if (conn instanceof HttpURLConnection) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    95
                HttpURLConnection httpConn = (HttpURLConnection) conn;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    96
                int status = httpConn.getResponseCode();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    97
                if (status / 100 == 3) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    98
                    haveRedirectURL = true;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
    99
                }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   100
                out.println("Status: " + status);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   101
                int n = 0;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   102
                while (httpConn.getHeaderField(n) != null) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   103
                    out.println("Header: " + httpConn.getHeaderFieldKey(n) + ": " + httpConn.getHeaderField(n));
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   104
                    n++;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   105
                }
53097
2e82ca64b25d 8215516: Move JavadocTester to a named package
jjg
parents: 52687
diff changeset
   106
                httpConn.disconnect();
52687
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   107
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   108
        } catch (Exception e) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   109
            out.println("Exception occurred: " + e);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   110
        }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   111
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   112
        if (!haveRedirectURL) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   113
            out.println("Setup failed; this test skipped");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   114
            return;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   115
        }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   116
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   117
        String apiURL = "http://docs.oracle.com/en/java/javase/11/docs/api";
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   118
        String outRedirect = "outRedirect";
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   119
        javadoc("-d", outRedirect,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   120
                "-html4",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   121
                "-sourcepath", testSrc,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   122
                "-link", apiURL,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   123
                "pkg");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   124
        checkExit(Exit.OK);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   125
        checkOutput("pkg/B.html", true,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   126
                "<a href=\"" + apiURL + "/java.base/java/lang/String.html?is-external=true\" "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   127
                        + "title=\"class or interface in java.lang\" class=\"externalLink\">Link-Plain to String Class</a>");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   128
        checkOutput("pkg/C.html", true,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   129
                "<a href=\"" + apiURL + "/java.base/java/lang/Object.html?is-external=true\" "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   130
                        + "title=\"class or interface in java.lang\" class=\"externalLink\">Object</a>");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   131
    }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   132
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   133
    private Path libApi = Path.of("libApi");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   134
    private HttpServer oldServer = null;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   135
    private HttpsServer newServer = null;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   136
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   137
    /**
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   138
     * This test verifies redirection using temporary localhost web servers,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   139
     * such that one server redirects to the other.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   140
     */
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   141
    @Test
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   142
    public void testWithServers() throws Exception {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   143
        // Set up a simple library
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   144
        Path libSrc = Path.of("libSrc");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   145
        tb.writeJavaFiles(libSrc.resolve("mA"),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   146
                "module mA { exports p1; exports p2; }",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   147
                "package p1; public class C1 { }",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   148
                "package p2; public class C2 { }");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   149
        tb.writeJavaFiles(libSrc.resolve("mB"),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   150
                "module mB { exports p3; exports p4; }",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   151
                "package p3; public class C3 { }",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   152
                "package p4; public class C4 { }");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   153
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   154
        Path libModules = Path.of("libModules");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   155
        Files.createDirectories(libModules);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   156
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   157
        new JavacTask(tb)
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   158
                .outdir(libModules)
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   159
                .options("--module-source-path", libSrc.toString(),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   160
                        "--module", "mA,mB")
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   161
                .run()
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   162
                .writeAll();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   163
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   164
        javadoc("-d", libApi.toString(),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   165
                "--module-source-path", libSrc.toString(),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   166
                "--module", "mA,mB" );
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   167
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   168
        // start web servers
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   169
        InetAddress localHost = InetAddress.getLocalHost();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   170
        try {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   171
            oldServer = HttpServer.create(new InetSocketAddress(localHost, 0), 0);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   172
            String oldURL = "http:/" + oldServer.getAddress();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   173
            oldServer.createContext("/", this::handleOldRequest);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   174
            out.println("Starting old server (" + oldServer.getClass().getSimpleName() + ") on " + oldURL);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   175
            oldServer.start();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   176
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   177
            SSLContext sslContext = new SimpleSSLContext().get();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   178
            newServer = HttpsServer.create(new InetSocketAddress(localHost, 0), 0);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   179
            String newURL = "https:/" + newServer.getAddress();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   180
            newServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   181
            newServer.createContext("/", this::handleNewRequest);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   182
            out.println("Starting new server (" + newServer.getClass().getSimpleName() + ") on " + newURL);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   183
            newServer.start();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   184
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   185
            // Set up API to use that library
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   186
            Path src = Path.of("src");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   187
            tb.writeJavaFiles(src.resolve("mC"),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   188
                    "module mC { requires mA; requires mB; exports p5; exports p6; }",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   189
                    "package p5; public class C5 extends p1.C1 { }",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   190
                    "package p6; public class C6 { public p4.C4 c4; }");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   191
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   192
            // Set defaults for HttpsURLConfiguration for the duration of this
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   193
            // invocation of javadoc to use our testing sslContext
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   194
            HostnameVerifier prevHostNameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   195
            SSLSocketFactory prevSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   196
            try {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   197
                HttpsURLConnection.setDefaultHostnameVerifier((hostName, session) -> true);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   198
                HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   199
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   200
                javadoc("-d", "api",
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   201
                        "--module-source-path", src.toString(),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   202
                        "--module-path", libModules.toString(),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   203
                        "-link", "http:/" + oldServer.getAddress(),
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   204
                        "--module", "mC" );
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   205
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   206
            } finally {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   207
                HttpsURLConnection.setDefaultHostnameVerifier(prevHostNameVerifier);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   208
                HttpsURLConnection.setDefaultSSLSocketFactory(prevSSLSocketFactory);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   209
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   210
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   211
            // Verify the following:
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   212
            // 1: A warning about the redirection is generated.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   213
            // 2: The contents of the redirected link were read successfully,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   214
            //    identifying the remote API
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   215
            // 3: The original URL is still used in the generated docs, to avoid assuming
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   216
            //    that all the other files at that link have been redirected as well.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   217
            checkOutput(Output.OUT, true,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   218
                    "javadoc: warning - URL " + oldURL + "/element-list was redirected to " + newURL + "/element-list");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   219
            checkOutput("mC/p5/C5.html", true,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   220
                    "extends <a href=\"" + oldURL + "/mA/p1/C1.html?is-external=true\" " +
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   221
                            "title=\"class or interface in p1\" class=\"externalLink\">C1</a>");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   222
            checkOutput("mC/p6/C6.html", true,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   223
                    "<a href=\"" + oldURL + "/mB/p4/C4.html?is-external=true\" " +
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   224
                            "title=\"class or interface in p4\" class=\"externalLink\">C4</a>");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   225
        } finally {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   226
            if (oldServer != null) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   227
                out.println("Stopping old server on " + oldServer.getAddress());
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   228
                oldServer.stop(0);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   229
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   230
            if (newServer != null) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   231
                out.println("Stopping new server on " + newServer.getAddress());
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   232
                newServer.stop(0);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   233
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   234
        }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   235
    }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   236
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   237
    private void handleOldRequest(HttpExchange x) throws IOException {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   238
        out.println("old request: "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   239
                + x.getProtocol() + " "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   240
                + x.getRequestMethod() + " "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   241
                + x.getRequestURI());
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   242
        String newProtocol = (newServer instanceof HttpsServer) ? "https" : "http";
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   243
        String redirectTo = newProtocol + ":/" + newServer.getAddress() + x.getRequestURI();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   244
        out.println("    redirect to: " + redirectTo);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   245
        x.getResponseHeaders().add("Location", redirectTo);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   246
        x.sendResponseHeaders(HttpURLConnection.HTTP_MOVED_PERM, 0);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   247
        x.getResponseBody().close();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   248
    }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   249
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   250
    private void handleNewRequest(HttpExchange x) throws IOException {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   251
        out.println("new request: "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   252
                + x.getProtocol() + " "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   253
                + x.getRequestMethod() + " "
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   254
                + x.getRequestURI());
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   255
        Path file = libApi.resolve(x.getRequestURI().getPath().substring(1).replace('/', File.separatorChar));
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   256
        System.err.println(file);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   257
        if (Files.exists(file)) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   258
            byte[] bytes = Files.readAllBytes(file);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   259
            // in the context of this test, the only request should be element-list,
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   260
            // which we can say is text/plain.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   261
            x.getResponseHeaders().add("Content-type", "text/plain");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   262
            x.sendResponseHeaders(HttpURLConnection.HTTP_OK, bytes.length);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   263
            try (OutputStream responseStream = x.getResponseBody()) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   264
                responseStream.write(bytes);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   265
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   266
        } else {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   267
            x.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, 0);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   268
            x.getResponseBody().close();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   269
        }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   270
    }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   271
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   272
    /**
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   273
     * Creates a simple usable SSLContext for an HttpsServer using
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   274
     * a default keystore in the test tree.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   275
     * <p>
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   276
     * This class is based on
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   277
     * test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SimpleSSLContext.java
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   278
     */
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   279
    static class SimpleSSLContext {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   280
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   281
        private final SSLContext ssl;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   282
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   283
        /**
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   284
         * Loads default keystore.
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   285
         */
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   286
        SimpleSSLContext() throws Exception {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   287
            Path p = Path.of(System.getProperty("test.src", ".")).toAbsolutePath();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   288
            while (!Files.exists(p.resolve("TEST.ROOT"))) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   289
                p = p.getParent();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   290
                if (p == null) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   291
                    throw new IOException("can't find TEST.ROOT");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   292
                }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   293
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   294
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   295
            System.err.println("Test suite root: " + p);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   296
            Path testKeys = p.resolve("../lib/jdk/test/lib/net/testkeys").normalize();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   297
            if (!Files.exists(testKeys)) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   298
                throw new IOException("can't find testkeys");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   299
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   300
            System.err.println("Test keys: " + testKeys);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   301
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   302
            try (InputStream fis = Files.newInputStream(testKeys)) {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   303
                ssl = init(fis);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   304
            }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   305
        }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   306
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   307
        private SSLContext init(InputStream i) throws Exception {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   308
            char[] passphrase = "passphrase".toCharArray();
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   309
            KeyStore ks = KeyStore.getInstance("PKCS12");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   310
            ks.load(i, passphrase);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   311
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   312
            KeyManagerFactory kmf = KeyManagerFactory.getInstance("PKIX");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   313
            kmf.init(ks, passphrase);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   314
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   315
            TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   316
            tmf.init(ks);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   317
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   318
            SSLContext ssl = SSLContext.getInstance("TLS");
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   319
            ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   320
            return ssl;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   321
        }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   322
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   323
        SSLContext get() {
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   324
            return ssl;
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   325
        }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   326
    }
526f5cf13972 8190312: javadoc -link doesn't work with http: -> https: URL redirects
jjg
parents:
diff changeset
   327
}