test/jdk/java/net/httpclient/ShortResponseBody.java
author jboes
Fri, 08 Nov 2019 11:15:16 +0000
changeset 59029 3786a0962570
parent 58968 7f1daafda27b
permissions -rw-r--r--
8232853: AuthenticationFilter.Cache::remove may throw ConcurrentModificationException Summary: Change implementation to use iterator instead of plain LinkedList Reviewed-by: dfuchs, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     1
/*
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     4
 *
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     8
 *
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    13
 * accompanied this code).
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    14
 *
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    18
 *
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    21
 * questions.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    22
 */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    23
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    24
/*
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    25
 * @test
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
    26
 * @bug 8216498
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    27
 * @summary Tests Exception detail message when too few response bytes are
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    28
 *          received before a socket exception or eof.
52121
934969c63223 8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents: 50985
diff changeset
    29
 * @library /test/lib
934969c63223 8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents: 50985
diff changeset
    30
 * @build jdk.test.lib.net.SimpleSSLContext
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    31
 * @run testng/othervm
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    32
 *       -Djdk.httpclient.HttpClient.log=headers,errors,channel
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    33
 *       ShortResponseBody
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    34
 */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    35
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    36
import java.io.IOException;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    37
import java.io.InputStream;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    38
import java.io.OutputStream;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    39
import java.io.UncheckedIOException;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    40
import java.net.InetAddress;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    41
import java.net.InetSocketAddress;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    42
import java.net.ServerSocket;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    43
import java.net.Socket;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    44
import java.net.URI;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    45
import java.net.http.HttpClient;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    46
import java.net.http.HttpRequest;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    47
import java.net.http.HttpRequest.BodyPublishers;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    48
import java.net.http.HttpResponse;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    49
import java.util.ArrayList;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    50
import java.util.Arrays;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    51
import java.util.List;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    52
import java.util.concurrent.ExecutionException;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    53
import java.util.concurrent.Executor;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    54
import java.util.concurrent.ExecutorService;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    55
import java.util.concurrent.Executors;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    56
import java.util.concurrent.ThreadFactory;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    57
import java.util.concurrent.atomic.AtomicLong;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    58
import java.util.stream.Stream;
52121
934969c63223 8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents: 50985
diff changeset
    59
import jdk.test.lib.net.SimpleSSLContext;
58968
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
    60
import org.testng.ITestContext;
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
    61
import org.testng.annotations.BeforeMethod;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    62
import org.testng.annotations.AfterTest;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    63
import org.testng.annotations.BeforeTest;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    64
import org.testng.annotations.DataProvider;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    65
import org.testng.annotations.Test;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    66
import javax.net.ssl.SSLContext;
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
    67
import javax.net.ssl.SSLHandshakeException;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    68
import javax.net.ssl.SSLServerSocketFactory;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    69
import javax.net.ssl.SSLParameters;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    70
import javax.net.ssl.SSLSocket;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    71
import static java.lang.System.out;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    72
import static java.net.http.HttpClient.Builder.NO_PROXY;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    73
import static java.net.http.HttpResponse.BodyHandlers.ofString;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    74
import static java.nio.charset.StandardCharsets.US_ASCII;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    75
import static java.util.stream.Collectors.toList;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    76
import static org.testng.Assert.assertTrue;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    77
import static org.testng.Assert.assertEquals;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    78
import static org.testng.Assert.fail;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    79
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    80
public class ShortResponseBody {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    81
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    82
    Server closeImmediatelyServer;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    83
    Server closeImmediatelyHttpsServer;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    84
    Server variableLengthServer;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    85
    Server variableLengthHttpsServer;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    86
    Server fixedLengthServer;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    87
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    88
    String httpURIClsImed;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    89
    String httpsURIClsImed;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    90
    String httpURIVarLen;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    91
    String httpsURIVarLen;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    92
    String httpURIFixLen;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    93
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    94
    SSLContext sslContext;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    95
    SSLParameters sslParameters;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    96
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    97
    static final String EXPECTED_RESPONSE_BODY =
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    98
            "<html><body><h1>Heading</h1><p>Some Text</p></body></html>";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
    99
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   100
    final static AtomicLong ids = new AtomicLong();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   101
    final ThreadFactory factory = new ThreadFactory() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   102
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   103
        public Thread newThread(Runnable r) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   104
            Thread thread = new Thread(r,  "HttpClient-Worker-" + ids.incrementAndGet());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   105
            thread.setDaemon(true);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   106
            return thread;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   107
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   108
    };
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   109
    final ExecutorService service = Executors.newCachedThreadPool(factory);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   110
