8224603: Replace wildcard address with loopback or local host in tests - part 11
Fixes a batch of tests that were observed failing intermittently. Reviewed-by: chegar, vtewari
This commit is contained in:
parent
241c32ca51
commit
ee040e4be2
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,11 +27,14 @@
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.net.SimpleSSLContext
|
||||
* @run main/othervm -Dsun.net.httpserver.selCacheTimeout=2 SelCacheTest
|
||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true
|
||||
-Dsun.net.httpserver.selCacheTimeout=2 SelCacheTest
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
@ -53,10 +56,11 @@ public class SelCacheTest extends Test {
|
||||
HttpServer s1 = null;
|
||||
HttpsServer s2 = null;
|
||||
ExecutorService executor=null;
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
try {
|
||||
String root = System.getProperty("test.src")+ "/docs";
|
||||
System.out.print("Test1: ");
|
||||
InetSocketAddress addr = new InetSocketAddress (0);
|
||||
InetSocketAddress addr = new InetSocketAddress(loopback, 0);
|
||||
s1 = HttpServer.create(addr, 0);
|
||||
if (s1 instanceof HttpsServer) {
|
||||
throw new RuntimeException("should not be httpsserver");
|
||||
@ -75,14 +79,14 @@ public class SelCacheTest extends Test {
|
||||
|
||||
int port = s1.getAddress().getPort();
|
||||
int httpsport = s2.getAddress().getPort();
|
||||
test (true, "http", root+"/test1", port, "smallfile.txt", 23);
|
||||
test (true, "http", root+"/test1", port, "largefile.txt", 2730088);
|
||||
test (true, "https", root+"/test1", httpsport, "smallfile.txt", 23);
|
||||
test (true, "https", root+"/test1", httpsport, "largefile.txt", 2730088);
|
||||
test (false, "http", root+"/test1", port, "smallfile.txt", 23);
|
||||
test (false, "http", root+"/test1", port, "largefile.txt", 2730088);
|
||||
test (false, "https", root+"/test1", httpsport, "smallfile.txt", 23);
|
||||
test (false, "https", root+"/test1", httpsport, "largefile.txt", 2730088);
|
||||
test(true, "http", root+"/test1", loopback, port, "smallfile.txt", 23);
|
||||
test(true, "http", root+"/test1", loopback, port, "largefile.txt", 2730088);
|
||||
test(true, "https", root+"/test1", loopback, httpsport, "smallfile.txt", 23);
|
||||
test(true, "https", root+"/test1", loopback, httpsport, "largefile.txt", 2730088);
|
||||
test(false, "http", root+"/test1", loopback, port, "smallfile.txt", 23);
|
||||
test(false, "http", root+"/test1", loopback, port, "largefile.txt", 2730088);
|
||||
test(false, "https", root+"/test1", loopback, httpsport, "smallfile.txt", 23);
|
||||
test(false, "https", root+"/test1", loopback, httpsport, "largefile.txt", 2730088);
|
||||
System.out.println("OK");
|
||||
} finally {
|
||||
delay();
|
||||
@ -92,10 +96,16 @@ public class SelCacheTest extends Test {
|
||||
}
|
||||
}
|
||||
|
||||
static void test (boolean fixedLen, String protocol, String root, int port, String f, int size) throws Exception {
|
||||
static void test(boolean fixedLen, String protocol, String root,
|
||||
InetAddress address, int port, String f, int size) throws Exception {
|
||||
Thread.sleep(2000);
|
||||
URL url = new URL (protocol+"://localhost:"+port+"/test1/"+f);
|
||||
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
|
||||
URL url = URIBuilder.newBuilder()
|
||||
.scheme(protocol)
|
||||
.host(address)
|
||||
.port(port)
|
||||
.path("/test1/"+f)
|
||||
.toURL();
|
||||
HttpURLConnection urlc = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
|
||||
if (urlc instanceof HttpsURLConnection) {
|
||||
HttpsURLConnection urlcs = (HttpsURLConnection) urlc;
|
||||
urlcs.setHostnameVerifier(new HostnameVerifier() {
|
||||
|
@ -26,6 +26,7 @@
|
||||
* @bug 6725892
|
||||
* @library /test/lib
|
||||
* @run main/othervm -Dsun.net.httpserver.maxReqTime=2 Test
|
||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true -Dsun.net.httpserver.maxReqTime=2 Test
|
||||
* @summary
|
||||
*/
|
||||
|
||||
@ -69,8 +70,9 @@ public class Test {
|
||||
|
||||
ExecutorService exec = Executors.newCachedThreadPool();
|
||||
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
try {
|
||||
InetSocketAddress addr = new InetSocketAddress (0);
|
||||
InetSocketAddress addr = new InetSocketAddress(loopback, 0);
|
||||
s1 = HttpServer.create(addr, 100);
|
||||
HttpHandler h = new Handler();
|
||||
HttpContext c1 = s1.createContext("/", h);
|
||||
@ -126,7 +128,7 @@ public class Test {
|
||||
// send request and don't read response. Check server closes connection
|
||||
|
||||
static void test2() throws IOException {
|
||||
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
|
||||
HttpURLConnection urlc = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setReadTimeout(20 * 1000);
|
||||
InputStream is = urlc.getInputStream();
|
||||
// we won't read response and check if it times out
|
||||
@ -183,7 +185,7 @@ public class Test {
|
||||
InputStream is = null;
|
||||
|
||||
try {
|
||||
urlc = (HttpURLConnection) url.openConnection();
|
||||
urlc = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setReadTimeout(20 * 1000);
|
||||
urlc.setDoOutput(true);
|
||||
} catch (IOException e) {
|
||||
|
@ -27,7 +27,7 @@
|
||||
* @modules java.base/sun.net.www
|
||||
* @library ../../../sun/net/www/httptest/
|
||||
* @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction
|
||||
* @run main B4722333
|
||||
* @run main/othervm B4722333
|
||||
* @summary JRE Proxy Authentication Not Working with ISA2000
|
||||
*/
|
||||
|
||||
@ -154,8 +154,7 @@ public class B4722333 implements HttpCallback {
|
||||
|
||||
int count = 0;
|
||||
|
||||
public PasswordAuthentication getPasswordAuthentication ()
|
||||
{
|
||||
public PasswordAuthentication getPasswordAuthentication() {
|
||||
System.out.println("Auth called");
|
||||
String scheme = getRequestingScheme();
|
||||
System.out.println("getRequestingScheme() returns " + scheme);
|
||||
@ -173,7 +172,7 @@ public class B4722333 implements HttpCallback {
|
||||
}
|
||||
|
||||
public int getCount () {
|
||||
return (count);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2012, 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,6 +26,8 @@
|
||||
* @bug 4094894
|
||||
* @summary On W95/W98 it's not possible to send a datagram >12k
|
||||
* via the loopback address.
|
||||
* @run main Send12k
|
||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true Send12k
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
@ -43,21 +45,24 @@ public class Send12k {
|
||||
} else {
|
||||
SEND_SIZE = 16 * 1024;
|
||||
}
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
DatagramSocket s1 = new DatagramSocket();
|
||||
DatagramSocket s2 = new DatagramSocket();
|
||||
DatagramSocket s2 = new DatagramSocket(0, localHost);
|
||||
|
||||
byte b1[] = new byte[ SEND_SIZE ];
|
||||
DatagramPacket p1 = new DatagramPacket(b1, 0, b1.length,
|
||||
InetAddress.getLocalHost(),
|
||||
localHost,
|
||||
s2.getLocalPort());
|
||||
boolean sendOkay = true;
|
||||
try {
|
||||
System.out.println("Sending to: [" + localHost + "]:" + s2.getLocalPort());
|
||||
s1.send(p1);
|
||||
} catch (IOException e) {
|
||||
/*
|
||||
* Prior to merlin a send of > 12k to loopback address
|
||||
* would fail silently.
|
||||
*/
|
||||
System.out.println("Sending failed: " + e);
|
||||
sendOkay = false;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -51,7 +51,7 @@ public class CloseAvailable {
|
||||
static void testClose() throws IOException {
|
||||
boolean error = true;
|
||||
InetAddress addr = InetAddress.getLocalHost();
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
ServerSocket ss = new ServerSocket(0, 0, addr);
|
||||
int port = ss.getLocalPort();
|
||||
|
||||
Thread t = new Thread(new Thread("Close-Available-1") {
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -51,12 +51,13 @@ public class Restart {
|
||||
public static void main(String args[]) throws Exception {
|
||||
IPSupport.throwSkippedExceptionIfNonOperational();
|
||||
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
ServerSocket ss = new ServerSocket(0, 0, localHost);
|
||||
Socket s1 = null, s2 = null;
|
||||
try {
|
||||
int port = ss.getLocalPort();
|
||||
|
||||
s1 = new Socket(InetAddress.getLocalHost(), port);
|
||||
s1 = new Socket(localHost, port);
|
||||
s2 = ss.accept();
|
||||
|
||||
// close server socket and the accepted connection
|
||||
@ -64,7 +65,7 @@ public class Restart {
|
||||
s2.close();
|
||||
|
||||
ss = new ServerSocket();
|
||||
ss.bind( new InetSocketAddress(port) );
|
||||
ss.bind( new InetSocketAddress(localHost, port) );
|
||||
ss.close();
|
||||
|
||||
// close the client socket
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,6 +27,7 @@
|
||||
* @run main/othervm BadProxySelector
|
||||
*/
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
@ -41,13 +42,13 @@ import java.io.*;
|
||||
public class BadProxySelector {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ProxySelector.setDefault(new HTTPProxySelector());
|
||||
try (ServerSocket ss = new ServerSocket(0);
|
||||
try (ServerSocket ss = new ServerSocket(0, 0, InetAddress.getLocalHost());
|
||||
Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
|
||||
Socket s2 = ss.accept()) {
|
||||
}
|
||||
|
||||
ProxySelector.setDefault(new NullHTTPProxySelector());
|
||||
try (ServerSocket ss = new ServerSocket(0);
|
||||
try (ServerSocket ss = new ServerSocket(0, 0, InetAddress.getLocalHost());
|
||||
Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
|
||||
Socket s2 = ss.accept()) {
|
||||
}
|
||||
@ -60,6 +61,7 @@ public class BadProxySelector {
|
||||
|
||||
@Override
|
||||
public List<Proxy> select(URI uri) {
|
||||
System.out.println(this.getClass().getSimpleName() + " called for " + uri);
|
||||
List<Proxy> proxies = new ArrayList<>();
|
||||
proxies.add(new Proxy(Proxy.Type.HTTP,
|
||||
new InetSocketAddress("localhost", 0)));
|
||||
@ -75,6 +77,7 @@ public class BadProxySelector {
|
||||
|
||||
@Override
|
||||
public List<Proxy> select(URI uri) {
|
||||
System.out.println(this.getClass().getSimpleName() + " called for " + uri);
|
||||
List<Proxy> proxies = new ArrayList<>();
|
||||
proxies.add(null);
|
||||
proxies.add(new Proxy(Proxy.Type.HTTP,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -51,7 +51,7 @@ public class SocksProxyVersion implements Runnable {
|
||||
}
|
||||
|
||||
public SocksProxyVersion() throws Exception {
|
||||
ss = new ServerSocket(0);
|
||||
ss = new ServerSocket(0, 0, InetAddress.getLocalHost());
|
||||
int port = ss.getLocalPort();
|
||||
Thread serverThread = new Thread(this);
|
||||
serverThread.start();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -29,6 +29,7 @@ import java.net.URLPermission;
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.net.SimpleSSLContext
|
||||
* @run main/othervm URLTest
|
||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true URLTest
|
||||
* @summary check URLPermission with Http(s)URLConnection
|
||||
*/
|
||||
|
||||
@ -77,14 +78,14 @@ public class URLTest {
|
||||
if (sm != null) {
|
||||
expectException = true;
|
||||
Policy.setPolicy(new CustomPolicy(
|
||||
new URLPermission("http://127.0.0.1:"+httpPort+"/foo.html", "GET:X-Foo,Z-Bar"),
|
||||
new URLPermission("https://127.0.0.1:"+httpsPort+"/foo.html", "POST:X-Fob,T-Bar")));
|
||||
new URLPermission("http://" + httpAuth + "/foo.html", "GET:X-Foo,Z-Bar"),
|
||||
new URLPermission("https://" + httpsAuth + "/foo.html", "POST:X-Fob,T-Bar")));
|
||||
}
|
||||
|
||||
String url1 = "http://127.0.0.1:"+httpPort+"/foo.html";
|
||||
String url2 = "https://127.0.0.1:"+httpsPort+"/foo.html";
|
||||
String url3 = "http://127.0.0.1:"+httpPort+"/bar.html";
|
||||
String url4 = "https://127.0.0.1:"+httpsPort+"/bar.html";
|
||||
String url1 = "http://" + httpAuth + "/foo.html";
|
||||
String url2 = "https://" + httpsAuth + "/foo.html";
|
||||
String url3 = "http://" + httpAuth + "/bar.html";
|
||||
String url4 = "https://" + httpsAuth + "/bar.html";
|
||||
|
||||
// simple positive test. Should succeed
|
||||
test(url1, "GET", "X-Foo");
|
||||
@ -108,14 +109,14 @@ public class URLTest {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
Policy.setPolicy(new CustomPolicy(
|
||||
new URLPermission("http://127.0.0.1:"+httpPort+"/*", "GET:X-Foo"),
|
||||
new URLPermission("https://127.0.0.1:"+httpsPort+"/*", "POST:X-Fob")));
|
||||
new URLPermission("http://" + httpAuth + "/*", "GET:X-Foo"),
|
||||
new URLPermission("https://" + httpsAuth + "/*", "POST:X-Fob")));
|
||||
}
|
||||
|
||||
String url1 = "http://127.0.0.1:"+httpPort+"/foo.html";
|
||||
String url2 = "https://127.0.0.1:"+httpsPort+"/foo.html";
|
||||
String url3 = "http://127.0.0.1:"+httpPort+"/bar.html";
|
||||
String url4 = "https://127.0.0.1:"+httpsPort+"/bar.html";
|
||||
String url1 = "http://" + httpAuth + "/foo.html";
|
||||
String url2 = "https://" + httpsAuth + "/foo.html";
|
||||
String url3 = "http://" + httpAuth + "/bar.html";
|
||||
String url4 = "https://" + httpsAuth + "/bar.html";
|
||||
|
||||
// simple positive test. Should succeed
|
||||
test(url1, "GET", "X-Foo");
|
||||
@ -132,14 +133,14 @@ public class URLTest {
|
||||
if (sm != null) {
|
||||
expectException = true;
|
||||
Policy.setPolicy(new CustomPolicy(
|
||||
new URLPermission("http://127.0.0.1:"+httpPort+"/a/b/-", "DELETE,GET:X-Foo,Y-Foo"),
|
||||
new URLPermission("https://127.0.0.1:"+httpsPort+"/a/c/-", "POST:*")));
|
||||
new URLPermission("http://" + httpAuth + "/a/b/-", "DELETE,GET:X-Foo,Y-Foo"),
|
||||
new URLPermission("https://" + httpsAuth + "/a/c/-", "POST:*")));
|
||||
}
|
||||
|
||||
String url1 = "http://127.0.0.1:"+httpPort+"/foo.html";
|
||||
String url2 = "https://127.0.0.1:"+httpsPort+"/a/c/d/e/foo.html";
|
||||
String url3 = "http://127.0.0.1:"+httpPort+"/a/b/c";
|
||||
String url4 = "https://127.0.0.1:"+httpsPort+"/a/b/c";
|
||||
String url1 = "http://" + httpAuth + "/foo.html";
|
||||
String url2 = "https://" + httpsAuth + "/a/c/d/e/foo.html";
|
||||
String url3 = "http://" + httpAuth + "/a/b/c";
|
||||
String url4 = "https://" + httpsAuth + "/a/b/c";
|
||||
|
||||
test(url1, "GET", "X-Foo", expectException);
|
||||
test(url2, "POST", "X-Zxc");
|
||||
@ -147,6 +148,16 @@ public class URLTest {
|
||||
test(url4, "POST", "Y-Foo", expectException);
|
||||
}
|
||||
|
||||
static String authority(InetSocketAddress address) {
|
||||
String hostaddr = address.getAddress().getHostAddress();
|
||||
int port = address.getPort();
|
||||
if (hostaddr.indexOf(':') > -1) {
|
||||
return "[" + hostaddr + "]:" + port;
|
||||
} else {
|
||||
return hostaddr + ":" + port;
|
||||
}
|
||||
}
|
||||
|
||||
// Convenience methods to simplify previous explicit test scenarios.
|
||||
static void test(String u, String method, String header) throws IOException {
|
||||
test(u, method, header, null, false);
|
||||
@ -175,7 +186,7 @@ public class URLTest {
|
||||
System.out.println("url=" + u + " method=" + method +
|
||||
" header1=" + header1 + " header2=" + header2 +
|
||||
" expectException=" + expectException);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
if (urlc instanceof HttpsURLConnection) {
|
||||
HttpsURLConnection ssl = (HttpsURLConnection)urlc;
|
||||
ssl.setHostnameVerifier((host, sess) -> true);
|
||||
@ -220,11 +231,14 @@ public class URLTest {
|
||||
static SSLContext ctx;
|
||||
static int httpPort;
|
||||
static int httpsPort;
|
||||
static String httpAuth;
|
||||
static String httpsAuth;
|
||||
|
||||
static void createServers() throws Exception {
|
||||
InetSocketAddress any = new InetSocketAddress(0);
|
||||
httpServer = HttpServer.create(any, 0);
|
||||
httpsServer = HttpsServer.create(any, 0);
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
InetSocketAddress address = new InetSocketAddress(loopback, 0);
|
||||
httpServer = HttpServer.create(address, 0);
|
||||
httpsServer = HttpsServer.create(address, 0);
|
||||
|
||||
OkHandler h = new OkHandler();
|
||||
|
||||
@ -243,6 +257,8 @@ public class URLTest {
|
||||
|
||||
httpPort = httpServer.getAddress().getPort();
|
||||
httpsPort = httpsServer.getAddress().getPort();
|
||||
httpAuth = authority(httpServer.getAddress());
|
||||
httpsAuth = authority(httpsServer.getAddress());
|
||||
}
|
||||
|
||||
static void shutdown() {
|
||||
@ -265,7 +281,9 @@ public class URLTest {
|
||||
java.util.Arrays.stream(permissions).forEach(perms::add);
|
||||
|
||||
// needed for the HTTP(S) server
|
||||
perms.add(new SocketPermission("localhost:1024-", "listen,resolve,accept"));
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
InetSocketAddress serverBound = new InetSocketAddress(loopback,1024);
|
||||
perms.add(new SocketPermission(authority(serverBound) + "-", "listen,resolve,accept"));
|
||||
// needed by the test to reset the policy, per testX method
|
||||
perms.add(new SecurityPermission("setPolicy"));
|
||||
// needed to shutdown the ThreadPoolExecutor ( used by the servers )
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,7 +24,10 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 5054016
|
||||
* @library /test/lib
|
||||
* @summary get the failure immediately when writing individual chunks over socket fail
|
||||
* @run main CheckError
|
||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true CheckError
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -33,11 +36,16 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import static java.lang.System.out;
|
||||
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
|
||||
public class CheckError {
|
||||
|
||||
static int BUFFER_SIZE = 8192; // 8k
|
||||
@ -51,8 +59,13 @@ public class CheckError {
|
||||
out.println("Server listening on " + port);
|
||||
|
||||
|
||||
URL url = new URL("http://localhost:" + port);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
URL url = URIBuilder.newBuilder()
|
||||
.scheme("http")
|
||||
.host(server.getAddress())
|
||||
.port(port)
|
||||
.toURL();
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
conn.setChunkedStreamingMode(1024);
|
||||
@ -98,13 +111,19 @@ public class CheckError {
|
||||
final ServerSocket serverSocket;
|
||||
|
||||
HTTPServer() throws IOException {
|
||||
serverSocket = new ServerSocket(0);
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
serverSocket = new ServerSocket();
|
||||
serverSocket.bind(new InetSocketAddress(loopback, 0));
|
||||
}
|
||||
|
||||
int getPort() {
|
||||
return serverSocket.getLocalPort();
|
||||
}
|
||||
|
||||
InetAddress getAddress() {
|
||||
return serverSocket.getInetAddress();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try (Socket client = serverSocket.accept()) {
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -221,6 +221,7 @@ public class TestHttpServer {
|
||||
listenerKey = schan.register (selector, SelectionKey.OP_ACCEPT);
|
||||
} catch (IOException e) {
|
||||
System.err.println ("Server could not start: " + e);
|
||||
throw new RuntimeException("Server could not start: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,6 +27,7 @@
|
||||
* @modules java.base/sun.net.www
|
||||
* @build TestHttpsServer HttpCallback
|
||||
* @run main/othervm ChunkedOutputStream
|
||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true ChunkedOutputStream
|
||||
*
|
||||
* SunJSSE does not support dynamic system properties, no way to re-use
|
||||
* system properties in samevm/agentvm mode.
|
||||
@ -157,7 +158,7 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
static void test1(String u) throws Exception {
|
||||
URL url = new URL(u);
|
||||
System.out.println("client opening connection to: " + u);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setChunkedStreamingMode(20);
|
||||
urlc.setDoOutput(true);
|
||||
urlc.setRequestMethod("POST");
|
||||
@ -174,7 +175,7 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
static void test3(String u) throws Exception {
|
||||
URL url = new URL(u);
|
||||
System.out.println("client opening connection to: " + u);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setFixedLengthStreamingMode(str2.length());
|
||||
urlc.setDoOutput(true);
|
||||
urlc.setRequestMethod("POST");
|
||||
@ -191,7 +192,7 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
static void test4(String u) throws Exception {
|
||||
URL url = new URL(u);
|
||||
System.out.println("client opening connection to: " + u);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setFixedLengthStreamingMode(str2.length()+1);
|
||||
urlc.setDoOutput(true);
|
||||
urlc.setRequestMethod("POST");
|
||||
@ -208,7 +209,7 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
static void test5(String u) throws Exception {
|
||||
URL url = new URL(u);
|
||||
System.out.println("client opening connection to: " + u);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setFixedLengthStreamingMode(str2.length()-1);
|
||||
urlc.setDoOutput(true);
|
||||
urlc.setRequestMethod("POST");
|
||||
@ -224,7 +225,7 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
static void test6(String u) throws Exception {
|
||||
URL url = new URL(u);
|
||||
System.out.println("client opening connection to: " + u);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setChunkedStreamingMode(20);
|
||||
urlc.setDoOutput(true);
|
||||
urlc.setRequestMethod("POST");
|
||||
@ -249,7 +250,7 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
static void test7(String u) throws Exception {
|
||||
URL url = new URL(u);
|
||||
System.out.println("client opening connection to: " + u);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setChunkedStreamingMode(20);
|
||||
urlc.setDoOutput(true);
|
||||
urlc.setRequestMethod("POST");
|
||||
@ -264,7 +265,7 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
static void test8(String u) throws Exception {
|
||||
URL url = new URL(u);
|
||||
System.out.println("client opening connection to: " + u);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||
urlc.setFixedLengthStreamingMode(0);
|
||||
urlc.setDoOutput(true);
|
||||
urlc.setRequestMethod("POST");
|
||||
@ -287,6 +288,8 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
System.getProperty("test.src", "./") + "/" + pathToStores +
|
||||
"/" + trustStoreFile;
|
||||
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
|
||||
HostnameVerifier reservedHV =
|
||||
HttpsURLConnection.getDefaultHostnameVerifier();
|
||||
try {
|
||||
@ -298,17 +301,17 @@ public class ChunkedOutputStream implements HttpCallback {
|
||||
|
||||
try {
|
||||
server = new TestHttpsServer(
|
||||
new ChunkedOutputStream(), 1, 10, 0);
|
||||
System.out.println ("Server started: listening on port: " + server.getLocalPort());
|
||||
new ChunkedOutputStream(), 1, 10, loopback, 0);
|
||||
System.out.println("Server started: listening on: " + server.getAuthority());
|
||||
// the test server doesn't support keep-alive yet
|
||||
// test1("http://localhost:"+server.getLocalPort()+"/d0");
|
||||
test1("https://localhost:"+server.getLocalPort()+"/d01");
|
||||
test3("https://localhost:"+server.getLocalPort()+"/d3");
|
||||
test4("https://localhost:"+server.getLocalPort()+"/d4");
|
||||
test5("https://localhost:"+server.getLocalPort()+"/d5");
|
||||
test6("https://localhost:"+server.getLocalPort()+"/d6");
|
||||
test7("https://localhost:"+server.getLocalPort()+"/d7");
|
||||
test8("https://localhost:"+server.getLocalPort()+"/d8");
|
||||
// test1("http://" + server.getAuthority() + "/d0");
|
||||
test1("https://" + server.getAuthority() + "/d01");
|
||||
test3("https://" + server.getAuthority() + "/d3");
|
||||
test4("https://" + server.getAuthority() + "/d4");
|
||||
test5("https://" + server.getAuthority() + "/d5");
|
||||
test6("https://" + server.getAuthority() + "/d6");
|
||||
test7("https://" + server.getAuthority() + "/d7");
|
||||
test8("https://" + server.getAuthority() + "/d8");
|
||||
} catch (Exception e) {
|
||||
if (server != null) {
|
||||
server.terminate();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -106,11 +106,33 @@ public class TestHttpsServer {
|
||||
* @param port the port number to bind the server to. <code>Zero</code>
|
||||
* means choose any free port.
|
||||
*/
|
||||
|
||||
public TestHttpsServer(HttpCallback cb, int threads, int cperthread, int port)
|
||||
throws IOException {
|
||||
this(cb, threads, cperthread, null, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>TestHttpsServer<code> instance with the specified number
|
||||
* of threads and maximum number of connections per thread and running on
|
||||
* the specified port. The specified number of threads are created to
|
||||
* handle incoming requests, and each thread is allowed
|
||||
* to handle a number of simultaneous TCP connections.
|
||||
* @param cb the callback object which is invoked to handle
|
||||
* each incoming request
|
||||
* @param threads the number of threads to create to handle
|
||||
* requests in parallel
|
||||
* @param cperthread the number of simultaneous TCP connections
|
||||
* to handle per thread
|
||||
* @param address the InetAddress to bind to. {@code Null} means the
|
||||
* wildcard address.
|
||||
* @param port the port number to bind the server to. {@code Zero}
|
||||
* means choose any free port.
|
||||
*/
|
||||
|
||||
public TestHttpsServer(HttpCallback cb, int threads, int cperthread, InetAddress address, int port)
|
||||
throws IOException {
|
||||
schan = ServerSocketChannel.open();
|
||||
InetSocketAddress addr = new InetSocketAddress (port);
|
||||
InetSocketAddress addr = new InetSocketAddress(address, port);
|
||||
schan.socket().bind(addr);
|
||||
this.threads = threads;
|
||||
this.cb = cb;
|
||||
@ -165,6 +187,14 @@ public class TestHttpsServer {
|
||||
return schan.socket().getLocalPort ();
|
||||
}
|
||||
|
||||
public String getAuthority() {
|
||||
InetAddress address = schan.socket().getInetAddress();
|
||||
String hostaddr = address.getHostAddress();
|
||||
if (address.isAnyLocalAddress()) hostaddr = "localhost";
|
||||
if (hostaddr.indexOf(':') > -1) hostaddr = "[" + hostaddr + "]";
|
||||
return hostaddr + ":" + getLocalPort();
|
||||
}
|
||||
|
||||
static class Server extends Thread {
|
||||
|
||||
ServerSocketChannel schan;
|
||||
|
Loading…
x
Reference in New Issue
Block a user