8225512: Replace wildcard address with loopback or local host in tests - part 15
Summary: Updates httpserver tests to use the loopback instead of the wildcard wherever possible.
Reviewed-by: michaelm
--- a/test/jdk/com/sun/net/httpserver/MissingTrailingSpace.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/MissingTrailingSpace.java Tue Jun 11 15:46:26 2019 +0100
@@ -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
@@ -25,9 +25,12 @@
* @test
* @bug 8068795
* @summary HttpServer missing tailing space for some response codes
+ * @run main MissingTrailingSpace
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true MissingTrailingSpace
* @author lev.priima@oracle.com
*/
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.io.InputStreamReader;
import java.io.IOException;
@@ -47,7 +50,8 @@
private static final String someContext = "/context";
public static void main(String[] args) throws Exception {
- HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ HttpServer server = HttpServer.create(new InetSocketAddress(loopback, 0), 0);
try {
server.setExecutor(Executors.newFixedThreadPool(1));
server.createContext(someContext, new HttpHandler() {
@@ -68,7 +72,7 @@
System.out.println("Server started at port "
+ server.getAddress().getPort());
- runRawSocketHttpClient("localhost", server.getAddress().getPort());
+ runRawSocketHttpClient(loopback, server.getAddress().getPort());
} finally {
((ExecutorService)server.getExecutor()).shutdown();
server.stop(0);
@@ -76,7 +80,7 @@
System.out.println("Server finished.");
}
- static void runRawSocketHttpClient(String hostname, int port)
+ static void runRawSocketHttpClient(InetAddress address, int port)
throws Exception
{
Socket socket = null;
@@ -84,7 +88,7 @@
BufferedReader reader = null;
final String CRLF = "\r\n";
try {
- socket = new Socket(hostname, port);
+ socket = new Socket(address, port);
writer = new PrintWriter(new OutputStreamWriter(
socket.getOutputStream()));
System.out.println("Client connected by socket: " + socket);
@@ -93,7 +97,7 @@
writer.print("User-Agent: Java/"
+ System.getProperty("java.version")
+ CRLF);
- writer.print("Host: " + hostname + CRLF);
+ writer.print("Host: " + address.getHostName() + CRLF);
writer.print("Accept: */*" + CRLF);
writer.print("Connection: keep-alive" + CRLF);
writer.print(CRLF); // Important, else the server will expect that
@@ -140,4 +144,3 @@
System.out.println("Client finished." );
}
}
-
--- a/test/jdk/com/sun/net/httpserver/Test10.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test10.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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 7005016
* @summary pit jdk7 b121 sqe test jhttp/HttpServer150013 failing
* @run main/othervm -Dsun.net.httpserver.clockTick=1000 -Dsun.net.httpserver.idleInterval=3 Test10
+ * @run main/othervm -Dsun.net.httpserver.clockTick=1000 -Dsun.net.httpserver.idleInterval=3
+ * -Djava.net.preferIPv6Addresses Test10
*/
import com.sun.net.httpserver.*;
@@ -42,7 +44,8 @@
public static void main (String[] args) throws Exception {
System.out.print ("Test10: ");
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
int port = server.getAddress().getPort();
HttpContext c2 = server.createContext ("/test", handler);
@@ -78,7 +81,7 @@
public static void doClient (int port) throws Exception {
String s = "GET /test/1.html HTTP/1.1\r\n\r\n";
- Socket socket = new Socket ("localhost", port);
+ Socket socket = new Socket (InetAddress.getLoopbackAddress(), port);
OutputStream os = socket.getOutputStream();
os.write (s.getBytes());
socket.setSoTimeout (10 * 1000);
--- a/test/jdk/com/sun/net/httpserver/Test11.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test11.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,12 +25,16 @@
* @test
* @bug 6270015
* @summary Light weight HTTP server
+ * @library /test/lib
+ * @run main Test11
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test11
*/
import java.net.*;
import java.util.concurrent.*;
import java.io.*;
import com.sun.net.httpserver.*;
+import jdk.test.lib.net.URIBuilder;
public class Test11 {
static class Handler implements HttpHandler {
@@ -51,7 +55,8 @@
public static void main (String[] args) throws Exception {
System.out.print ("Test 11: ");
- HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ HttpServer server = HttpServer.create(new InetSocketAddress(loopback, 0), 0);
ExecutorService s = Executors.newCachedThreadPool();
try {
HttpContext ctx = server.createContext (
@@ -59,9 +64,13 @@
);
s = Executors.newCachedThreadPool();
server.start ();
- URL url = new URL ("http://localhost:" + server.getAddress().getPort()+
- "/Foo/bar/test.html");
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/Foo/bar/test.html")
+ .toURL();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
int r = urlc.getResponseCode();
if (r == 200) {
throw new RuntimeException ("wrong response received");
--- a/test/jdk/com/sun/net/httpserver/Test12.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test12.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 @@
* @library /test/lib
* @build jdk.test.lib.net.SimpleSSLContext
* @run main/othervm Test12
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test12
* @summary Light weight HTTP server
*/
@@ -37,6 +38,7 @@
import java.net.*;
import javax.net.ssl.*;
import jdk.test.lib.net.SimpleSSLContext;
+import jdk.test.lib.net.URIBuilder;
/* basic http/s connectivity test
* Tests:
@@ -56,7 +58,8 @@
try {
String root = System.getProperty ("test.src")+ "/docs";
System.out.print ("Test12: ");
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
s1 = HttpServer.create (addr, 0);
s2 = HttpsServer.create (addr, 0);
HttpHandler h = new FileServerHandler (root);
@@ -130,8 +133,13 @@
public void run () {
try {
- URL url = new URL (protocol+"://localhost:"+port+"/test1/"+f);
- HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
+ URL url = URIBuilder.newBuilder()
+ .scheme(protocol)
+ .loopback()
+ .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 () {
--- a/test/jdk/com/sun/net/httpserver/Test13.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test13.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 @@
* @library /test/lib
* @build jdk.test.lib.net.SimpleSSLContext
* @run main/othervm Test13
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test13
* @summary Light weight HTTP server
*/
@@ -38,6 +39,7 @@
import java.net.*;
import javax.net.ssl.*;
import jdk.test.lib.net.SimpleSSLContext;
+import jdk.test.lib.net.URIBuilder;
/* basic http/s connectivity test
* Tests:
@@ -61,10 +63,12 @@
ha.setLevel(Level.ALL);
l.setLevel(Level.ALL);
l.addHandler(ha);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+
try {
String root = System.getProperty ("test.src")+ "/docs";
System.out.print ("Test13: ");
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
s1 = HttpServer.create (addr, 0);
s2 = HttpsServer.create (addr, 0);
HttpHandler h = new FileServerHandler (root);
@@ -136,8 +140,13 @@
public void run () {
try {
- URL url = new URL (protocol+"://localhost:"+port+"/test1/"+f);
- HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
+ URL url = URIBuilder.newBuilder()
+ .scheme(protocol)
+ .loopback()
+ .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 () {
--- a/test/jdk/com/sun/net/httpserver/Test14.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test14.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,6 +25,9 @@
* @test
* @bug 6270015
* @summary Light weight HTTP server
+ * @library /test/lib
+ * @run main Test14
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test14
*/
import com.sun.net.httpserver.*;
@@ -36,6 +39,7 @@
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
/**
* Test filters
@@ -77,7 +81,8 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
@@ -94,9 +99,14 @@
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
System.out.print ("Test14: " );
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
InputStream is = urlc.getInputStream();
int x = 0;
String output="";
--- a/test/jdk/com/sun/net/httpserver/Test2.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test2.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,6 +25,9 @@
* @test
* @bug 6270015
* @summary Light weight HTTP server
+ * @library /test/lib
+ * @run main Test2
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test2
*/
import com.sun.net.httpserver.*;
@@ -36,6 +39,7 @@
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
/**
* Test authentication
@@ -45,7 +49,8 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
BasicAuthenticator a = new BasicAuthenticator ("foobar@test.realm") {
@@ -60,9 +65,15 @@
server.start ();
java.net.Authenticator.setDefault (new MyAuthenticator());
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+
System.out.print ("Test2: " );
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
InputStream is = urlc.getInputStream();
int c = 0;
while (is.read()!= -1) {
--- a/test/jdk/com/sun/net/httpserver/Test3.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test3.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 6270015
* @summary Light weight HTTP server
* @run main/othervm -Dsun.net.httpserver.idleInterval=4 Test3
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true
+ * -Dsun.net.httpserver.idleInterval=4 Test3
*/
import com.sun.net.httpserver.*;
@@ -48,7 +50,8 @@
public static void main (String[] args) throws Exception {
System.out.print ("Test3: ");
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
int port = server.getAddress().getPort();
HttpContext c2 = server.createContext ("/test", handler);
@@ -135,7 +138,7 @@
"GET /test/4.html HTTP/1.1\r\nContent-length: 10\r\n"+
"\r\n"+body4;
- Socket socket = new Socket ("localhost", port);
+ Socket socket = new Socket (InetAddress.getLoopbackAddress(), port);
OutputStream os = socket.getOutputStream();
os.write (s.getBytes());
InputStream is = socket.getInputStream();
--- a/test/jdk/com/sun/net/httpserver/Test4.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test4.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 6270015
* @summary Light weight HTTP server
* @run main/othervm -Dsun.net.httpserver.idleInterval=4 Test4
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true
+ * -Dsun.net.httpserver.idleInterval=4 Test4
*/
import com.sun.net.httpserver.*;
@@ -46,7 +48,8 @@
public static void main (String[] args) throws Exception {
System.out.print ("Test4: ");
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
int port = server.getAddress().getPort();
HttpContext c2 = server.createContext ("/test", handler);
@@ -133,7 +136,7 @@
"GET /test/4.html HTTP/1.1\r\nContent-length: 10\r\n"+
"\r\n"+body4;
- Socket socket = new Socket ("localhost", port);
+ Socket socket = new Socket (InetAddress.getLoopbackAddress(), port);
OutputStream os = socket.getOutputStream();
os.write (s.getBytes());
InputStream is = socket.getInputStream();
--- a/test/jdk/com/sun/net/httpserver/Test5.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test5.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 6270015
* @summary Light weight HTTP server
* @run main/othervm -Dsun.net.httpserver.idleInterval=4 Test5
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true
+ * -Dsun.net.httpserver.idleInterval=4 Test5
*/
import com.sun.net.httpserver.*;
@@ -47,7 +49,8 @@
public static void main (String[] args) throws Exception {
System.out.print ("Test5: ");
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
int port = server.getAddress().getPort();
HttpContext c2 = server.createContext ("/test", handler);
@@ -132,7 +135,7 @@
"GET /test/4.html HTTP/1.1\r\nContent-length: 10\r\n"+
"\r\n"+body4;
- Socket socket = new Socket ("localhost", port);
+ Socket socket = new Socket (InetAddress.getLoopbackAddress(), port);
OutputStream os = socket.getOutputStream();
os.write (s.getBytes());
InputStream is = socket.getInputStream();
--- a/test/jdk/com/sun/net/httpserver/Test6.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test6.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,6 +25,9 @@
* @test
* @bug 6270015
* @summary Light weight HTTP server
+ * @library /test/lib
+ * @run main Test6
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test6
*/
import com.sun.net.httpserver.*;
@@ -36,6 +39,7 @@
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
/**
* Test POST large file via chunked encoding (unusually small chunks)
@@ -45,16 +49,23 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+
System.out.print ("Test6: " );
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
urlc.setDoOutput (true);
urlc.setRequestMethod ("POST");
urlc.setChunkedStreamingMode (32); // small chunks
--- a/test/jdk/com/sun/net/httpserver/Test7.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test7.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 6270015
+ * @library /test/lib
* @summary Light weight HTTP server
+ * @run main Test7
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test7
*/
import com.sun.net.httpserver.*;
@@ -36,6 +39,7 @@
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
/**
* Test POST large file via chunked encoding (large chunks)
@@ -45,16 +49,22 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
System.out.print ("Test7: " );
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
urlc.setDoOutput (true);
urlc.setRequestMethod ("POST");
urlc.setChunkedStreamingMode (16 * 1024); // big chunks
--- a/test/jdk/com/sun/net/httpserver/Test7a.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test7a.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,8 +25,9 @@
* @test
* @bug 6270015
* @library /test/lib
- * @build jdk.test.lib.net.SimpleSSLContext
+ * @build jdk.test.lib.net.SimpleSSLContext jdk.test.lib.net.URIBuilder
* @run main/othervm Test7a
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test7a
* @summary Light weight HTTP server
*/
@@ -37,6 +38,7 @@
import java.net.*;
import javax.net.ssl.*;
import jdk.test.lib.net.SimpleSSLContext;
+import jdk.test.lib.net.URIBuilder;
/**
* Test POST large file via chunked encoding (large chunks)
@@ -51,7 +53,8 @@
//h.setLevel (Level.ALL);
//log.addHandler (h);
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpsServer server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
@@ -60,9 +63,15 @@
server.setExecutor (executor);
server.start ();
- URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+ URL url = URIBuilder.newBuilder()
+ .scheme("https")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+
System.out.print ("Test7a: " );
- HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
+ HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection(Proxy.NO_PROXY);
urlc.setDoOutput (true);
urlc.setRequestMethod ("POST");
urlc.setChunkedStreamingMode (16 * 1024); // big chunks
--- a/test/jdk/com/sun/net/httpserver/Test8.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test8.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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 6270015
+ * @library /test/lib
* @summary Light weight HTTP server
+ * @run main Test8
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test8
*/
import com.sun.net.httpserver.*;
@@ -36,6 +39,7 @@
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
/**
* Test POST large file via fixed len encoding
@@ -45,16 +49,23 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+
System.out.print ("Test8: " );
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
urlc.setDoOutput (true);
urlc.setRequestMethod ("POST");
OutputStream os = new BufferedOutputStream (urlc.getOutputStream());
--- a/test/jdk/com/sun/net/httpserver/Test8a.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test8a.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,8 +25,9 @@
* @test
* @bug 6270015
* @library /test/lib
- * @build jdk.test.lib.net.SimpleSSLContext
+ * @build jdk.test.lib.net.SimpleSSLContext jdk.test.lib.net.URIBuilder
* @run main/othervm Test8a
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test8a
* @summary Light weight HTTP server
*/
@@ -37,6 +38,7 @@
import java.net.*;
import javax.net.ssl.*;
import jdk.test.lib.net.SimpleSSLContext;
+import jdk.test.lib.net.URIBuilder;
/**
* Test POST large file via fixed len encoding
@@ -54,7 +56,8 @@
ExecutorService executor = null;
try {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
executor = Executors.newCachedThreadPool();
@@ -63,9 +66,15 @@
server.setExecutor (executor);
server.start ();
- URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
+ URL url = URIBuilder.newBuilder()
+ .scheme("https")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+
System.out.print ("Test8a: " );
- HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
+ HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection(Proxy.NO_PROXY);
urlc.setDoOutput (true);
urlc.setRequestMethod ("POST");
urlc.setHostnameVerifier (new DummyVerifier());
--- a/test/jdk/com/sun/net/httpserver/Test9.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test9.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,8 +25,9 @@
* @test
* @bug 6270015
* @library /test/lib
- * @build jdk.test.lib.net.SimpleSSLContext
+ * @build jdk.test.lib.net.SimpleSSLContext jdk.test.lib.net.URIBuilder
* @run main/othervm Test9
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test9
* @summary Light weight HTTP server
*/
@@ -37,6 +38,7 @@
import java.net.*;
import javax.net.ssl.*;
import jdk.test.lib.net.SimpleSSLContext;
+import jdk.test.lib.net.URIBuilder;
/* Same as Test1 but requests run in parallel.
*/
@@ -53,7 +55,8 @@
try {
String root = System.getProperty ("test.src")+ "/docs";
System.out.print ("Test9: ");
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
s1 = HttpServer.create (addr, 0);
s2 = HttpsServer.create (addr, 0);
HttpHandler h = new FileServerHandler (root);
@@ -137,8 +140,14 @@
public void run () {
try {
- URL url = new URL (protocol+"://localhost:"+port+"/test1/"+f);
- HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
+ URL url = URIBuilder.newBuilder()
+ .scheme(protocol)
+ .loopback()
+ .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 () {
@@ -185,7 +194,8 @@
String orig = root + "/" + f;
compare (new File(orig), temp);
temp.delete();
- } catch (IOException e) {
+ } catch (Exception e) {
+ e.printStackTrace();
error = true;
}
}
--- a/test/jdk/com/sun/net/httpserver/Test9a.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/Test9a.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,8 +25,9 @@
* @test
* @bug 6270015
* @library /test/lib
- * @build jdk.test.lib.net.SimpleSSLContext
+ * @build jdk.test.lib.net.SimpleSSLContext jdk.test.lib.net.URIBuilder
* @run main/othervm Test9a
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true Test9a
* @summary Light weight HTTP server
*/
@@ -37,6 +38,7 @@
import java.net.*;
import javax.net.ssl.*;
import jdk.test.lib.net.SimpleSSLContext;
+import jdk.test.lib.net.URIBuilder;
/* Same as Test1 but requests run in parallel.
*/
@@ -53,7 +55,8 @@
try {
String root = System.getProperty ("test.src")+ "/docs";
System.out.print ("Test9a: ");
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
server = HttpsServer.create (addr, 0);
HttpHandler h = new FileServerHandler (root);
HttpContext c1 = server.createContext ("/test1", h);
@@ -131,8 +134,14 @@
public void run () {
try {
- URL url = new URL (protocol+"://localhost:"+port+"/test1/"+f);
- HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
+ URL url = URIBuilder.newBuilder()
+ .scheme(protocol)
+ .loopback()
+ .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 () {
@@ -179,7 +188,7 @@
String orig = root + "/" + f;
compare (new File(orig), temp);
temp.delete();
- } catch (IOException e) {
+ } catch (Exception e) {
e.printStackTrace();
error = true;
}
--- a/test/jdk/com/sun/net/httpserver/TestLogging.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/TestLogging.java Tue Jun 11 15:46:26 2019 +0100
@@ -26,6 +26,8 @@
* @bug 6422914
* @library /test/lib
* @summary change httpserver exception printouts
+ * @run main TestLogging
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true TestLogging
*/
import com.sun.net.httpserver.*;
@@ -49,7 +51,8 @@
try {
System.out.print ("Test9: ");
String root = System.getProperty ("test.src")+ "/docs";
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
Logger logger = Logger.getLogger ("com.sun.net.httpserver");
logger.setLevel (Level.ALL);
Handler h1 = new ConsoleHandler ();
@@ -70,9 +73,9 @@
.loopback()
.port(p1)
.path("/test1/smallfile.txt")
- .toURLUnchecked();
+ .toURL();
System.out.println("URL: " + url);
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
InputStream is = urlc.getInputStream();
while (is.read() != -1) ;
is.close();
--- a/test/jdk/com/sun/net/httpserver/bugs/B6339483.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6339483.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,6 +25,9 @@
* @test
* @bug 6339483
* @summary NullPointerException when creating a HttpContext with no handler
+ * @library /test/lib
+ * @run main B6339483
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B6339483
*/
import com.sun.net.httpserver.*;
@@ -36,19 +39,26 @@
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
public class B6339483 {
public static void main (String[] args) throws Exception {
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test");
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
try {
InputStream is = urlc.getInputStream();
int c = 0;
--- a/test/jdk/com/sun/net/httpserver/bugs/B6341616.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6341616.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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,6 +24,9 @@
/**
* @test
* @bug 6341616
+ * @library /test/lib
+ * @run main B6341616
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B6341616
* @summary Server doesnt send response if there is a RuntimeException in validate of BasicAuthFilter
*/
@@ -36,12 +39,14 @@
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
public class B6341616 {
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
BasicAuthenticator filter = new BasicAuthenticator ("foobar@test.realm") {
@@ -56,8 +61,13 @@
server.start ();
java.net.Authenticator.setDefault (new MyAuthenticator());
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
try {
InputStream is = urlc.getInputStream();
int c = 0;
--- a/test/jdk/com/sun/net/httpserver/bugs/B6393710.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6393710.java Tue Jun 11 15:46:26 2019 +0100
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
* @test
* @bug 6393710
* @summary Non authenticated call followed by authenticated call never returns
+ * @run main B6393710
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B6393710
*/
import com.sun.net.httpserver.*;
@@ -65,7 +67,8 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ctx.setAuthenticator (new BasicAuthenticator ("test") {
@@ -76,7 +79,7 @@
server.start ();
- Socket s = new Socket ("localhost", server.getAddress().getPort());
+ Socket s = new Socket (loopback, server.getAddress().getPort());
s.setSoTimeout (5000);
OutputStream os = s.getOutputStream();
--- a/test/jdk/com/sun/net/httpserver/bugs/B6526158.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6526158.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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,6 +24,9 @@
/**
* @test
* @bug 6526158
+ * @library /test/lib
+ * @run main B6526158
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B6526158
* @summary HttpExchange.getRequestBody().close() throws Exception
*/
@@ -36,6 +39,7 @@
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
public class B6526158 {
@@ -44,7 +48,8 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
@@ -52,8 +57,13 @@
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
urlc.setDoOutput (true);
try {
OutputStream os = new BufferedOutputStream (urlc.getOutputStream());
--- a/test/jdk/com/sun/net/httpserver/bugs/B6526913.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6526913.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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 6526913
+ * @library /test/lib
* @run main/othervm -Dhttp.keepAlive=false B6526913
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true
+ * -Dhttp.keepAlive=false B6526913
* @summary HttpExchange.getResponseBody().close() throws Exception
*/
@@ -37,12 +40,14 @@
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
public class B6526913 {
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
@@ -50,8 +55,13 @@
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection (Proxy.NO_PROXY);
try {
InputStream is = urlc.getInputStream();
int c ,count = 0;
--- a/test/jdk/com/sun/net/httpserver/bugs/B6529200.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6529200.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -25,6 +25,7 @@
* @test
* @bug 6529200
* @run main/othervm B6529200
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B6529200
* @summary lightweight http server does not work with http1.0 clients
*/
@@ -42,7 +43,8 @@
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
@@ -52,7 +54,7 @@
/* test 1: keep-alive */
- Socket sock = new Socket ("localhost", server.getAddress().getPort());
+ Socket sock = new Socket (loopback, server.getAddress().getPort());
OutputStream os = sock.getOutputStream();
System.out.println ("GET /test/foo HTTP/1.0\r\nConnection: keep-alive\r\n\r\n");
os.write ("GET /test/foo HTTP/1.0\r\nConnection: keep-alive\r\n\r\n".getBytes());
--- a/test/jdk/com/sun/net/httpserver/bugs/B6744329.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6744329.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,6 +25,9 @@
* @test
* @bug 6744329
* @summary Exception in light weight Http server
+ * @library /test/lib
+ * @run main B6744329
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B6744329
*/
import com.sun.net.httpserver.*;
@@ -36,20 +39,27 @@
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
+import jdk.test.lib.net.URIBuilder;
public class B6744329 {
public static void main (String[] args) throws Exception {
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
try {
InputStream is = urlc.getInputStream();
int c = 0;
@@ -59,6 +69,7 @@
System.out.println ("OK");
} catch (IOException e) {
System.out.println ("exception");
+ e.printStackTrace();
error = true;
}
server.stop(2);
--- a/test/jdk/com/sun/net/httpserver/bugs/B6886436.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/B6886436.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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 6886436
- * @summary
+ * @summary HttpServer should not send a body with 204 response.
+ * @library /test/lib
+ * @run main B6886436
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B6886436
*/
import com.sun.net.httpserver.*;
@@ -34,6 +37,7 @@
import java.util.logging.*;
import java.io.*;
import java.net.*;
+import jdk.test.lib.net.URIBuilder;
public class B6886436 {
@@ -44,20 +48,26 @@
logger.addHandler (c);
logger.setLevel (Level.WARNING);
Handler handler = new Handler();
- InetSocketAddress addr = new InetSocketAddress (0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress (loopback, 0);
HttpServer server = HttpServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
server.start ();
- URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
- HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/test/foo.html")
+ .toURL();
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
try {
InputStream is = urlc.getInputStream();
while (is.read()!= -1) ;
is.close ();
- urlc = (HttpURLConnection)url.openConnection ();
+ urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
urlc.setReadTimeout (3000);
is = urlc.getInputStream();
while (is.read()!= -1);
--- a/test/jdk/com/sun/net/httpserver/bugs/FixedLengthInputStream.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/FixedLengthInputStream.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -25,20 +25,26 @@
* @test
* @bug 6756771 6755625
* @summary com.sun.net.httpserver.HttpServer should handle POSTs larger than 2Gig
+ * @library /test/lib
+ * @run main FixedLengthInputStream
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true FixedLengthInputStream
*/
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.HttpURLConnection;
+import java.net.Proxy;
import java.net.URL;
import java.net.Socket;
import java.util.logging.*;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
+import jdk.test.lib.net.URIBuilder;
public class FixedLengthInputStream
{
@@ -48,8 +54,13 @@
HttpServer httpServer = startHttpServer();
int port = httpServer.getAddress().getPort();
try {
- URL url = new URL("http://localhost:" + port + "/flis/");
- HttpURLConnection uc = (HttpURLConnection)url.openConnection();
+ URL url = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(port)
+ .path("/flis/")
+ .toURLUnchecked();
+ HttpURLConnection uc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
uc.setDoOutput(true);
uc.setRequestMethod("POST");
uc.setFixedLengthStreamingMode(POST_SIZE);
@@ -90,7 +101,8 @@
logger.setLevel(Level.FINEST);
logger.addHandler(outHandler);
}
- HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ HttpServer httpServer = HttpServer.create(new InetSocketAddress(loopback, 0), 0);
httpServer.createContext("/flis/", new MyHandler(POST_SIZE));
httpServer.start();
return httpServer;
--- a/test/jdk/com/sun/net/httpserver/bugs/HeadTest.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/HeadTest.java Tue Jun 11 15:46:26 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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,11 +24,16 @@
/**
* @test
* @bug 6886723
+ * @library /test/lib
+ * @run main HeadTest
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true HeadTest
* @summary light weight http server doesn't return correct status code for HEAD requests
*/
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.HttpURLConnection;
+import java.net.Proxy;
import java.net.URL;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
@@ -37,6 +42,7 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
+import jdk.test.lib.net.URIBuilder;
public class HeadTest {
@@ -45,7 +51,8 @@
}
static void server() throws Exception {
- InetSocketAddress inetAddress = new InetSocketAddress(0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress inetAddress = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create(inetAddress, 5);
try {
server.setExecutor(Executors.newFixedThreadPool(5));
@@ -88,7 +95,13 @@
}
});
server.start();
- String urlStr = "http://localhost:" + server.getAddress().getPort() + "/";
+ String urlStr = URIBuilder.newBuilder()
+ .scheme("http")
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path("/")
+ .build()
+ .toString();
System.out.println("Server is at " + urlStr);
// Run the chunked client
@@ -107,7 +120,7 @@
}
static void runClient(String urlStr) throws Exception {
- HttpURLConnection conn = (HttpURLConnection) new URL(urlStr).openConnection();
+ HttpURLConnection conn = (HttpURLConnection) new URL(urlStr).openConnection(Proxy.NO_PROXY);
conn.setRequestMethod("HEAD");
int status = conn.getResponseCode();
if (status != 200) {
--- a/test/jdk/com/sun/net/httpserver/bugs/TruncatedRequestBody.java Mon Jun 10 10:11:42 2019 +0100
+++ b/test/jdk/com/sun/net/httpserver/bugs/TruncatedRequestBody.java Tue Jun 11 15:46:26 2019 +0100
@@ -90,7 +90,8 @@
logger.setLevel(Level.ALL);
logger.addHandler(h);
- InetSocketAddress addr = new InetSocketAddress(0);
+ InetAddress loopback = InetAddress.getLoopbackAddress();
+ InetSocketAddress addr = new InetSocketAddress(loopback, 0);
HttpServer server = HttpServer.create(addr, 10);
HttpContext ct = server.createContext("/", new Handler());
ExecutorService ex = Executors.newCachedThreadPool();
@@ -101,7 +102,7 @@
// Test 1: fixed length
- Socket sock = new Socket(InetAddress.getLoopbackAddress(), port);
+ Socket sock = new Socket(loopback, port);
String s1 = "POST /foo HTTP/1.1\r\nContent-length: 200000\r\n"
+ "\r\nfoo bar99";
@@ -115,7 +116,7 @@
String s2 = "POST /foo HTTP/1.1\r\nTransfer-encoding: chunked\r\n\r\n" +
"100\r\nFoo bar";
- sock = new Socket(InetAddress.getLoopbackAddress(), port);
+ sock = new Socket(loopback, port);
os = sock.getOutputStream();
os.write(s2.getBytes(StandardCharsets.ISO_8859_1));
Thread.sleep(500);