58968
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   111
    @BeforeMethod
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   112
    void beforeMethod(ITestContext context) {
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   113
        if (context.getFailedTests().size() > 0) {
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   114
            throw new RuntimeException("some tests failed");
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   115
        }
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   116
    }
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   117
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   118
    @DataProvider(name = "sanity")
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   119
    public Object[][] sanity() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   120
        return new Object[][]{
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   121
            { httpURIVarLen  + "?length=all" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   122
            { httpsURIVarLen + "?length=all" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   123
            { httpURIFixLen  + "?length=all" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   124
        };
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   125
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   126
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   127
    @Test(dataProvider = "sanity")
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   128
    void sanity(String url) throws Exception {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   129
        HttpClient client = newHttpClient();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   130
        HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   131
        HttpResponse<String> response = client.send(request, ofString());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   132
        String body = response.body();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   133
        assertEquals(body, EXPECTED_RESPONSE_BODY);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   134
        client.sendAsync(request, ofString())
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   135
                .thenApply(resp -> resp.body())
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   136
                .thenAccept(b -> assertEquals(b, EXPECTED_RESPONSE_BODY))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   137
                .join();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   138
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   139
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   140
    @DataProvider(name = "uris")
58968
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   141
    public Object[][] variants(ITestContext context) {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   142
        String[][] cases = new String[][] {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   143
            // The length query string is the total number of bytes in the reply,
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   144
            // including headers, before the server closes the connection. The
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   145
            // second arg is a partial-expected-detail message in the exception.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   146
            { httpURIVarLen + "?length=0",   "no bytes"     }, // EOF without receiving anything
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   147
            { httpURIVarLen + "?length=1",   "status line"  }, // EOF during status-line
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   148
            { httpURIVarLen + "?length=2",   "status line"  },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   149
            { httpURIVarLen + "?length=10",  "status line"  },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   150
            { httpURIVarLen + "?length=19",  "header"       }, // EOF during Content-Type header
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   151
            { httpURIVarLen + "?length=30",  "header"       },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   152
            { httpURIVarLen + "?length=45",  "header"       },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   153
            { httpURIVarLen + "?length=48",  "header"       },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   154
            { httpURIVarLen + "?length=51",  "header"       },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   155
            { httpURIVarLen + "?length=98",  "header"       }, // EOF during Connection header
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   156
            { httpURIVarLen + "?length=100", "header"       },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   157
            { httpURIVarLen + "?length=101", "header"       },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   158
            { httpURIVarLen + "?length=104", "header"       },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   159
            { httpURIVarLen + "?length=106", "chunked transfer encoding" }, // EOF during chunk header ( length )
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   160
            { httpURIVarLen + "?length=110", "chunked transfer encoding" }, // EOF during chunk response body data
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   161
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   162
            { httpsURIVarLen + "?length=0",   "no bytes"    },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   163
            { httpsURIVarLen + "?length=1",   "status line" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   164
            { httpsURIVarLen + "?length=2",   "status line" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   165
            { httpsURIVarLen + "?length=10",  "status line" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   166
            { httpsURIVarLen + "?length=19",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   167
            { httpsURIVarLen + "?length=30",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   168
            { httpsURIVarLen + "?length=45",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   169
            { httpsURIVarLen + "?length=48",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   170
            { httpsURIVarLen + "?length=51",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   171
            { httpsURIVarLen + "?length=98",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   172
            { httpsURIVarLen + "?length=100", "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   173
            { httpsURIVarLen + "?length=101", "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   174
            { httpsURIVarLen + "?length=104", "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   175
            { httpsURIVarLen + "?length=106", "chunked transfer encoding" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   176
            { httpsURIVarLen + "?length=110", "chunked transfer encoding" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   177
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   178
            { httpURIFixLen + "?length=0",   "no bytes"    }, // EOF without receiving anything
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   179
            { httpURIFixLen + "?length=1",   "status line" }, // EOF during status-line
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   180
            { httpURIFixLen + "?length=2",   "status line" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   181
            { httpURIFixLen + "?length=10",  "status line" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   182
            { httpURIFixLen + "?length=19",  "header"      }, // EOF during Content-Type header
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   183
            { httpURIFixLen + "?length=30",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   184
            { httpURIFixLen + "?length=45",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   185
            { httpURIFixLen + "?length=48",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   186
            { httpURIFixLen + "?length=51",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   187
            { httpURIFixLen + "?length=78",  "header"      }, // EOF during Connection header
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   188
            { httpURIFixLen + "?length=79",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   189
            { httpURIFixLen + "?length=86",  "header"      },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   190
            { httpURIFixLen + "?length=104", "fixed content-length" }, // EOF during body
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   191
            { httpURIFixLen + "?length=106", "fixed content-length" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   192
            { httpURIFixLen + "?length=110", "fixed content-length" },
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   193
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   194
            // ## ADD https fixed
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   195
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   196
            { httpURIClsImed,  "no bytes"},
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   197
            { httpsURIClsImed, "no bytes"},
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   198
        };
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   199
58968
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   200
        if (context.getFailedTests().size() > 0) {
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   201
            // Shorten the log output by preventing useless
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   202
            // skip traces to be printed for subsequent methods
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   203
            // if one of the previous @Test method has failed.
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   204
            return new Object[0][];
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   205
        }
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   206
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   207
        List<Object[]> list = new ArrayList<>();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   208
        Arrays.asList(cases).stream()
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   209
                .map(e -> new Object[] {e[0], e[1], true})  // reuse client
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   210
                .forEach(list::add);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   211
        Arrays.asList(cases).stream()
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   212
                .map(e -> new Object[] {e[0], e[1], false}) // do not reuse client
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   213
                .forEach(list::add);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   214
        return list.stream().toArray(Object[][]::new);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   215
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   216
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   217
    static final int ITERATION_COUNT = 3;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   218
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   219
    HttpClient newHttpClient() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   220
        return HttpClient.newBuilder()
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   221
                .proxy(NO_PROXY)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   222
                .sslContext(sslContext)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   223
                .sslParameters(sslParameters)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   224
                .executor(service)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   225
                .build();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   226
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   227
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   228
    @Test(dataProvider = "uris")
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   229
    void testSynchronousGET(String url, String expectedMsg, boolean sameClient)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   230
        throws Exception
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   231
    {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   232
        out.print("---\n");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   233
        HttpClient client = null;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   234
        for (int i=0; i< ITERATION_COUNT; i++) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   235
            if (!sameClient || client == null)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   236
                client = newHttpClient();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   237
            HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   238
            try {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   239
                HttpResponse<String> response = client.send(request, ofString());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   240
                String body = response.body();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   241
                out.println(response + ": " + body);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   242
                fail("UNEXPECTED RESPONSE: " + response);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   243
            } catch (IOException ioe) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   244
                out.println("Caught expected exception:" + ioe);
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   245
                assertExpectedMessage(request, ioe, expectedMsg);
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   246
                // synchronous API must have the send method on the stack
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   247
                assertSendMethodOnStack(ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   248
                assertNoConnectionExpiredException(ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   249
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   250
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   251
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   252
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   253
    @Test(dataProvider = "uris")
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   254
    void testAsynchronousGET(String url, String expectedMsg, boolean sameClient)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   255
        throws Exception
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   256
    {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   257
        out.print("---\n");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   258
        HttpClient client = null;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   259
        for (int i=0; i< ITERATION_COUNT; i++) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   260
            if (!sameClient || client == null)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   261
                client = newHttpClient();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   262
            HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   263
            try {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   264
                HttpResponse<String> response = client.sendAsync(request, ofString()).get();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   265
                String body = response.body();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   266
                out.println(response + ": " + body);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   267
                fail("UNEXPECTED RESPONSE: " + response);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   268
            } catch (ExecutionException ee) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   269
                if (ee.getCause() instanceof IOException) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   270
                    IOException ioe = (IOException) ee.getCause();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   271
                    out.println("Caught expected exception:" + ioe);
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   272
                    assertExpectedMessage(request, ioe, expectedMsg);
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   273
                    assertNoConnectionExpiredException(ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   274
                } else {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   275
                    throw ee;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   276
                }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   277
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   278
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   279
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   280
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   281
    // can be used to prolong request body publication
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   282
    static final class InfiniteInputStream extends InputStream {
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   283
        int count = 0;
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   284
        int k16 = 0;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   285
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   286
        public int read() throws IOException {
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   287
            if (++count == 1) {
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   288
                System.out.println("Start sending 1 byte");
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   289
            }
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   290
            if (count > 16 * 1024) {
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   291
                k16++;
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   292
                System.out.println("... 16K sent.");
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   293
                count = count % (16 * 1024);
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   294
            }
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   295
            if (k16 > 128) {
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   296
                System.out.println("WARNING: InfiniteInputStream: " +
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   297
                        "more than 128 16k buffers generated: returning EOF");
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   298
                return -1;
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   299
            }
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   300
            return 1;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   301
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   302
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   303
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   304
        public int read(byte[] buf, int offset, int length) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   305
            //int count = offset;
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   306
            length = Math.max(0, Math.min(buf.length - offset, length));
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   307
            //for (; count < length; count++)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   308
            //    buf[offset++] = 0x01;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   309
            //return count;
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   310
            if (count == 0) {
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   311
                System.out.println("Start sending " + length);
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   312
            } else if (count > 16 * 1024) {
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   313
                k16++;
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   314
                System.out.println("... 16K sent.");
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   315
                count = count % (16 * 1024);
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   316
            }
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   317
            if (k16 > 128) {
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   318
                System.out.println("WARNING: InfiniteInputStream: " +
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   319
                        "more than 128 16k buffers generated: returning EOF");
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   320
                return -1;
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   321
            }
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   322
            count += length;
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   323
            return length;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   324
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   325
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   326
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   327
    // POST tests are racy in what may be received before writing may cause a
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   328
    // broken pipe or reset exception, before all the received data can be read.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   329
    // Any message up to, and including, the "expected" error message can occur.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   330
    // Strictly ordered list, in order of possible occurrence.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   331
    static final List<String> MSGS_ORDER =
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   332
            List.of("no bytes", "status line", "header");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   333
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   334
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   335
    @Test(dataProvider = "uris")
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   336
    void testSynchronousPOST(String url, String expectedMsg, boolean sameClient)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   337
        throws Exception
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   338
    {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   339
        out.print("---\n");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   340
        HttpClient client = null;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   341
        for (int i=0; i< ITERATION_COUNT; i++) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   342
            if (!sameClient || client == null)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   343
                client = newHttpClient();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   344
            HttpRequest request = HttpRequest.newBuilder(URI.create(url))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   345
                    .POST(BodyPublishers.ofInputStream(() -> new InfiniteInputStream()))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   346
                    .build();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   347
            try {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   348
                HttpResponse<String> response = client.send(request, ofString());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   349
                String body = response.body();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   350
                out.println(response + ": " + body);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   351
                fail("UNEXPECTED RESPONSE: " + response);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   352
            } catch (IOException ioe) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   353
                out.println("Caught expected exception:" + ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   354
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   355
                List<String> expectedMessages = new ArrayList<>();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   356
                expectedMessages.add(expectedMsg);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   357
                MSGS_ORDER.stream().takeWhile(s -> !s.equals(expectedMsg))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   358
                                   .forEach(expectedMessages::add);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   359
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   360
                assertExpectedMessage(request, ioe, expectedMessages);
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   361
                // synchronous API must have the send method on the stack
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   362
                assertSendMethodOnStack(ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   363
                assertNoConnectionExpiredException(ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   364
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   365
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   366
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   367
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   368
    @Test(dataProvider = "uris")
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   369
    void testAsynchronousPOST(String url, String expectedMsg, boolean sameClient)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   370
        throws Exception
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   371
    {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   372
        out.print("---\n");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   373
        HttpClient client = null;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   374
        for (int i=0; i< ITERATION_COUNT; i++) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   375
            if (!sameClient || client == null)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   376
                client = newHttpClient();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   377
            HttpRequest request = HttpRequest.newBuilder(URI.create(url))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   378
                    .POST(BodyPublishers.ofInputStream(() -> new InfiniteInputStream()))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   379
                    .build();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   380
            try {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   381
                HttpResponse<String> response = client.sendAsync(request, ofString()).get();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   382
                String body = response.body();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   383
                out.println(response + ": " + body);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   384
                fail("UNEXPECTED RESPONSE: " + response);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   385
            } catch (ExecutionException ee) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   386
                if (ee.getCause() instanceof IOException) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   387
                    IOException ioe = (IOException) ee.getCause();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   388
                    out.println("Caught expected exception:" + ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   389
                    String msg = ioe.getMessage();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   390
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   391
                    List<String> expectedMessages = new ArrayList<>();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   392
                    expectedMessages.add(expectedMsg);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   393
                    MSGS_ORDER.stream().takeWhile(s -> !s.equals(expectedMsg))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   394
                            .forEach(expectedMessages::add);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   395
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   396
                    assertExpectedMessage(request, ioe, expectedMessages);
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   397
                    assertNoConnectionExpiredException(ioe);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   398
                } else {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   399
                    throw ee;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   400
                }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   401
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   402
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   403
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   404
53256
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   405
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   406
    void assertExpectedMessage(HttpRequest request, Throwable t, String expected) {
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   407
        if (request.uri().getScheme().equalsIgnoreCase("https")
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   408
                && (t instanceof SSLHandshakeException)) {
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   409
            // OK
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   410
            out.println("Skipping expected " + t);
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   411
        } else {
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   412
            String msg = t.getMessage();
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   413
            assertTrue(msg.contains(expected),
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   414
                    "exception msg:[" + msg + "]");
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   415
        }
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   416
    }
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   417
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   418
    void assertExpectedMessage(HttpRequest request, Throwable t, List<String> expected) {
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   419
        if (request.uri().getScheme().equalsIgnoreCase("https")
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   420
                && (t instanceof SSLHandshakeException)) {
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   421
            // OK
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   422
            out.println("Skipping expected " + t);
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   423
        } else {
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   424
            String msg = t.getMessage();
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   425
            assertTrue(expected.stream().anyMatch(msg::contains),
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   426
                    "exception msg:[" + msg + "] not in " + Arrays.asList(expected));
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   427
        }
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   428
    }
bd8df96decba 8216498: Confusing and unneeded wrapping of SSLHandshakeException
dfuchs
parents: 52121
diff changeset
   429
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   430
    // Asserts that the "send" method appears in the stack of the given
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   431
    // exception. The synchronous API must contain the send method on the stack.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   432
    static void assertSendMethodOnStack(IOException ioe) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   433
        final String cn = "jdk.internal.net.http.HttpClientImpl";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   434
        List<StackTraceElement> list = Stream.of(ioe.getStackTrace())
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   435
                .filter(ste -> ste.getClassName().equals(cn)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   436
                        && ste.getMethodName().equals("send"))
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   437
                .collect(toList());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   438
        if (list.size() != 1) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   439
            ioe.printStackTrace(out);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   440
            fail(cn + ".send method not found in stack.");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   441
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   442
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   443
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   444
    // Asserts that the implementation-specific ConnectionExpiredException does
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   445
    // NOT appear anywhere in the exception or its causal chain.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   446
    static void assertNoConnectionExpiredException(IOException ioe) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   447
        Throwable throwable = ioe;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   448
        do {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   449
            String cn = throwable.getClass().getSimpleName();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   450
            if (cn.equals("ConnectionExpiredException")) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   451
                ioe.printStackTrace(out);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   452
                fail("UNEXPECTED ConnectionExpiredException in:[" + ioe + "]");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   453
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   454
        } while ((throwable = throwable.getCause()) != null);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   455
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   456
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   457
    // -- infra
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   458
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   459
    /**
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   460
     * A server that, listens on a port, accepts new connections, and can be
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   461
     * closed.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   462
     */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   463
    static abstract class Server extends Thread implements AutoCloseable {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   464
        protected final ServerSocket ss;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   465
        protected volatile boolean closed;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   466
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   467
        Server(String name) throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   468
            super(name);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   469
            ss = newServerSocket();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   470
            ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   471
            this.start();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   472
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   473
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   474
        protected ServerSocket newServerSocket() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   475
            return new ServerSocket();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   476
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   477
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   478
        public int getPort() { return ss.getLocalPort(); }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   479
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   480
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   481
        public void close() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   482
            if (closed)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   483
                return;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   484
            closed = true;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   485
            try {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   486
                ss.close();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   487
            } catch (IOException e) {
58968
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   488
                out.println("Unexpected exception while closing server: " + e);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   489
                e.printStackTrace(out);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   490
                throw new UncheckedIOException("Unexpected: ", e);
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   491
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   492
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   493
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   494
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   495
    /**
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   496
     * A server that closes the connection immediately, without reading or writing.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   497
     */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   498
    static class PlainCloseImmediatelyServer extends Server {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   499
        PlainCloseImmediatelyServer() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   500
            super("PlainCloseImmediatelyServer");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   501
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   502
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   503
        protected PlainCloseImmediatelyServer(String name) throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   504
            super(name);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   505
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   506
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   507
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   508
        public void run() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   509
            while (!closed) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   510
                try (Socket s = ss.accept()) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   511
                    if (s instanceof SSLSocket) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   512
                        ((SSLSocket)s).startHandshake();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   513
                    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   514
                    out.println("Server: got connection, closing immediately ");
58968
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   515
                } catch (Throwable e) {
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   516
                    if (!closed) {
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   517
                        out.println("Unexpected exception in server: " + e);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   518
                        e.printStackTrace(out);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   519
                        throw new RuntimeException("Unexpected: ", e);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   520
                    }
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   521
                }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   522
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   523
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   524
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   525
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   526
    /**
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   527
     * A server that closes the connection immediately, without reading or writing,
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   528
     * after completing the SSL handshake.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   529
     */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   530
    static final class SSLCloseImmediatelyServer extends PlainCloseImmediatelyServer {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   531
        SSLCloseImmediatelyServer() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   532
            super("SSLCloseImmediatelyServer");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   533
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   534
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   535
        public ServerSocket newServerSocket() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   536
            return SSLServerSocketFactory.getDefault().createServerSocket();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   537
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   538
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   539
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   540
    /**
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   541
     * A server that replies with headers and a, possibly partial, reply, before
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   542
     * closing the connection. The number of bytes of written ( header + body),
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   543
     * is controllable through the "length" query string param in the requested
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   544
     * URI.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   545
     */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   546
    static abstract class ReplyingServer extends Server {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   547
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   548
        private final String name;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   549
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   550
        ReplyingServer(String name) throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   551
            super(name);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   552
            this.name = name;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   553
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   554
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   555
        abstract String response();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   556
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   557
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   558
        public void run() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   559
            while (!closed) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   560
                try (Socket s = ss.accept()) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   561
                    out.print(name + ": got connection ");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   562
                    InputStream is = s.getInputStream();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   563
                    URI requestMethod = readRequestMethod(is);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   564
                    out.print(requestMethod + " ");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   565
                    URI uriPath = readRequestPath(is);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   566
                    out.println(uriPath);
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   567
                    String headers = readRequestHeaders(is);
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   568
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   569
                    String query = uriPath.getRawQuery();
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   570
                    if (query == null) {
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   571
                        out.println("Request headers: [" + headers + "]");
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   572
                    }
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   573
                    assert query != null : "null query for uriPath: " + uriPath;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   574
                    String qv = query.split("=")[1];
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   575
                    int len;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   576
                    if (qv.equals("all")) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   577
                        len = response().getBytes(US_ASCII).length;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   578
                    } else {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   579
                        len = Integer.parseInt(query.split("=")[1]);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   580
                    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   581
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   582
                    OutputStream os = s.getOutputStream();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   583
                    out.println(name + ": writing " + len  + " bytes");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   584
                    byte[] responseBytes = response().getBytes(US_ASCII);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   585
                    for (int i = 0; i< len; i++) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   586
                        os.write(responseBytes[i]);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   587
                        os.flush();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   588
                    }
58968
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   589
                } catch (Throwable e) {
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   590
                    if (!closed) {
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   591
                        out.println("Unexpected exception in server: " + e);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   592
                        e.printStackTrace(out);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   593
                        throw new RuntimeException("Unexpected: " + e, e);
7f1daafda27b 8233403: Improve verbosity of some httpclient tests
dfuchs
parents: 53256
diff changeset
   594
                    }
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   595
                }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   596
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   597
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   598
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   599
        static final byte[] requestEnd = new byte[] { '\r', '\n', '\r', '\n' };
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   600
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   601
        // Read the request method
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   602
        static URI readRequestMethod(InputStream is) throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   603
            StringBuilder sb = new StringBuilder();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   604
            int r;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   605
            while ((r = is.read()) != -1 && r != 0x20) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   606
                sb.append((char)r);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   607
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   608
            return URI.create(sb.toString());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   609
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   610
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   611
        // Read the request URI path
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   612
        static URI readRequestPath(InputStream is) throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   613
            StringBuilder sb = new StringBuilder();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   614
            int r;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   615
            while ((r = is.read()) != -1 && r != 0x20) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   616
                sb.append((char)r);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   617
            }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   618
            return URI.create(sb.toString());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   619
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   620
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   621
        // Read until the end of a HTTP request headers
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   622
        static String readRequestHeaders(InputStream is) throws IOException {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   623
            int requestEndCount = 0, r;
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   624
            StringBuilder sb = new StringBuilder();
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   625
            while ((r = is.read()) != -1) {
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   626
                sb.append((char) r);
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   627
                if (r == requestEnd[requestEndCount]) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   628
                    requestEndCount++;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   629
                    if (requestEndCount == 4) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   630
                        break;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   631
                    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   632
                } else {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   633
                    requestEndCount = 0;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   634
                }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   635
            }
50985
cd41f34e548c 8206001: Enable TLS1.3 by default in Http Client
michaelm
parents: 50681
diff changeset
   636
            return sb.toString();
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   637
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   638
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   639
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   640
    /** A server that issues a, possibly-partial, chunked reply. */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   641
    static class PlainVariableLengthServer extends ReplyingServer {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   642
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   643
        static final String CHUNKED_RESPONSE_BODY =
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   644
                "6\r\n"+ "<html>\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   645
                "6\r\n"+ "<body>\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   646
                "10\r\n"+ "<h1>Heading</h1>\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   647
                "10\r\n"+ "<p>Some Text</p>\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   648
                "7\r\n"+ "</body>\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   649
                "7\r\n"+ "</html>\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   650
                "0\r\n"+ "\r\n";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   651
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   652
        static final String RESPONSE_HEADERS =
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   653
                "HTTP/1.1 200 OK\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   654
                "Content-Type: text/html; charset=utf-8\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   655
                "Transfer-Encoding: chunked\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   656
                "Connection: close\r\n\r\n";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   657
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   658
        static final String RESPONSE = RESPONSE_HEADERS + CHUNKED_RESPONSE_BODY;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   659
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   660
        PlainVariableLengthServer() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   661
            super("PlainVariableLengthServer");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   662
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   663
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   664
        protected PlainVariableLengthServer(String name) throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   665
            super(name);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   666
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   667
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   668
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   669
        String response( ) { return RESPONSE; }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   670
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   671
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   672
    /** A server that issues a, possibly-partial, chunked reply over SSL. */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   673
    static final class SSLVariableLengthServer extends PlainVariableLengthServer {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   674
        SSLVariableLengthServer() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   675
            super("SSLVariableLengthServer");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   676
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   677
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   678
        public ServerSocket newServerSocket() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   679
            return SSLServerSocketFactory.getDefault().createServerSocket();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   680
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   681
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   682
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   683
    /** A server that issues a fixed-length reply. */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   684
    static final class FixedLengthServer extends ReplyingServer {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   685
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   686
        static final String RESPONSE_BODY = EXPECTED_RESPONSE_BODY;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   687
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   688
        static final String RESPONSE_HEADERS =
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   689
                "HTTP/1.1 200 OK\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   690
                "Content-Type: text/html; charset=utf-8\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   691
                "Content-Length: " + RESPONSE_BODY.length() + "\r\n" +
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   692
                "Connection: close\r\n\r\n";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   693
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   694
        static final String RESPONSE = RESPONSE_HEADERS + RESPONSE_BODY;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   695
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   696
        FixedLengthServer() throws IOException {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   697
            super("FixedLengthServer");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   698
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   699
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   700
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   701
        String response( ) { return RESPONSE; }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   702
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   703
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   704
    static String serverAuthority(Server server) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   705
        return InetAddress.getLoopbackAddress().getHostName() + ":"
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   706
                + server.getPort();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   707
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   708
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   709
    @BeforeTest
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   710
    public void setup() throws Exception {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   711
        sslContext = new SimpleSSLContext().get();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   712
        if (sslContext == null)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   713
            throw new AssertionError("Unexpected null sslContext");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   714
        SSLContext.setDefault(sslContext);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   715
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   716
        sslParameters = new SSLParameters();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   717
        sslParameters.setProtocols(new String[] {"TLSv1.2"});
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   718
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   719
        closeImmediatelyServer = new PlainCloseImmediatelyServer();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   720
        httpURIClsImed = "http://" + serverAuthority(closeImmediatelyServer)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   721
                + "/http1/closeImmediately/foo";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   722
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   723
        closeImmediatelyHttpsServer = new SSLCloseImmediatelyServer();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   724
        httpsURIClsImed = "https://" + serverAuthority(closeImmediatelyHttpsServer)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   725
                + "/https1/closeImmediately/foo";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   726
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   727
        variableLengthServer = new PlainVariableLengthServer();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   728
        httpURIVarLen = "http://" + serverAuthority(variableLengthServer)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   729
                + "/http1/variable/bar";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   730
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   731
        variableLengthHttpsServer = new SSLVariableLengthServer();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   732
        httpsURIVarLen = "https://" + serverAuthority(variableLengthHttpsServer)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   733
                + "/https1/variable/bar";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   734
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   735
        fixedLengthServer = new FixedLengthServer();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   736
        httpURIFixLen = "http://" + serverAuthority(fixedLengthServer)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   737
                + "/http1/fixed/baz";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   738
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   739
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   740
    @AfterTest
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   741
    public void teardown() throws Exception {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   742
        closeImmediatelyServer.close();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   743
        closeImmediatelyHttpsServer.close();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   744
        variableLengthServer.close();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   745
        variableLengthHttpsServer.close();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   746
        fixedLengthServer.close();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   747
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents:
diff changeset
   748
}