author | chegar |
Sat, 24 Feb 2018 11:27:11 +0000 | |
branch | http-client-branch |
changeset 56167 | 96fa4f49a9ff |
parent 56093 | 22d94c4a3641 |
child 56233 | 1753108d07b9 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
56093 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
4 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
18 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
21 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
23 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
24 |
/* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
* @test |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
26 |
* @bug 8156514 |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
* @library /lib/testlibrary server |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
28 |
* @build jdk.testlibrary.SimpleSSLContext |
48083 | 29 |
* @modules java.base/sun.net.www.http |
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
30 |
* java.net.http/jdk.internal.net.http.common |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
31 |
* java.net.http/jdk.internal.net.http.frame |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
32 |
* java.net.http/jdk.internal.net.http.hpack |
56093 | 33 |
* @run testng/othervm |
34 |
* -Djdk.httpclient.HttpClient.log=frames,ssl,requests,responses,errors |
|
35 |
* RedirectTest |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
36 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
38 |
import java.net.InetSocketAddress; |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
39 |
import java.net.URI; |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
40 |
import java.net.http.HttpClient; |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
41 |
import java.net.http.HttpRequest; |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
42 |
import java.net.http.HttpRequest.BodyPublishers; |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
43 |
import java.net.http.HttpResponse; |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
44 |
import java.net.http.HttpResponse.BodyHandlers; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
45 |
import java.util.concurrent.*; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
46 |
import java.util.function.*; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
47 |
import java.util.Arrays; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
48 |
import java.util.Iterator; |
48083 | 49 |
import org.testng.annotations.Test; |
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
50 |
import static java.net.http.HttpClient.Version.HTTP_2; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
51 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
52 |
public class RedirectTest { |
48083 | 53 |
static int httpPort; |
54 |
static Http2TestServer httpServer; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
55 |
static HttpClient client; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
56 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
57 |
static String httpURIString, altURIString1, altURIString2; |
48083 | 58 |
static URI httpURI, altURI1, altURI2; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
59 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
60 |
static Supplier<String> sup(String... args) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
61 |
Iterator<String> i = Arrays.asList(args).iterator(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
62 |
// need to know when to stop calling it. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
63 |
return () -> i.next(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
|
48083 | 66 |
static class Redirector extends Http2RedirectHandler { |
67 |
private InetSocketAddress remoteAddr; |
|
68 |
private boolean error = false; |
|
69 |
||
70 |
Redirector(Supplier<String> supplier) { |
|
71 |
super(supplier); |
|
72 |
} |
|
73 |
||
74 |
protected synchronized void examineExchange(Http2TestExchange ex) { |
|
75 |
InetSocketAddress addr = ex.getRemoteAddress(); |
|
76 |
if (remoteAddr == null) { |
|
77 |
remoteAddr = addr; |
|
78 |
return; |
|
79 |
} |
|
80 |
// check that the client addr/port stays the same, proving |
|
81 |
// that the connection didn't get dropped. |
|
82 |
if (!remoteAddr.equals(addr)) { |
|
83 |
System.err.printf("Error %s/%s\n", remoteAddr.toString(), |
|
84 |
addr.toString()); |
|
85 |
error = true; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
public synchronized boolean error() { |
|
90 |
return error; |
|
91 |
} |
|
92 |
} |
|
93 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
94 |
static void initialize() throws Exception { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
95 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
96 |
client = getClient(); |
48083 | 97 |
httpServer = new Http2TestServer(false, 0, null, null); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
98 |
httpPort = httpServer.getAddress().getPort(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
99 |
|
48083 | 100 |
// urls are accessed in sequence below. The first two are on |
101 |
// different servers. Third on same server as second. So, the |
|
102 |
// client should use the same http connection. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
103 |
httpURIString = "http://127.0.0.1:" + httpPort + "/foo/"; |
48083 | 104 |
httpURI = URI.create(httpURIString); |
105 |
altURIString1 = "http://127.0.0.1:" + httpPort + "/redir"; |
|
106 |
altURI1 = URI.create(altURIString1); |
|
107 |
altURIString2 = "http://127.0.0.1:" + httpPort + "/redir_again"; |
|
108 |
altURI2 = URI.create(altURIString2); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
|
48083 | 110 |
Redirector r = new Redirector(sup(altURIString1, altURIString2)); |
111 |
httpServer.addHandler(r, "/foo"); |
|
112 |
httpServer.addHandler(r, "/redir"); |
|
113 |
httpServer.addHandler(new Http2EchoHandler(), "/redir_again"); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
114 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
115 |
httpServer.start(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
116 |
} catch (Throwable e) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
117 |
System.err.println("Throwing now"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
118 |
e.printStackTrace(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
119 |
throw e; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
120 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
121 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
122 |
|
48083 | 123 |
@Test |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
124 |
public static void test() throws Exception { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
125 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
126 |
initialize(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
127 |
simpleTest(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
128 |
} finally { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
129 |
httpServer.stop(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
130 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
131 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
132 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
133 |
static HttpClient getClient() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
134 |
if (client == null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
135 |
client = HttpClient.newBuilder() |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
136 |
.followRedirects(HttpClient.Redirect.ALWAYS) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
137 |
.version(HTTP_2) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
138 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
139 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
140 |
return client; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
141 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
142 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
143 |
static URI getURI() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
144 |
return URI.create(httpURIString); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
145 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
146 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
147 |
static void checkStatus(int expected, int found) throws Exception { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
148 |
if (expected != found) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
149 |
System.err.printf ("Test failed: wrong status code %d/%d\n", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
150 |
expected, found); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
151 |
throw new RuntimeException("Test failed"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
152 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
153 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
154 |
|
48083 | 155 |
static void checkURIs(URI expected, URI found) throws Exception { |
156 |
System.out.printf ("Expected: %s, Found: %s\n", expected.toString(), found.toString()); |
|
157 |
if (!expected.equals(found)) { |
|
158 |
System.err.printf ("Test failed: wrong URI %s/%s\n", |
|
159 |
expected.toString(), found.toString()); |
|
160 |
throw new RuntimeException("Test failed"); |
|
161 |
} |
|
162 |
} |
|
163 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
164 |
static void checkStrings(String expected, String found) throws Exception { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
165 |
if (!expected.equals(found)) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
166 |
System.err.printf ("Test failed: wrong string %s/%s\n", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
167 |
expected, found); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
168 |
throw new RuntimeException("Test failed"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
169 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
170 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
171 |
|
48083 | 172 |
static void check(boolean cond, Object... msg) { |
173 |
if (cond) |
|
174 |
return; |
|
175 |
StringBuilder sb = new StringBuilder(); |
|
176 |
for (Object o : msg) |
|
177 |
sb.append(o); |
|
178 |
throw new RuntimeException(sb.toString()); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
179 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
180 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
181 |
static final String SIMPLE_STRING = "Hello world Goodbye world"; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
182 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
183 |
static void simpleTest() throws Exception { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
184 |
URI uri = getURI(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
185 |
System.err.println("Request to " + uri); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
186 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
187 |
HttpClient client = getClient(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
188 |
HttpRequest req = HttpRequest.newBuilder(uri) |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
189 |
.POST(BodyPublishers.ofString(SIMPLE_STRING)) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
190 |
.build(); |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56093
diff
changeset
|
191 |
CompletableFuture<HttpResponse<String>> cf = client.sendAsync(req, BodyHandlers.ofString()); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
192 |
HttpResponse<String> response = cf.join(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
193 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
194 |
checkStatus(200, response.statusCode()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
195 |
String responseBody = response.body(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
196 |
checkStrings(SIMPLE_STRING, responseBody); |
48083 | 197 |
checkURIs(response.uri(), altURI2); |
198 |
||
199 |
// check two previous responses |
|
200 |
HttpResponse<String> prev = response.previousResponse() |
|
201 |
.orElseThrow(() -> new RuntimeException("no previous response")); |
|
202 |
checkURIs(prev.uri(), altURI1); |
|
203 |
||
204 |
prev = prev.previousResponse() |
|
205 |
.orElseThrow(() -> new RuntimeException("no previous response")); |
|
206 |
checkURIs(prev.uri(), httpURI); |
|
207 |
||
208 |
checkPreviousRedirectResponses(req, response); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
209 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
210 |
System.err.println("DONE"); |
48083 | 211 |
} |
212 |
||
213 |
static void checkPreviousRedirectResponses(HttpRequest initialRequest, |
|
214 |
HttpResponse<?> finalResponse) { |
|
215 |
// there must be at least one previous response |
|
216 |
finalResponse.previousResponse() |
|
217 |
.orElseThrow(() -> new RuntimeException("no previous response")); |
|
218 |
||
219 |
HttpResponse<?> response = finalResponse; |
|
220 |
do { |
|
221 |
URI uri = response.uri(); |
|
222 |
response = response.previousResponse().get(); |
|
223 |
check(300 <= response.statusCode() && response.statusCode() <= 309, |
|
224 |
"Expected 300 <= code <= 309, got:" + response.statusCode()); |
|
225 |
check(response.body() == null, "Unexpected body: " + response.body()); |
|
226 |
String locationHeader = response.headers().firstValue("Location") |
|
227 |
.orElseThrow(() -> new RuntimeException("no previous Location")); |
|
228 |
check(uri.toString().endsWith(locationHeader), |
|
229 |
"URI: " + uri + ", Location: " + locationHeader); |
|
230 |
} while (response.previousResponse().isPresent()); |
|
231 |
||
232 |
// initial |
|
233 |
check(initialRequest.equals(response.request()), |
|
234 |
"Expected initial request [%s] to equal last prev req [%s]", |
|
235 |
initialRequest, response.request()); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
236 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
237 |
} |