author | chegar |
Fri, 27 Sep 2019 09:55:35 +0100 | |
changeset 58365 | 73950479184b |
parent 52121 | 934969c63223 |
permissions | -rw-r--r-- |
50681 | 1 |
/* |
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @summary Tests that all response body is delivered to the BodySubscriber |
|
27 |
* before an abortive error terminates the flow |
|
52121
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
50681
diff
changeset
|
28 |
* @library /test/lib |
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
50681
diff
changeset
|
29 |
* @build jdk.test.lib.net.SimpleSSLContext |
50681 | 30 |
* @run testng/othervm ResponseBodyBeforeError |
31 |
*/ |
|
32 |
||
33 |
import java.io.Closeable; |
|
34 |
import java.io.IOException; |
|
35 |
import java.io.InputStream; |
|
36 |
import java.io.OutputStream; |
|
37 |
import java.io.UncheckedIOException; |
|
38 |
import java.net.InetAddress; |
|
39 |
import java.net.InetSocketAddress; |
|
40 |
import java.net.ServerSocket; |
|
41 |
import java.net.Socket; |
|
42 |
import java.net.URI; |
|
43 |
import java.net.http.HttpClient; |
|
44 |
import java.net.http.HttpRequest; |
|
45 |
import java.net.http.HttpResponse; |
|
46 |
import java.net.http.HttpResponse.BodySubscriber; |
|
47 |
import java.nio.ByteBuffer; |
|
48 |
import java.util.ArrayList; |
|
49 |
import java.util.Arrays; |
|
50 |
import java.util.List; |
|
51 |
import java.util.concurrent.CompletableFuture; |
|
52 |
import java.util.concurrent.CompletionStage; |
|
53 |
import java.util.concurrent.ExecutionException; |
|
54 |
import java.util.concurrent.Flow; |
|
52121
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
50681
diff
changeset
|
55 |
import jdk.test.lib.net.SimpleSSLContext; |
50681 | 56 |
import org.testng.annotations.AfterTest; |
57 |
import org.testng.annotations.BeforeTest; |
|
58 |
import org.testng.annotations.DataProvider; |
|
59 |
import org.testng.annotations.Test; |
|
60 |
import javax.net.ssl.SSLContext; |
|
61 |
import javax.net.ssl.SSLServerSocketFactory; |
|
62 |
import static java.lang.System.out; |
|
63 |
import static java.net.http.HttpClient.Builder.NO_PROXY; |
|
64 |
import static java.net.http.HttpResponse.BodyHandlers.ofString; |
|
65 |
import static java.nio.charset.StandardCharsets.US_ASCII; |
|
66 |
import static java.nio.charset.StandardCharsets.UTF_8; |
|
67 |
import static org.testng.Assert.assertEquals; |
|
68 |
import static org.testng.Assert.fail; |
|
69 |
||
70 |
public class ResponseBodyBeforeError { |
|
71 |
||
72 |
ReplyingServer variableLengthServer; |
|
73 |
ReplyingServer variableLengthHttpsServer; |
|
74 |
ReplyingServer fixedLengthServer; |
|
75 |
ReplyingServer fixedLengthHttpsServer; |
|
76 |
||
77 |
String httpURIVarLen; |
|
78 |
String httpsURIVarLen; |
|
79 |
String httpURIFixLen; |
|
80 |
String httpsURIFixLen; |
|
81 |
||
82 |
SSLContext sslContext; |
|
83 |
||
84 |
static final String EXPECTED_RESPONSE_BODY = |
|
85 |
"<html><body><h1>Heading</h1><p>Some Text</p></body></html>"; |
|
86 |
||
87 |
@DataProvider(name = "sanity") |
|
88 |
public Object[][] sanity() { |
|
89 |
return new Object[][]{ |
|
90 |
{ httpURIVarLen + "?length=all" }, |
|
91 |
{ httpsURIVarLen + "?length=all" }, |
|
92 |
{ httpURIFixLen + "?length=all" }, |
|
93 |
{ httpsURIFixLen + "?length=all" }, |
|
94 |
}; |
|
95 |
} |
|
96 |
||
97 |
@Test(dataProvider = "sanity") |
|
98 |
void sanity(String url) throws Exception { |
|
99 |
HttpClient client = HttpClient.newBuilder() |
|
100 |
.proxy(NO_PROXY) |
|
101 |
.sslContext(sslContext) |
|
102 |
.build(); |
|
103 |
HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build(); |
|
104 |
HttpResponse<String> response = client.send(request, ofString()); |
|
105 |
String body = response.body(); |
|
106 |
assertEquals(body, EXPECTED_RESPONSE_BODY); |
|
107 |
client.sendAsync(request, ofString()) |
|
108 |
.thenApply(resp -> resp.body()) |
|
109 |
.thenAccept(b -> assertEquals(b, EXPECTED_RESPONSE_BODY)) |
|
110 |
.join(); |
|
111 |
} |
|
112 |
||
113 |
@DataProvider(name = "uris") |
|
114 |
public Object[][] variants() { |
|
115 |
Object[][] cases = new Object[][] { |
|
116 |
// The length query string is the total number of response body |
|
117 |
// bytes in the reply, before the server closes the connection. The |
|
118 |
// second arg is a partial-expected-body that the body subscriber |
|
119 |
// should receive before onError is invoked. |
|
120 |
||
121 |
{ httpURIFixLen + "?length=0", "" }, |
|
122 |
{ httpURIFixLen + "?length=1", "<" }, |
|
123 |
{ httpURIFixLen + "?length=2", "<h" }, |
|
124 |
{ httpURIFixLen + "?length=10", "<html><bod" }, |
|
125 |
{ httpURIFixLen + "?length=19", "<html><body><h1>Hea" }, |
|
126 |
{ httpURIFixLen + "?length=31", "<html><body><h1>Heading</h1><p>" }, |
|
127 |
||
128 |
{ httpsURIFixLen + "?length=0", "" }, |
|
129 |
{ httpsURIFixLen + "?length=1", "<" }, |
|
130 |
{ httpsURIFixLen + "?length=2", "<h" }, |
|
131 |
{ httpsURIFixLen + "?length=10", "<html><bod" }, |
|
132 |
{ httpsURIFixLen + "?length=19", "<html><body><h1>Hea" }, |
|
133 |
{ httpsURIFixLen + "?length=31", "<html><body><h1>Heading</h1><p>" }, |
|
134 |
||
135 |
// accounts for chunk framing |
|
136 |
{ httpURIVarLen + "?length=0", "" }, |
|
137 |
{ httpURIVarLen + "?length=1", "" }, |
|
138 |
{ httpURIVarLen + "?length=2", "" }, |
|
139 |
{ httpURIVarLen + "?length=4", "<" }, |
|
140 |
{ httpURIVarLen + "?length=5", "<h" }, |
|
141 |
{ httpURIVarLen + "?length=18", "<html><bod" }, |
|
142 |
{ httpURIVarLen + "?length=20", "<html><body>" }, |
|
143 |
{ httpURIVarLen + "?length=21", "<html><body>" }, // boundary around chunk framing |
|
144 |
{ httpURIVarLen + "?length=22", "<html><body>" }, |
|
145 |
{ httpURIVarLen + "?length=23", "<html><body>" }, |
|
146 |
{ httpURIVarLen + "?length=24", "<html><body>" }, |
|
147 |
{ httpURIVarLen + "?length=25", "<html><body>" }, |
|
148 |
{ httpURIVarLen + "?length=26", "<html><body>" }, |
|
149 |
{ httpURIVarLen + "?length=27", "<html><body><" }, |
|
150 |
{ httpURIVarLen + "?length=51", "<html><body><h1>Heading</h1><p>" }, |
|
151 |
||
152 |
{ httpsURIVarLen + "?length=0", "" }, |
|
153 |
{ httpsURIVarLen + "?length=1", "" }, |
|
154 |
{ httpsURIVarLen + "?length=2", "" }, |
|
155 |
{ httpsURIVarLen + "?length=4", "<" }, |
|
156 |
{ httpsURIVarLen + "?length=5", "<h" }, |
|
157 |
{ httpsURIVarLen + "?length=18", "<html><bod" }, |
|
158 |
{ httpsURIVarLen + "?length=20", "<html><body>" }, |
|
159 |
{ httpsURIVarLen + "?length=21", "<html><body>" }, |
|
160 |
{ httpsURIVarLen + "?length=22", "<html><body>" }, |
|
161 |
{ httpsURIVarLen + "?length=23", "<html><body>" }, |
|
162 |
{ httpsURIVarLen + "?length=24", "<html><body>" }, |
|
163 |
{ httpsURIVarLen + "?length=25", "<html><body>" }, |
|
164 |
{ httpsURIVarLen + "?length=26", "<html><body>" }, |
|
165 |
{ httpsURIVarLen + "?length=27", "<html><body><" }, |
|
166 |
{ httpsURIVarLen + "?length=51", "<html><body><h1>Heading</h1><p>" }, |
|
167 |
}; |
|
168 |
||
169 |
List<Object[]> list = new ArrayList<>(); |
|
170 |
Arrays.asList(cases).stream() |
|
171 |
.map(e -> new Object[] {e[0], e[1], true}) // reuse client |
|
172 |
.forEach(list::add); |
|
173 |
Arrays.asList(cases).stream() |
|
174 |
.map(e -> new Object[] {e[0], e[1], false}) // do not reuse client |
|
175 |
.forEach(list::add); |
|
176 |
return list.stream().toArray(Object[][]::new); |
|
177 |
} |
|
178 |
||
179 |
static final int ITERATION_COUNT = 3; |
|
180 |
||
181 |
@Test(dataProvider = "uris") |
|
182 |
void testSynchronousAllRequestBody(String url, |
|
183 |
String expectedPatrialBody, |
|
184 |
boolean sameClient) |
|
185 |
throws Exception |
|
186 |
{ |
|
187 |
out.print("---\n"); |
|
188 |
HttpClient client = null; |
|
189 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
190 |
if (!sameClient || client == null) |
|
191 |
client = HttpClient.newBuilder() |
|
192 |
.proxy(NO_PROXY) |
|
193 |
.sslContext(sslContext) |
|
194 |
.build(); |
|
195 |
HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build(); |
|
196 |
CustomBodySubscriber bs = new CustomBodySubscriber(); |
|
197 |
try { |
|
198 |
HttpResponse<String> response = client.send(request, r -> bs); |
|
199 |
String body = response.body(); |
|
200 |
out.println(response + ": " + body); |
|
201 |
fail("UNEXPECTED RESPONSE: " + response); |
|
202 |
} catch (IOException expected) { |
|
203 |
String pm = bs.receivedAsString(); |
|
204 |
out.println("partial body received: " + pm); |
|
205 |
assertEquals(pm, expectedPatrialBody); |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
@Test(dataProvider = "uris") |
|
211 |
void testAsynchronousAllRequestBody(String url, |
|
212 |
String expectedPatrialBody, |
|
213 |
boolean sameClient) |
|
214 |
throws Exception |
|
215 |
{ |
|
216 |
out.print("---\n"); |
|
217 |
HttpClient client = null; |
|
218 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
219 |
if (!sameClient || client == null) |
|
220 |
client = HttpClient.newBuilder() |
|
221 |
.proxy(NO_PROXY) |
|
222 |
.sslContext(sslContext) |
|
223 |
.build(); |
|
224 |
HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build(); |
|
225 |
CustomBodySubscriber bs = new CustomBodySubscriber(); |
|
226 |
try { |
|
227 |
HttpResponse<String> response = client.sendAsync(request, r -> bs).get(); |
|
228 |
String body = response.body(); |
|
229 |
out.println(response + ": " + body); |
|
230 |
fail("UNEXPECTED RESPONSE: " + response); |
|
231 |
} catch (ExecutionException ee) { |
|
232 |
if (ee.getCause() instanceof IOException) { |
|
233 |
String pm = bs.receivedAsString(); |
|
234 |
out.println("partial body received: " + pm); |
|
235 |
assertEquals(pm, expectedPatrialBody); |
|
236 |
} else { |
|
237 |
throw ee; |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
static final class CustomBodySubscriber implements BodySubscriber<String> { |
|
244 |
||
245 |
Flow.Subscription subscription; |
|
246 |
private final List<ByteBuffer> received = new ArrayList<>(); |
|
247 |
private final CompletableFuture<String> cf = new CompletableFuture<>(); |
|
248 |
||
249 |
@Override |
|
250 |
public CompletionStage<String> getBody() { |
|
251 |
return cf; |
|
252 |
} |
|
253 |
||
254 |
@Override |
|
255 |
public void onSubscribe(Flow.Subscription subscription) { |
|
256 |
out.println("CustomBodySubscriber got onSubscribe: "); |
|
257 |
this.subscription = subscription; |
|
258 |
subscription.request(1); |
|
259 |
} |
|
260 |
||
261 |
@Override |
|
262 |
public void onNext(List<ByteBuffer> items) { |
|
263 |
out.println("CustomBodySubscriber got onNext: " + items); |
|
264 |
received.addAll(items); |
|
265 |
subscription.request(1); |
|
266 |
} |
|
267 |
||
268 |
@Override |
|
269 |
public void onError(Throwable expected) { |
|
270 |
out.println("CustomBodySubscriber got expected: " + expected); |
|
271 |
cf.completeExceptionally(expected); |
|
272 |
} |
|
273 |
||
274 |
String receivedAsString() { |
|
275 |
int size = received.stream().mapToInt(ByteBuffer::remaining).sum(); |
|
276 |
byte[] res = new byte[size]; |
|
277 |
int from = 0; |
|
278 |
for (ByteBuffer b : received) { |
|
279 |
int l = b.remaining(); |
|
280 |
b.get(res, from, l); |
|
281 |
from += l; |
|
282 |
} |
|
283 |
return new String(res, UTF_8); |
|
284 |
} |
|
285 |
||
286 |
@Override |
|
287 |
public void onComplete() { |
|
288 |
out.println("CustomBodySubscriber got complete: "); |
|
289 |
assert false : "Unexpected onComplete"; |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
// -- infra |
|
294 |
||
295 |
/** |
|
296 |
* A server that replies with headers and a, possibly partial, reply, before |
|
297 |
* closing the connection. The number of body bytes of written, is |
|
298 |
* controllable through the "length" query string param in the requested |
|
299 |
* URI. |
|
300 |
*/ |
|
301 |
static abstract class ReplyingServer extends Thread implements Closeable { |
|
302 |
||
303 |
private final String name; |
|
304 |
private final ServerSocket ss; |
|
305 |
private volatile boolean closed; |
|
306 |
||
307 |
private ReplyingServer(String name) throws IOException { |
|
308 |
super(name); |
|
309 |
this.name = name; |
|
310 |
ss = newServerSocket(); |
|
311 |
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); |
|
312 |
this.start(); |
|
313 |
} |
|
314 |
||
315 |
protected ServerSocket newServerSocket() throws IOException { |
|
316 |
return new ServerSocket(); |
|
317 |
} |
|
318 |
||
319 |
abstract String responseHeaders(); |
|
320 |
||
321 |
abstract String responseBody(); |
|
322 |
||
323 |
@Override |
|
324 |
public void run() { |
|
325 |
while (!closed) { |
|
326 |
try (Socket s = ss.accept()) { |
|
327 |
out.print(name + ": got connection "); |
|
328 |
InputStream is = s.getInputStream(); |
|
329 |
URI requestMethod = readRequestMethod(is); |
|
330 |
out.print(requestMethod + " "); |
|
331 |
URI uriPath = readRequestPath(is); |
|
332 |
out.println(uriPath); |
|
333 |
readRequestHeaders(is); |
|
334 |
||
335 |
String query = uriPath.getRawQuery(); |
|
336 |
assert query != null; |
|
337 |
String qv = query.split("=")[1]; |
|
338 |
int len; |
|
339 |
if (qv.equals("all")) { |
|
340 |
len = responseBody().getBytes(US_ASCII).length; |
|
341 |
} else { |
|
342 |
len = Integer.parseInt(query.split("=")[1]); |
|
343 |
} |
|
344 |
||
345 |
OutputStream os = s.getOutputStream(); |
|
346 |
os.write(responseHeaders().getBytes(US_ASCII)); |
|
347 |
out.println(name + ": headers written, writing " + len + " body bytes"); |
|
348 |
byte[] responseBytes = responseBody().getBytes(US_ASCII); |
|
349 |
for (int i = 0; i< len; i++) { |
|
350 |
os.write(responseBytes[i]); |
|
351 |
os.flush(); |
|
352 |
} |
|
353 |
} catch (IOException e) { |
|
354 |
if (!closed) |
|
355 |
throw new UncheckedIOException("Unexpected", e); |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
static final byte[] requestEnd = new byte[] { '\r', '\n', '\r', '\n' }; |
|
361 |
||
362 |
// Read the request method |
|
363 |
static URI readRequestMethod(InputStream is) throws IOException { |
|
364 |
StringBuilder sb = new StringBuilder(); |
|
365 |
int r; |
|
366 |
while ((r = is.read()) != -1 && r != 0x20) { |
|
367 |
sb.append((char)r); |
|
368 |
} |
|
369 |
return URI.create(sb.toString()); |
|
370 |
} |
|
371 |
||
372 |
// Read the request URI path |
|
373 |
static URI readRequestPath(InputStream is) throws IOException { |
|
374 |
StringBuilder sb = new StringBuilder(); |
|
375 |
int r; |
|
376 |
while ((r = is.read()) != -1 && r != 0x20) { |
|
377 |
sb.append((char)r); |
|
378 |
} |
|
379 |
return URI.create(sb.toString()); |
|
380 |
} |
|
381 |
||
382 |
// Read until the end of a HTTP request headers |
|
383 |
static void readRequestHeaders(InputStream is) throws IOException { |
|
384 |
int requestEndCount = 0, r; |
|
385 |
while ((r = is.read()) != -1) { |
|
386 |
if (r == requestEnd[requestEndCount]) { |
|
387 |
requestEndCount++; |
|
388 |
if (requestEndCount == 4) { |
|
389 |
break; |
|
390 |
} |
|
391 |
} else { |
|
392 |
requestEndCount = 0; |
|
393 |
} |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
public int getPort() { return ss.getLocalPort(); } |
|
398 |
||
399 |
@Override |
|
400 |
public void close() { |
|
401 |
if (closed) |
|
402 |
return; |
|
403 |
closed = true; |
|
404 |
try { |
|
405 |
ss.close(); |
|
406 |
} catch (IOException e) { |
|
407 |
throw new UncheckedIOException("Unexpected", e); |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
||
412 |
/** A server that issues a possibly-partial chunked reply. */ |
|
413 |
static class PlainVariableLengthServer extends ReplyingServer { |
|
414 |
||
415 |
static final String CHUNKED_RESPONSE_BODY = |
|
416 |
"6\r\n"+ "<html>\r\n" + |
|
417 |
"6\r\n"+ "<body>\r\n" + |
|
418 |
"10\r\n"+ "<h1>Heading</h1>\r\n" + |
|
419 |
"10\r\n"+ "<p>Some Text</p>\r\n" + |
|
420 |
"7\r\n"+ "</body>\r\n" + |
|
421 |
"7\r\n"+ "</html>\r\n" + |
|
422 |
"0\r\n"+ "\r\n"; |
|
423 |
||
424 |
static final String RESPONSE_HEADERS = |
|
425 |
"HTTP/1.1 200 OK\r\n" + |
|
426 |
"Content-Type: text/html; charset=utf-8\r\n" + |
|
427 |
"Transfer-Encoding: chunked\r\n" + |
|
428 |
"Connection: close\r\n\r\n"; |
|
429 |
||
430 |
||
431 |
PlainVariableLengthServer() throws IOException { |
|
432 |
super("PlainVariableLengthServer"); |
|
433 |
} |
|
434 |
||
435 |
protected PlainVariableLengthServer(String name) throws IOException { |
|
436 |
super(name); |
|
437 |
} |
|
438 |
||
439 |
@Override |
|
440 |
String responseHeaders( ) { return RESPONSE_HEADERS; } |
|
441 |
||
442 |
@Override |
|
443 |
String responseBody( ) { return CHUNKED_RESPONSE_BODY; } |
|
444 |
} |
|
445 |
||
446 |
/** A server that issues a, possibly-partial, chunked reply over SSL */ |
|
447 |
static final class SSLVariableLengthServer extends PlainVariableLengthServer { |
|
448 |
SSLVariableLengthServer() throws IOException { |
|
449 |
super("SSLVariableLengthServer"); |
|
450 |
} |
|
451 |
@Override |
|
452 |
public ServerSocket newServerSocket() throws IOException { |
|
453 |
return SSLServerSocketFactory.getDefault().createServerSocket(); |
|
454 |
} |
|
455 |
} |
|
456 |
||
457 |
/** A server that issues a, possibly-partial, fixed-length reply. */ |
|
458 |
static class PlainFixedLengthServer extends ReplyingServer { |
|
459 |
||
460 |
static final String RESPONSE_BODY = EXPECTED_RESPONSE_BODY; |
|
461 |
||
462 |
static final String RESPONSE_HEADERS = |
|
463 |
"HTTP/1.1 200 OK\r\n" + |
|
464 |
"Content-Type: text/html; charset=utf-8\r\n" + |
|
465 |
"Content-Length: " + RESPONSE_BODY.length() + "\r\n" + |
|
466 |
"Connection: close\r\n\r\n"; |
|
467 |
||
468 |
PlainFixedLengthServer() throws IOException { |
|
469 |
super("PlainFixedLengthServer"); |
|
470 |
} |
|
471 |
||
472 |
protected PlainFixedLengthServer(String name) throws IOException { |
|
473 |
super(name); |
|
474 |
} |
|
475 |
||
476 |
@Override |
|
477 |
String responseHeaders( ) { return RESPONSE_HEADERS; } |
|
478 |
||
479 |
@Override |
|
480 |
String responseBody( ) { return RESPONSE_BODY; } |
|
481 |
} |
|
482 |
||
483 |
/** A server that issues a, possibly-partial, fixed-length reply over SSL */ |
|
484 |
static final class SSLFixedLengthServer extends PlainFixedLengthServer { |
|
485 |
SSLFixedLengthServer() throws IOException { |
|
486 |
super("SSLFixedLengthServer"); |
|
487 |
} |
|
488 |
@Override |
|
489 |
public ServerSocket newServerSocket() throws IOException { |
|
490 |
return SSLServerSocketFactory.getDefault().createServerSocket(); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
static String serverAuthority(ReplyingServer server) { |
|
495 |
return InetAddress.getLoopbackAddress().getHostName() + ":" |
|
496 |
+ server.getPort(); |
|
497 |
} |
|
498 |
||
499 |
@BeforeTest |
|
500 |
public void setup() throws Exception { |
|
501 |
sslContext = new SimpleSSLContext().get(); |
|
502 |
if (sslContext == null) |
|
503 |
throw new AssertionError("Unexpected null sslContext"); |
|
504 |
SSLContext.setDefault(sslContext); |
|
505 |
||
506 |
variableLengthServer = new PlainVariableLengthServer(); |
|
507 |
httpURIVarLen = "http://" + serverAuthority(variableLengthServer) |
|
508 |
+ "/http1/variable/foo"; |
|
509 |
||
510 |
variableLengthHttpsServer = new SSLVariableLengthServer(); |
|
511 |
httpsURIVarLen = "https://" + serverAuthority(variableLengthHttpsServer) |
|
512 |
+ "/https1/variable/bar"; |
|
513 |
||
514 |
fixedLengthServer = new PlainFixedLengthServer(); |
|
515 |
httpURIFixLen = "http://" + serverAuthority(fixedLengthServer) |
|
516 |
+ "/http1/fixed/baz"; |
|
517 |
||
518 |
fixedLengthHttpsServer = new SSLFixedLengthServer(); |
|
519 |
httpsURIFixLen = "https://" + serverAuthority(fixedLengthHttpsServer) |
|
520 |
+ "/https1/fixed/foz"; |
|
521 |
} |
|
522 |
||
523 |
@AfterTest |
|
524 |
public void teardown() throws Exception { |
|
525 |
variableLengthServer.close(); |
|
526 |
variableLengthHttpsServer.close(); |
|
527 |
fixedLengthServer.close(); |
|
528 |
fixedLengthHttpsServer.close(); |
|
529 |
} |
|
530 |
} |