8223856: Replace wildcard address with loopback or local host in tests - part 8
Fixes some intermittent test failures by replacing wildcard with loopback - or retrying once. Reviewed-by: aefimov, chegar
This commit is contained in:
parent
ef5194182f
commit
cd9e3c1b13
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,8 +24,12 @@
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8015692
|
* @bug 8015692
|
||||||
|
* @key intermittent
|
||||||
* @summary Test HttpServer instantiation, start, and stop repeated in a loop
|
* @summary Test HttpServer instantiation, start, and stop repeated in a loop
|
||||||
* Testing for Bind exception on Windows
|
* Testing for Bind exception on Windows. This test may fail
|
||||||
|
* intermittently if other tests / process manage to bind to
|
||||||
|
* the same port that the test is using in the short window
|
||||||
|
* time where the port might appear available again.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -41,24 +45,40 @@ public class SimpleHttpServerTest {
|
|||||||
System.out.println(System.getProperty("java.version"));
|
System.out.println(System.getProperty("java.version"));
|
||||||
InetSocketAddress serverAddr = new InetSocketAddress(0);
|
InetSocketAddress serverAddr = new InetSocketAddress(0);
|
||||||
HttpServer server = HttpServer.create(serverAddr, 0);
|
HttpServer server = HttpServer.create(serverAddr, 0);
|
||||||
final int serverPort = server.getAddress().getPort();
|
int serverPort = server.getAddress().getPort();
|
||||||
server.start();
|
server.start();
|
||||||
server.stop(0);
|
server.stop(0);
|
||||||
serverAddr = new InetSocketAddress(serverPort);
|
serverAddr = new InetSocketAddress(serverPort);
|
||||||
int exceptionCount = 0;
|
int exceptionCount = 0;
|
||||||
|
boolean failedOnce = false;
|
||||||
System.out.println("Using serverPort == " + serverPort);
|
System.out.println("Using serverPort == " + serverPort);
|
||||||
|
RETRY: while (exceptionCount == 0) {
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
try {
|
try {
|
||||||
server = HttpServer.create(serverAddr, 0);
|
server = HttpServer.create(serverAddr, 0);
|
||||||
server.start();
|
server.start();
|
||||||
server.stop(0);
|
server.stop(0);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
if (!failedOnce) {
|
||||||
|
failedOnce = true;
|
||||||
|
server = HttpServer.create(new InetSocketAddress(0), 0);
|
||||||
|
serverPort = server.getAddress().getPort();
|
||||||
|
server.start();
|
||||||
|
server.stop(0);
|
||||||
|
serverAddr = new InetSocketAddress(serverPort);
|
||||||
|
System.out.println("Retrying with serverPort == " + serverPort);
|
||||||
|
continue RETRY;
|
||||||
|
}
|
||||||
|
System.err.println("Got exception at iteration: " + i );
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
exceptionCount++;
|
exceptionCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (exceptionCount > 0) {
|
if (exceptionCount > 0) {
|
||||||
throw new RuntimeException("Test Failed");
|
throw new RuntimeException("Test Failed: got "
|
||||||
|
+ exceptionCount + " exceptions.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -51,18 +51,24 @@ public class Test {
|
|||||||
|
|
||||||
static int count;
|
static int count;
|
||||||
static int failures;
|
static int failures;
|
||||||
|
static boolean retried;
|
||||||
|
|
||||||
static void doTest(Object test[], InetAddress ia1, InetAddress ia2,
|
static void doTest(Object test[], InetAddress ia1, InetAddress ia2,
|
||||||
boolean silent) throws Exception {
|
boolean silent) throws Exception {
|
||||||
String s1_type = (String)test[0];
|
|
||||||
String s2_type = (String)test[1];
|
|
||||||
int port = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Increment test count
|
* Increment test count
|
||||||
*/
|
*/
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
|
doTest(test, count, ia1, ia2, silent, !retried);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void doTest(Object test[], int count, InetAddress ia1, InetAddress ia2,
|
||||||
|
boolean silent, boolean retry) throws Exception {
|
||||||
|
String s1_type = (String)test[0];
|
||||||
|
String s2_type = (String)test[1];
|
||||||
|
int port = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do the test
|
* Do the test
|
||||||
*/
|
*/
|
||||||
@ -74,6 +80,8 @@ public class Test {
|
|||||||
Socket sock1 = null;
|
Socket sock1 = null;
|
||||||
ServerSocket ss = null;
|
ServerSocket ss = null;
|
||||||
DatagramSocket dsock1 = null;
|
DatagramSocket dsock1 = null;
|
||||||
|
boolean firstBound = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/* bind the first socket */
|
/* bind the first socket */
|
||||||
|
|
||||||
@ -95,6 +103,13 @@ public class Test {
|
|||||||
|
|
||||||
/* bind the second socket */
|
/* bind the second socket */
|
||||||
|
|
||||||
|
// The fact that the port was available for ia1 does not
|
||||||
|
// guarantee that it will also be available for ia2 as something
|
||||||
|
// else might already be bound to that port.
|
||||||
|
// For the sake of test stability we will retry once in
|
||||||
|
// case of unexpected bind exception.
|
||||||
|
|
||||||
|
firstBound = true;
|
||||||
if (s2_type.equals("Socket")) {
|
if (s2_type.equals("Socket")) {
|
||||||
try (Socket sock2 = new Socket()) {
|
try (Socket sock2 = new Socket()) {
|
||||||
sock2.bind( new InetSocketAddress(ia2, port));
|
sock2.bind( new InetSocketAddress(ia2, port));
|
||||||
@ -148,6 +163,18 @@ public class Test {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failed && retry && firstBound) {
|
||||||
|
// retry once at the first failure only
|
||||||
|
retried = true;
|
||||||
|
if (!silent) {
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("**************************");
|
||||||
|
System.out.println("Test " + count + ": Retrying...");
|
||||||
|
}
|
||||||
|
doTest(test, count, ia1, ia2, silent, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (failed || !silent) {
|
if (failed || !silent) {
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
System.out.println("**************************");
|
System.out.println("**************************");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -35,8 +35,10 @@ public class SetOption {
|
|||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
|
||||||
ServerSocket ss = new ServerSocket(0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
Socket s1 = new Socket("localhost", ss.getLocalPort());
|
ServerSocket ss = new ServerSocket(0, 0, loopback);
|
||||||
|
|
||||||
|
Socket s1 = new Socket(loopback, ss.getLocalPort());
|
||||||
Socket s2 = ss.accept();
|
Socket s2 = ss.accept();
|
||||||
|
|
||||||
s1.close();
|
s1.close();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -47,8 +47,10 @@ public class RST implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RST() throws Exception {
|
RST() throws Exception {
|
||||||
ServerSocket ss = new ServerSocket(0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
client = new Socket("localhost", ss.getLocalPort());
|
ServerSocket ss = new ServerSocket();
|
||||||
|
ss.bind(new InetSocketAddress(loopback, 0));
|
||||||
|
client = new Socket(loopback, ss.getLocalPort());
|
||||||
Socket server = ss.accept();
|
Socket server = ss.accept();
|
||||||
|
|
||||||
Thread thr = new Thread(this);
|
Thread thr = new Thread(this);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -27,12 +27,14 @@
|
|||||||
* @summary URLConnection cannot enumerate request properties,
|
* @summary URLConnection cannot enumerate request properties,
|
||||||
* and URLConnection can neither get nor set multiple
|
* and URLConnection can neither get nor set multiple
|
||||||
* request properties w/ same key
|
* request properties w/ same key
|
||||||
|
* @library /test/lib
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class URLConnectionHeaders {
|
public class URLConnectionHeaders {
|
||||||
|
|
||||||
@ -77,14 +79,21 @@ public class URLConnectionHeaders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws Exception {
|
||||||
try {
|
try {
|
||||||
ServerSocket serversocket = new ServerSocket (0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
|
ServerSocket serversocket = new ServerSocket();
|
||||||
|
serversocket.bind(new InetSocketAddress(loopback, 0));
|
||||||
int port = serversocket.getLocalPort();
|
int port = serversocket.getLocalPort();
|
||||||
XServer server = new XServer(serversocket);
|
XServer server = new XServer(serversocket);
|
||||||
server.start();
|
server.start();
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
URL url = new URL ("http://localhost:"+port+"/index.html");
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("http")
|
||||||
|
.loopback()
|
||||||
|
.port(port)
|
||||||
|
.path("/index.html")
|
||||||
|
.toURL();
|
||||||
URLConnection uc = url.openConnection();
|
URLConnection uc = url.openConnection();
|
||||||
|
|
||||||
// add request properties
|
// add request properties
|
||||||
@ -106,6 +115,7 @@ public class URLConnectionHeaders {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,11 +24,14 @@
|
|||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4868820
|
* @bug 4868820
|
||||||
* @summary IPv6 support for Windows XP and 2003 server
|
* @key intermittent
|
||||||
|
* @summary IPv6 support for Windows XP and 2003 server.
|
||||||
|
* This test requires binding to the wildcard address and as such
|
||||||
|
* may fail intermittently on some platforms.
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @build jdk.test.lib.NetworkConfiguration
|
* @build jdk.test.lib.NetworkConfiguration
|
||||||
* jdk.test.lib.Platform
|
* jdk.test.lib.Platform
|
||||||
* @run main UdpTest
|
* @run main UdpTest -d
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
@ -92,6 +95,7 @@ public class UdpTest extends Tests {
|
|||||||
/* basic UDP connectivity test using IPv6 only and IPv4/IPv6 together */
|
/* basic UDP connectivity test using IPv6 only and IPv4/IPv6 together */
|
||||||
|
|
||||||
static void test1 () throws Exception {
|
static void test1 () throws Exception {
|
||||||
|
System.out.println("Test1 starting");
|
||||||
s1 = new DatagramSocket ();
|
s1 = new DatagramSocket ();
|
||||||
s2 = new DatagramSocket ();
|
s2 = new DatagramSocket ();
|
||||||
simpleDataExchange (s1, ia4addr, s2, ia4addr);
|
simpleDataExchange (s1, ia4addr, s2, ia4addr);
|
||||||
@ -130,6 +134,7 @@ public class UdpTest extends Tests {
|
|||||||
/* check timeouts on receive */
|
/* check timeouts on receive */
|
||||||
|
|
||||||
static void test2 () throws Exception {
|
static void test2 () throws Exception {
|
||||||
|
System.out.println("Test2 starting");
|
||||||
s1 = new DatagramSocket ();
|
s1 = new DatagramSocket ();
|
||||||
s2 = new DatagramSocket ();
|
s2 = new DatagramSocket ();
|
||||||
s1.setSoTimeout (4000);
|
s1.setSoTimeout (4000);
|
||||||
@ -180,6 +185,7 @@ public class UdpTest extends Tests {
|
|||||||
/* check connected sockets */
|
/* check connected sockets */
|
||||||
|
|
||||||
static void test3 () throws Exception {
|
static void test3 () throws Exception {
|
||||||
|
System.out.println("Test3 starting");
|
||||||
s1 = new DatagramSocket ();
|
s1 = new DatagramSocket ();
|
||||||
s2 = new DatagramSocket ();
|
s2 = new DatagramSocket ();
|
||||||
s1.connect (ia6addr, s2.getLocalPort());
|
s1.connect (ia6addr, s2.getLocalPort());
|
||||||
@ -191,6 +197,7 @@ public class UdpTest extends Tests {
|
|||||||
/* check PortUnreachable */
|
/* check PortUnreachable */
|
||||||
|
|
||||||
static void test4 () throws Exception {
|
static void test4 () throws Exception {
|
||||||
|
System.out.println("Test4 starting");
|
||||||
s1 = new DatagramSocket ();
|
s1 = new DatagramSocket ();
|
||||||
s1.connect (ia6addr, 5000);
|
s1.connect (ia6addr, 5000);
|
||||||
s1.setSoTimeout (3000);
|
s1.setSoTimeout (3000);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -105,13 +105,14 @@ public class B6427768 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
FtpServer server = new FtpServer(0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
|
FtpServer server = new FtpServer(loopback, 0);
|
||||||
int port = server.getLocalPort();
|
int port = server.getLocalPort();
|
||||||
server.setFileSystemHandler(new MyFileSystemHandler("/"));
|
server.setFileSystemHandler(new MyFileSystemHandler("/"));
|
||||||
server.setAuthHandler(new MyAuthHandler());
|
server.setAuthHandler(new MyAuthHandler());
|
||||||
server.start();
|
server.start();
|
||||||
URL url = new URL("ftp://user:passwd@localhost:" + port + "/foo.txt");
|
URL url = new URL("ftp://user:passwd@" + server.getAuthority() + "/foo.txt");
|
||||||
URLConnection con = url.openConnection();
|
URLConnection con = url.openConnection(Proxy.NO_PROXY);
|
||||||
// triggers the connection
|
// triggers the connection
|
||||||
try {
|
try {
|
||||||
con.getInputStream();
|
con.getInputStream();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -238,14 +238,14 @@ public class FtpCommandHandler extends Thread {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (pasv == null)
|
|
||||||
pasv = new ServerSocket(0);
|
|
||||||
int port = pasv.getLocalPort();
|
|
||||||
InetAddress rAddress = cmd.getLocalAddress();
|
InetAddress rAddress = cmd.getLocalAddress();
|
||||||
if (rAddress instanceof Inet6Address) {
|
if (rAddress instanceof Inet6Address) {
|
||||||
out.println("500 PASV illegal over IPv6 addresses, use EPSV.");
|
out.println("500 PASV illegal over IPv6 addresses, use EPSV.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (pasv == null)
|
||||||
|
pasv = new ServerSocket(0, 0, rAddress);
|
||||||
|
int port = pasv.getLocalPort();
|
||||||
byte[] a = rAddress.getAddress();
|
byte[] a = rAddress.getAddress();
|
||||||
out.println("227 Entering Passive Mode " + a[0] + "," + a[1] + "," + a[2] + "," + a[3] + "," +
|
out.println("227 Entering Passive Mode " + a[0] + "," + a[1] + "," + a[2] + "," + a[3] + "," +
|
||||||
(port >> 8) + "," + (port & 0xff) );
|
(port >> 8) + "," + (port & 0xff) );
|
||||||
@ -266,7 +266,7 @@ public class FtpCommandHandler extends Thread {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (pasv == null)
|
if (pasv == null)
|
||||||
pasv = new ServerSocket(0);
|
pasv = new ServerSocket(0, 0, parent.getInetAddress());
|
||||||
int port = pasv.getLocalPort();
|
int port = pasv.getLocalPort();
|
||||||
out.println("229 Entering Extended Passive Mode (|||" + port + "|)");
|
out.println("229 Entering Extended Passive Mode (|||" + port + "|)");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -110,8 +110,12 @@ public class FtpServer extends Thread implements AutoCloseable {
|
|||||||
return listener.getLocalPort();
|
return listener.getLocalPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InetAddress getInetAddress() {
|
||||||
|
return listener.getInetAddress();
|
||||||
|
}
|
||||||
|
|
||||||
public String getAuthority() {
|
public String getAuthority() {
|
||||||
InetAddress address = listener.getInetAddress();
|
InetAddress address = getInetAddress();
|
||||||
String hostaddr = address.isAnyLocalAddress()
|
String hostaddr = address.isAnyLocalAddress()
|
||||||
? "localhost" : address.getHostAddress();
|
? "localhost" : address.getHostAddress();
|
||||||
if (hostaddr.indexOf(':') > -1) {
|
if (hostaddr.indexOf(':') > -1) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -25,6 +25,7 @@
|
|||||||
* @test
|
* @test
|
||||||
* @bug 6427251 6382788
|
* @bug 6427251 6382788
|
||||||
* @modules jdk.httpserver
|
* @modules jdk.httpserver
|
||||||
|
* @library /test/lib
|
||||||
* @run main RetryPost
|
* @run main RetryPost
|
||||||
* @run main/othervm -Dsun.net.http.retryPost=false RetryPost noRetry
|
* @run main/othervm -Dsun.net.http.retryPost=false RetryPost noRetry
|
||||||
* @summary HttpURLConnection automatically retries non-idempotent method POST
|
* @summary HttpURLConnection automatically retries non-idempotent method POST
|
||||||
@ -36,12 +37,14 @@ import com.sun.net.httpserver.HttpHandler;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class RetryPost
|
public class RetryPost
|
||||||
{
|
{
|
||||||
@ -70,7 +73,12 @@ public class RetryPost
|
|||||||
void doClient() {
|
void doClient() {
|
||||||
try {
|
try {
|
||||||
InetSocketAddress address = httpServer.getAddress();
|
InetSocketAddress address = httpServer.getAddress();
|
||||||
URL url = new URL("http://localhost:" + address.getPort() + "/test/");
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("http")
|
||||||
|
.host(address.getAddress())
|
||||||
|
.port(address.getPort())
|
||||||
|
.path("/test/")
|
||||||
|
.toURLUnchecked();
|
||||||
HttpURLConnection uc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
HttpURLConnection uc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||||
uc.setDoOutput(true);
|
uc.setDoOutput(true);
|
||||||
uc.setRequestMethod("POST");
|
uc.setRequestMethod("POST");
|
||||||
@ -99,7 +107,8 @@ public class RetryPost
|
|||||||
* Http Server
|
* Http Server
|
||||||
*/
|
*/
|
||||||
public void startHttpServer(boolean shouldRetry) throws IOException {
|
public void startHttpServer(boolean shouldRetry) throws IOException {
|
||||||
httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(0), 0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
|
httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(loopback, 0), 0);
|
||||||
httpHandler = new MyHandler(shouldRetry);
|
httpHandler = new MyHandler(shouldRetry);
|
||||||
|
|
||||||
HttpContext ctx = httpServer.createContext("/test/", httpHandler);
|
HttpContext ctx = httpServer.createContext("/test/", httpHandler);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -29,21 +29,25 @@
|
|||||||
* @bug 7129083
|
* @bug 7129083
|
||||||
* @summary Cookiemanager does not store cookies if url is read
|
* @summary Cookiemanager does not store cookies if url is read
|
||||||
* before setting cookiemanager
|
* before setting cookiemanager
|
||||||
|
* @library /test/lib
|
||||||
* @run main/othervm CookieHttpsClientTest
|
* @run main/othervm CookieHttpsClientTest
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.CookieHandler;
|
import java.net.CookieHandler;
|
||||||
import java.net.CookieManager;
|
import java.net.CookieManager;
|
||||||
import java.net.CookiePolicy;
|
import java.net.CookiePolicy;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
import javax.net.ssl.SSLServerSocket;
|
import javax.net.ssl.SSLServerSocket;
|
||||||
import javax.net.ssl.SSLServerSocketFactory;
|
import javax.net.ssl.SSLServerSocketFactory;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class CookieHttpsClientTest {
|
public class CookieHttpsClientTest {
|
||||||
static final int TIMEOUT = 10 * 1000;
|
static final int TIMEOUT = 10 * 1000;
|
||||||
@ -91,10 +95,11 @@ public class CookieHttpsClientTest {
|
|||||||
* to avoid infinite hangs.
|
* to avoid infinite hangs.
|
||||||
*/
|
*/
|
||||||
void doServerSide() throws Exception {
|
void doServerSide() throws Exception {
|
||||||
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
SSLServerSocketFactory sslssf =
|
SSLServerSocketFactory sslssf =
|
||||||
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
||||||
SSLServerSocket sslServerSocket =
|
SSLServerSocket sslServerSocket =
|
||||||
(SSLServerSocket) sslssf.createServerSocket(serverPort);
|
(SSLServerSocket) sslssf.createServerSocket(serverPort, 0, loopback);
|
||||||
serverPort = sslServerSocket.getLocalPort();
|
serverPort = sslServerSocket.getLocalPort();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -137,10 +142,17 @@ public class CookieHttpsClientTest {
|
|||||||
return true;
|
return true;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
URL url = new URL("https://localhost:" + serverPort +"/");
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("https")
|
||||||
|
.loopback()
|
||||||
|
.port(serverPort)
|
||||||
|
.path("/")
|
||||||
|
.toURL();
|
||||||
|
|
||||||
|
System.out.println("Client ready to connect to: " + url);
|
||||||
|
|
||||||
// Run without a CookieHandler first
|
// Run without a CookieHandler first
|
||||||
InputStream in = url.openConnection().getInputStream();
|
InputStream in = url.openConnection(java.net.Proxy.NO_PROXY).getInputStream();
|
||||||
while (in.read() != -1); // read response body so connection can be reused
|
while (in.read() != -1); // read response body so connection can be reused
|
||||||
|
|
||||||
// Set a CookeHandler and retest using the HttpClient from the KAC
|
// Set a CookeHandler and retest using the HttpClient from the KAC
|
||||||
@ -183,6 +195,10 @@ public class CookieHttpsClientTest {
|
|||||||
volatile Exception serverException = null;
|
volatile Exception serverException = null;
|
||||||
volatile Exception clientException = null;
|
volatile Exception clientException = null;
|
||||||
|
|
||||||
|
private boolean sslConnectionFailed() {
|
||||||
|
return clientException instanceof SSLHandshakeException;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
String keyFilename =
|
String keyFilename =
|
||||||
System.getProperty("test.src", ".") + "/" + pathToStores +
|
System.getProperty("test.src", ".") + "/" + pathToStores +
|
||||||
@ -229,8 +245,12 @@ public class CookieHttpsClientTest {
|
|||||||
*/
|
*/
|
||||||
if (separateServerThread) {
|
if (separateServerThread) {
|
||||||
if (serverThread != null) {
|
if (serverThread != null) {
|
||||||
|
// don't join the server thread if the
|
||||||
|
// client failed to connect
|
||||||
|
if (!sslConnectionFailed()) {
|
||||||
serverThread.join();
|
serverThread.join();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (clientThread != null) {
|
if (clientThread != null) {
|
||||||
clientThread.join();
|
clientThread.join();
|
||||||
@ -259,7 +279,7 @@ public class CookieHttpsClientTest {
|
|||||||
*/
|
*/
|
||||||
if ((local != null) && (remote != null)) {
|
if ((local != null) && (remote != null)) {
|
||||||
// If both failed, return the curthread's exception.
|
// If both failed, return the curthread's exception.
|
||||||
local.initCause(remote);
|
local.addSuppressed(remote);
|
||||||
exception = local;
|
exception = local;
|
||||||
} else if (local != null) {
|
} else if (local != null) {
|
||||||
exception = local;
|
exception = local;
|
||||||
@ -274,7 +294,7 @@ public class CookieHttpsClientTest {
|
|||||||
* output it.
|
* output it.
|
||||||
*/
|
*/
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
if (exception != startException) {
|
if (exception != startException && startException != null) {
|
||||||
exception.addSuppressed(startException);
|
exception.addSuppressed(startException);
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
@ -323,7 +343,7 @@ public class CookieHttpsClientTest {
|
|||||||
/*
|
/*
|
||||||
* Our client thread just died.
|
* Our client thread just died.
|
||||||
*/
|
*/
|
||||||
System.err.println("Client died...");
|
System.err.println("Client died: " + e);
|
||||||
clientException = e;
|
clientException = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,6 +353,7 @@ public class CookieHttpsClientTest {
|
|||||||
try {
|
try {
|
||||||
doClientSide();
|
doClientSide();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
System.err.println("Client died: " + e);
|
||||||
clientException = e;
|
clientException = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -32,12 +32,14 @@
|
|||||||
* @summary sun.net.client.defaultConnectTimeout should work with
|
* @summary sun.net.client.defaultConnectTimeout should work with
|
||||||
* HttpsURLConnection; HTTP client: Connect and read timeouts;
|
* HttpsURLConnection; HTTP client: Connect and read timeouts;
|
||||||
* Https needs to support new tiger features that went into http
|
* Https needs to support new tiger features that went into http
|
||||||
|
* @library /test/lib
|
||||||
* @run main/othervm ReadTimeout
|
* @run main/othervm ReadTimeout
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class ReadTimeout {
|
public class ReadTimeout {
|
||||||
|
|
||||||
@ -93,10 +95,11 @@ public class ReadTimeout {
|
|||||||
* to avoid infinite hangs.
|
* to avoid infinite hangs.
|
||||||
*/
|
*/
|
||||||
void doServerSide() throws Exception {
|
void doServerSide() throws Exception {
|
||||||
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
SSLServerSocketFactory sslssf =
|
SSLServerSocketFactory sslssf =
|
||||||
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
||||||
SSLServerSocket sslServerSocket =
|
SSLServerSocket sslServerSocket =
|
||||||
(SSLServerSocket) sslssf.createServerSocket(serverPort);
|
(SSLServerSocket) sslssf.createServerSocket(serverPort, 0, loopback);
|
||||||
serverPort = sslServerSocket.getLocalPort();
|
serverPort = sslServerSocket.getLocalPort();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -163,7 +166,11 @@ public class ReadTimeout {
|
|||||||
}
|
}
|
||||||
HttpsURLConnection http = null;
|
HttpsURLConnection http = null;
|
||||||
try {
|
try {
|
||||||
URL url = new URL("https://localhost:" + serverPort);
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("https")
|
||||||
|
.loopback()
|
||||||
|
.port(serverPort)
|
||||||
|
.toURL();
|
||||||
|
|
||||||
// set read timeout through system property
|
// set read timeout through system property
|
||||||
System.setProperty("sun.net.client.defaultReadTimeout", "2000");
|
System.setProperty("sun.net.client.defaultReadTimeout", "2000");
|
||||||
@ -184,7 +191,11 @@ public class ReadTimeout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL("https://localhost:" + serverPort);
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("https")
|
||||||
|
.loopback()
|
||||||
|
.port(serverPort)
|
||||||
|
.toURL();
|
||||||
|
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(
|
HttpsURLConnection.setDefaultHostnameVerifier(
|
||||||
new NameVerifier());
|
new NameVerifier());
|
||||||
@ -239,6 +250,10 @@ public class ReadTimeout {
|
|||||||
volatile Exception serverException = null;
|
volatile Exception serverException = null;
|
||||||
volatile Exception clientException = null;
|
volatile Exception clientException = null;
|
||||||
|
|
||||||
|
private boolean sslConnectionFailed() {
|
||||||
|
return clientException instanceof SSLHandshakeException;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
String keyFilename =
|
String keyFilename =
|
||||||
System.getProperty("test.src", "./") + "/" + pathToStores +
|
System.getProperty("test.src", "./") + "/" + pathToStores +
|
||||||
@ -282,7 +297,9 @@ public class ReadTimeout {
|
|||||||
* Wait for other side to close down.
|
* Wait for other side to close down.
|
||||||
*/
|
*/
|
||||||
if (separateServerThread) {
|
if (separateServerThread) {
|
||||||
|
if (!sslConnectionFailed()) {
|
||||||
serverThread.join();
|
serverThread.join();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
clientThread.join();
|
clientThread.join();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -26,6 +26,7 @@
|
|||||||
* @bug 4423074
|
* @bug 4423074
|
||||||
* @summary Need to rebase all the duplicated classes from Merlin.
|
* @summary Need to rebase all the duplicated classes from Merlin.
|
||||||
* This test will check out http POST
|
* This test will check out http POST
|
||||||
|
* @library /test/lib
|
||||||
* @run main/othervm Redirect
|
* @run main/othervm Redirect
|
||||||
*
|
*
|
||||||
* SunJSSE does not support dynamic system properties, no way to re-use
|
* SunJSSE does not support dynamic system properties, no way to re-use
|
||||||
@ -35,6 +36,7 @@
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class Redirect {
|
public class Redirect {
|
||||||
|
|
||||||
@ -95,10 +97,11 @@ public class Redirect {
|
|||||||
* to avoid infinite hangs.
|
* to avoid infinite hangs.
|
||||||
*/
|
*/
|
||||||
void doServerSide() throws Exception {
|
void doServerSide() throws Exception {
|
||||||
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
SSLServerSocketFactory sslssf =
|
SSLServerSocketFactory sslssf =
|
||||||
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
||||||
SSLServerSocket sslServerSocket =
|
SSLServerSocket sslServerSocket =
|
||||||
(SSLServerSocket) sslssf.createServerSocket(serverPort);
|
(SSLServerSocket) sslssf.createServerSocket(serverPort, 0, loopback);
|
||||||
serverPort = sslServerSocket.getLocalPort();
|
serverPort = sslServerSocket.getLocalPort();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -154,7 +157,11 @@ public class Redirect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send HTTP POST request to server
|
// Send HTTP POST request to server
|
||||||
URL url = new URL("https://localhost:"+serverPort);
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("https")
|
||||||
|
.loopback()
|
||||||
|
.port(serverPort)
|
||||||
|
.toURL();
|
||||||
|
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(
|
HttpsURLConnection.setDefaultHostnameVerifier(
|
||||||
new NameVerifier());
|
new NameVerifier());
|
||||||
@ -190,6 +197,10 @@ public class Redirect {
|
|||||||
volatile Exception serverException = null;
|
volatile Exception serverException = null;
|
||||||
volatile Exception clientException = null;
|
volatile Exception clientException = null;
|
||||||
|
|
||||||
|
private boolean sslConnectionFailed() {
|
||||||
|
return clientException instanceof SSLHandshakeException;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
String keyFilename =
|
String keyFilename =
|
||||||
System.getProperty("test.src", "./") + "/" + pathToStores +
|
System.getProperty("test.src", "./") + "/" + pathToStores +
|
||||||
@ -233,7 +244,9 @@ public class Redirect {
|
|||||||
* Wait for other side to close down.
|
* Wait for other side to close down.
|
||||||
*/
|
*/
|
||||||
if (separateServerThread) {
|
if (separateServerThread) {
|
||||||
|
if (!sslConnectionFailed()) {
|
||||||
serverThread.join();
|
serverThread.join();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
clientThread.join();
|
clientThread.join();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user