test/jdk/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java
author dfuchs
Wed, 04 Sep 2019 18:10:07 +0100
changeset 58009 0daf32316b47
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230435: Replace wildcard address with loopback or local host in tests - part 22 Summary: fixes tests to use the loopback address whenever possible. It also fixes some safe publishing issues, or add diagnostics in some of the tests. Reviewed-by: michaelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58009
0daf32316b47 8230435: Replace wildcard address with loopback or local host in tests - part 22
dfuchs
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1949
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1949
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1949
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
34522
fa15f1bdaec2 8144890: Add the intermittent keyword test B6216082.java
xuelei
parents: 30820
diff changeset
    24
//
fa15f1bdaec2 8144890: Add the intermittent keyword test B6216082.java
xuelei
parents: 30820
diff changeset
    25
// SunJSSE does not support dynamic system properties, no way to re-use
fa15f1bdaec2 8144890: Add the intermittent keyword test B6216082.java
xuelei
parents: 30820
diff changeset
    26
// system properties in samevm/agentvm mode.
fa15f1bdaec2 8144890: Add the intermittent keyword test B6216082.java
xuelei
parents: 30820
diff changeset
    27
//
fa15f1bdaec2 8144890: Add the intermittent keyword test B6216082.java
xuelei
parents: 30820
diff changeset
    28
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @bug 6216082
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    32
 * @summary  Redirect problem with HttpsURLConnection using a proxy
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23052
diff changeset
    33
 * @modules java.base/sun.net.www
45186
387a39577f09 8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents: 44671
diff changeset
    34
 * @library .. /test/lib
45467
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45186
diff changeset
    35
 * @build jdk.test.lib.NetworkConfiguration
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45186
diff changeset
    36
 *        jdk.test.lib.Platform
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45186
diff changeset
    37
 *        HttpCallback TestHttpsServer ClosedChannelList
45186
387a39577f09 8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents: 44671
diff changeset
    38
 *        HttpTransaction TunnelProxy
34522
fa15f1bdaec2 8144890: Add the intermittent keyword test B6216082.java
xuelei
parents: 30820
diff changeset
    39
 * @key intermittent
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    40
 * @run main/othervm B6216082
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    41
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
45186
387a39577f09 8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents: 44671
diff changeset
    48
import jdk.test.lib.NetworkConfiguration;
44671
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
    49
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class B6216082 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static SimpleHttpTransaction httpTrans;
13788
3f38e525f30a 6354758: rename old test HttpServer classes
chegar
parents: 13669
diff changeset
    52
    static TestHttpsServer server;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static TunnelProxy proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // it seems there's no proxy ever if a url points to 'localhost',
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // even if proxy related properties are set. so we need to bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // our simple http proxy and http server to a non-loopback address
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static InetAddress firstNonLoAddress = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static void main(String[] args) throws Exception {
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    61
        HostnameVerifier reservedHV =
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    62
            HttpsURLConnection.getDefaultHostnameVerifier();
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    63
        try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    64
            // XXX workaround for CNFE
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    65
            Class.forName("java.nio.channels.ClosedByInterruptException");
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    66
            if (!setupEnv()) {
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    67
                return;
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    68
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    70
            startHttpServer();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    72
            // https.proxyPort can only be set after the TunnelProxy has been
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    73
            // created as it will use an ephemeral port.
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    74
            System.setProperty("https.proxyPort",
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    75
                        (new Integer(proxy.getLocalPort())).toString() );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    77
            makeHttpCall();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    79
            if (httpTrans.hasBadRequest) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    80
                throw new RuntimeException("Test failed : bad http request");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    81
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    82
        } finally {
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    83
            if (proxy != null) {
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    84
                proxy.terminate();
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    85
            }
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    86
            if (server != null) {
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    87
               server.terminate();
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
    88
            }
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    89
            HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Where do we find the keystores for ssl?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
23052
241885315119 8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents: 13788
diff changeset
    96
    static String pathToStores = "../../../../../../javax/net/ssl/etc";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    static String passwd = "passphrase";
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   100
    public static boolean setupEnv() throws Exception {
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   101
        firstNonLoAddress = getNonLoAddress();
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   102
        if (firstNonLoAddress == null) {
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   103
            System.err.println("The test needs at least one non-loopback address to run. Quit now.");
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   104
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   106
        System.out.println(firstNonLoAddress.getHostAddress());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // will use proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        System.setProperty( "https.proxyHost", firstNonLoAddress.getHostAddress());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // setup properties to do ssl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        String keyFilename = System.getProperty("test.src", "./") + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                             pathToStores + "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        String trustFilename = System.getProperty("test.src", "./") + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                               pathToStores + "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   121
        return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static InetAddress getNonLoAddress() throws Exception {
44671
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   125
        InetAddress lh = InetAddress.getByName("localhost");
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   126
        NetworkInterface loNIC = NetworkInterface.getByInetAddress(lh);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
44671
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   128
        NetworkConfiguration nc = NetworkConfiguration.probe();
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   129
        Optional<InetAddress> oaddr = nc.interfaces()
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   130
                .filter(nif -> !nif.getName().equalsIgnoreCase(loNIC.getName()))
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   131
                .flatMap(nif -> nc.addresses(nif))
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   132
                .filter(a -> !a.isLoopbackAddress())
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   133
                .findFirst();
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   134
d1d011d4654d 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents: 34522
diff changeset
   135
        return oaddr.orElseGet(() -> null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   138
    public static void startHttpServer() throws IOException {
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   139
        // Both the https server and the proxy let the
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   140
        // system pick up an ephemeral port.
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   141
        httpTrans = new SimpleHttpTransaction();
58009
0daf32316b47 8230435: Replace wildcard address with loopback or local host in tests - part 22
dfuchs
parents: 47216
diff changeset
   142
        server = new TestHttpsServer(httpTrans, 1, 10, firstNonLoAddress, 0);
0daf32316b47 8230435: Replace wildcard address with loopback or local host in tests - part 22
dfuchs
parents: 47216
diff changeset
   143
        proxy = new TunnelProxy(1, 10, firstNonLoAddress, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   146
    public static void makeHttpCall() throws Exception {
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   147
        System.out.println("https server listen on: " + server.getLocalPort());
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   148
        System.out.println("https proxy listen on: " + proxy.getLocalPort());
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   149
        URL url = new URL("https" , firstNonLoAddress.getHostAddress(),
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   150
                            server.getLocalPort(), "/");
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   151
        HttpURLConnection uc = (HttpURLConnection)url.openConnection();
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   152
        System.out.println(uc.getResponseCode());
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   153
        uc.disconnect();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    static class NameVerifier implements HostnameVerifier {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        public boolean verify(String hostname, SSLSession session) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
class SimpleHttpTransaction implements HttpCallback {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public boolean hasBadRequest = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Our http server which simply redirect first call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public void request(HttpTransaction trans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            String path = trans.getRequestURI().getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (path.equals("/")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                // the first call, redirect it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                String location = "/redirect";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                trans.addResponseHeader("Location", location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                trans.sendResponse(302, "Moved Temporarily");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                // if the bug exsits, it'll send 2 GET commands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                // check 2nd GET here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                String duplicatedGet = trans.getRequestHeader(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (duplicatedGet != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    duplicatedGet.toUpperCase().indexOf("GET") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    trans.sendResponse(400, "Bad Request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    hasBadRequest = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    trans.sendResponse(200, "OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } catch (Exception e) {
13669
0f1340f8a157 7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents: 10328
diff changeset
   190
            throw new RuntimeException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
}