2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2019-05-14 13:34:49 +01:00
|
|
|
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 15:58:33 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @bug 4772077
|
2019-03-27 09:06:43 -07:00
|
|
|
* @library /test/lib
|
2007-12-01 00:00:00 +00:00
|
|
|
* @summary using defaultReadTimeout appear to retry request upon timeout
|
2015-05-28 10:54:48 -07:00
|
|
|
* @modules java.base/sun.net.www
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import java.net.*;
|
|
|
|
import java.io.*;
|
2019-03-27 09:06:43 -07:00
|
|
|
import jdk.test.lib.net.URIBuilder;
|
2007-12-01 00:00:00 +00:00
|
|
|
import sun.net.www.*;
|
|
|
|
|
|
|
|
public class RetryUponTimeout implements Runnable {
|
|
|
|
// run server
|
|
|
|
public void run(){
|
|
|
|
Socket socket = null;
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
socket = server.accept();
|
|
|
|
InputStream is = socket.getInputStream ();
|
|
|
|
MessageHeader header = new MessageHeader (is);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
// ignored
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
socket.close();
|
|
|
|
server.close();
|
|
|
|
} catch (IOException ioex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static ServerSocket server;
|
|
|
|
static int count = 0;
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
try {
|
2019-05-14 13:34:49 +01:00
|
|
|
server = new ServerSocket(0, 0, InetAddress.getLoopbackAddress());
|
2007-12-01 00:00:00 +00:00
|
|
|
int port = server.getLocalPort ();
|
|
|
|
new Thread(new RetryUponTimeout()).start ();
|
|
|
|
|
2019-03-27 09:06:43 -07:00
|
|
|
URL url = URIBuilder.newBuilder()
|
|
|
|
.scheme("http")
|
|
|
|
.loopback()
|
|
|
|
.port(port)
|
|
|
|
.toURL();
|
|
|
|
System.out.println("URL: " + url);
|
2007-12-01 00:00:00 +00:00
|
|
|
java.net.URLConnection uc = url.openConnection();
|
|
|
|
uc.setReadTimeout(1000);
|
|
|
|
uc.getInputStream();
|
|
|
|
} catch (SocketTimeoutException stex) {
|
|
|
|
// expected exception
|
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 1) {
|
|
|
|
throw new RuntimeException("Server received "+count+" requests instead of one.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|