Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/RetryUponTimeout.java
41159 views
1
/*
2
* Copyright (c) 2003, 2019, 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
* @bug 4772077
27
* @library /test/lib
28
* @summary using defaultReadTimeout appear to retry request upon timeout
29
* @modules java.base/sun.net.www
30
*/
31
32
import java.net.*;
33
import java.io.*;
34
import jdk.test.lib.net.URIBuilder;
35
import sun.net.www.*;
36
37
public class RetryUponTimeout implements Runnable {
38
// run server
39
public void run(){
40
Socket socket = null;
41
try {
42
for (int i = 0; i < 2; i++) {
43
socket = server.accept();
44
InputStream is = socket.getInputStream ();
45
MessageHeader header = new MessageHeader (is);
46
count++;
47
}
48
} catch (Exception ex) {
49
// ignored
50
} finally {
51
try {
52
socket.close();
53
server.close();
54
} catch (IOException ioex) {
55
}
56
}
57
58
}
59
60
static ServerSocket server;
61
static int count = 0;
62
public static void main(String[] args) throws Exception {
63
try {
64
server = new ServerSocket(0, 0, InetAddress.getLoopbackAddress());
65
int port = server.getLocalPort ();
66
new Thread(new RetryUponTimeout()).start ();
67
68
URL url = URIBuilder.newBuilder()
69
.scheme("http")
70
.loopback()
71
.port(port)
72
.toURL();
73
System.out.println("URL: " + url);
74
java.net.URLConnection uc = url.openConnection();
75
uc.setReadTimeout(1000);
76
uc.getInputStream();
77
} catch (SocketTimeoutException stex) {
78
// expected exception
79
server.close();
80
}
81
82
if (count > 1) {
83
throw new RuntimeException("Server received "+count+" requests instead of one.");
84
}
85
86
}
87
}
88
89