Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions jdk/test/com/sun/net/httpserver/bugs/B6361557.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void handle (HttpExchange t)

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);

Expand All @@ -78,15 +79,18 @@ public static void main (String[] args) throws Exception {
server.start ();

InetSocketAddress destaddr = new InetSocketAddress (
"127.0.0.1", server.getAddress().getPort()
loopback, server.getAddress().getPort()
);
System.out.println ("destaddr " + destaddr);

Selector selector = Selector.open ();
int requests = 0;
int responses = 0;
while (true) {
int selres = selector.select (1);
// we need to read responses from time to time: slightly
// increase the timeout with the amount of pending responses
// to give a chance to the server to reply.
int selres = selector.select (requests - responses + 1);
Set<SelectionKey> selkeys = selector.selectedKeys();
for (SelectionKey key : selkeys) {
if (key.isReadable()) {
Expand All @@ -95,14 +99,18 @@ public static void main (String[] args) throws Exception {
try {
int x = chan.read(buf);
if (x == -1 || responseComplete(buf)) {
System.out.print("_");
key.attach(null);
chan.close();
responses++;
}
} catch (IOException e) {}
} catch (IOException e) {
System.out.println(e);
}
}
}
if (requests < NUM) {
System.out.print(".");
SocketChannel schan = SocketChannel.open(destaddr);
requestBuf.rewind();
int c = 0;
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/java/net/Authenticator/B4722333.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -120,13 +120,14 @@ public static void main (String[] args) throws Exception {
MyAuthenticator auth = new MyAuthenticator ();
Authenticator.setDefault (auth);
try {
server = new TestHttpServer (new B4722333(), 1, 10, 0);
InetAddress loopback = InetAddress.getLoopbackAddress();
server = new TestHttpServer (new B4722333(), 1, 10, loopback, 0);
System.out.println ("Server started: listening on port: " + server.getLocalPort());
client ("http://localhost:"+server.getLocalPort()+"/d1/d2/d3/foo.html");
client ("http://localhost:"+server.getLocalPort()+"/ASD/d3/x.html");
client ("http://localhost:"+server.getLocalPort()+"/biz/d3/x.html");
client ("http://localhost:"+server.getLocalPort()+"/bar/d3/x.html");
client ("http://localhost:"+server.getLocalPort()+"/fuzz/d3/x.html");
client ("http://" + server.getAuthority() + "/d1/d2/d3/foo.html");
client ("http://" + server.getAuthority() + "/ASD/d3/x.html");
client ("http://" + server.getAuthority() + "/biz/d3/x.html");
client ("http://" + server.getAuthority() + "/bar/d3/x.html");
client ("http://" + server.getAuthority() + "/fuzz/d3/x.html");
} catch (Exception e) {
if (server != null) {
server.terminate();
Expand Down
16 changes: 12 additions & 4 deletions jdk/test/java/net/HttpURLConnection/UnmodifiableMaps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,11 +24,13 @@
/**
* @test
* @bug 7128648
* @library /lib/testlibrary
* @modules jdk.httpserver
* @summary HttpURLConnection.getHeaderFields should return an unmodifiable Map
*/

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.HttpURLConnection;
Expand All @@ -41,14 +43,20 @@
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.Headers;
import static java.net.Proxy.NO_PROXY;
import jdk.testlibrary.net.URIBuilder;

public class UnmodifiableMaps {

void test(String[] args) throws Exception {
HttpServer server = startHttpServer();
try {
InetSocketAddress address = server.getAddress();
URI uri = new URI("http://localhost:" + address.getPort() + "/foo");
URI uri = URIBuilder.newBuilder()
.scheme("http")
.host(address.getAddress())
.port(address.getPort())
.path("/foo")
.build();
doClient(uri);
} finally {
server.stop(0);
Expand Down Expand Up @@ -78,7 +86,8 @@ void doClient(URI uri) throws Exception {

// HTTP Server
HttpServer startHttpServer() throws IOException {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
InetAddress loopback = InetAddress.getLoopbackAddress();
HttpServer httpServer = HttpServer.create(new InetSocketAddress(loopback, 0), 0);
httpServer.createContext("/foo", new SimpleHandler());
httpServer.start();
return httpServer;
Expand Down Expand Up @@ -146,4 +155,3 @@ public void instanceMain(String[] args) throws Throwable {
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");}
}

19 changes: 14 additions & 5 deletions jdk/test/java/net/ResponseCache/ResponseCacheTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2010, 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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,7 @@
/* @test
* @summary Unit test for java.net.ResponseCache
* @bug 4837267
* @library /lib/testlibrary
* @author Yingxian Wang
*/

Expand All @@ -32,6 +33,7 @@
import java.io.*;
import sun.net.www.ParseUtil;
import javax.net.ssl.*;
import jdk.testlibrary.net.URIBuilder;

/**
* Request should get serviced by the cache handler. Response get
Expand Down Expand Up @@ -91,14 +93,17 @@ public void run() {
try { fis.close(); } catch (IOException unused) {}
}
}
static class NameVerifier implements HostnameVerifier {
static class NameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
ResponseCacheTest() throws Exception {
/* start the server */
ss = new ServerSocket(0);
InetAddress loopback = InetAddress.getLoopbackAddress();
ss = new ServerSocket();
ss.bind(new InetSocketAddress(loopback, 0));

(new Thread(this)).start();
/* establish http connection to server */
url1 = new URL("http://localhost/file1.cache");
Expand Down Expand Up @@ -127,8 +132,12 @@ public boolean verify(String hostname, SSLSession session) {
http.disconnect();

// testing ResponseCacheHandler.put()
url2 = new URL("http://localhost:" +
Integer.toString(ss.getLocalPort())+"/file2.1");
url2 = URIBuilder.newBuilder()
.scheme("http")
.host(ss.getInetAddress())
.port(ss.getLocalPort())
.path("/file2.1")
.toURL();
http = (HttpURLConnection)url2.openConnection();
System.out.println("responsecode2 is :"+http.getResponseCode());
Map<String,List<String>> headers2 = http.getHeaderFields();
Expand Down
5 changes: 3 additions & 2 deletions jdk/test/java/net/Socket/GetLocalAddress.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2013, 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
Expand Down Expand Up @@ -45,7 +45,8 @@ public static void main(String args[]) throws Exception {
int linger = 65546;
int value = 0;
addr = InetAddress.getLocalHost();
ss = new ServerSocket(0);
ss = new ServerSocket();
ss.bind(new InetSocketAddress(addr, 0));
port = ss.getLocalPort();

Thread t = new Thread(new GetLocalAddress());
Expand Down
10 changes: 7 additions & 3 deletions jdk/test/java/net/Socket/SetReceiveBufferSize.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2010, 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.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,6 +28,8 @@
*
*/

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.ServerSocket;

Expand All @@ -37,8 +39,10 @@ public static void main(String[] args) throws Exception {
}

public SetReceiveBufferSize() throws Exception {
ServerSocket ss = new ServerSocket(0);
Socket s = new Socket("localhost", ss.getLocalPort());
ServerSocket ss = new ServerSocket();
InetAddress loopback = InetAddress.getLoopbackAddress();
ss.bind(new InetSocketAddress(loopback, 0));
Socket s = new Socket(loopback, ss.getLocalPort());
Socket accepted = ss.accept();
try {
s.setReceiveBufferSize(0);
Expand Down
5 changes: 3 additions & 2 deletions jdk/test/java/net/Socket/SoTimeout.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2010, 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
Expand Down Expand Up @@ -44,7 +44,8 @@ public class SoTimeout implements Runnable {

public static void main(String[] args) throws Exception {
addr = InetAddress.getLocalHost();
serverSocket = new ServerSocket(0);
serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress(addr, 0));
port = serverSocket.getLocalPort();

byte[] b = new byte[12];
Expand Down
7 changes: 4 additions & 3 deletions jdk/test/java/net/Socket/TestAfterClose.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,8 +36,9 @@ public class TestAfterClose

public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(0, 0, null);
Socket socket = new Socket("localhost", ss.getLocalPort());
InetAddress loopback = InetAddress.getLoopbackAddress();
ServerSocket ss = new ServerSocket(0, 0, loopback);
Socket socket = new Socket(loopback, ss.getLocalPort());
ss.accept();
ss.close();
test(socket);
Expand Down
6 changes: 4 additions & 2 deletions jdk/test/java/net/Socket/UrgentDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public static void main (String args[]) {
try {
UrgentDataTest test = new UrgentDataTest ();
if (args.length == 0) {
test.listener = new ServerSocket (0);
InetAddress loopback = InetAddress.getLoopbackAddress();
test.listener = new ServerSocket ();
test.listener.bind(new InetSocketAddress(loopback, 0));
test.isClient = true;
test.isServer = true;
test.clHost = "127.0.0.1";
test.clHost = loopback.getHostAddress();
test.clPort = test.listener.getLocalPort();
test.run();
} else if (args[0].equals ("-server")) {
Expand Down
14 changes: 9 additions & 5 deletions jdk/test/java/net/URL/GetContent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2010, 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
Expand All @@ -24,11 +24,13 @@
/**
* @test
* @bug 4145315
* @library /lib/testlibrary
* @summary Test a read from nonexistant URL
*/

import java.net.*;
import java.io.*;
import jdk.testlibrary.net.URIBuilder;

public class GetContent implements Runnable {

Expand Down Expand Up @@ -71,10 +73,12 @@ public void run() {

boolean error = true;
try {
String name = "http://localhost:" + ss.getLocalPort() +
"/no-such-name";
java.net.URL url = null;
url = new java.net.URL(name);
java.net.URL url = URIBuilder.newBuilder()
.scheme("http")
.host(ss.getInetAddress())
.port(ss.getLocalPort())
.path("/no-such-name")
.toURL();
Object obj = url.getContent();
InputStream in = (InputStream) obj;
byte buff[] = new byte[200];
Expand Down
7 changes: 4 additions & 3 deletions jdk/test/java/net/URLConnection/B5052093.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2012, 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
Expand Down Expand Up @@ -63,9 +63,10 @@ public void request(HttpTransaction req) {
}

public static void main(String[] args) throws Exception {
server = new TestHttpServer(new B5052093(), 1, 10, 0);
InetAddress loopback = InetAddress.getLoopbackAddress();
server = new TestHttpServer(new B5052093(), 1, 10, loopback, 0);
try {
URL url = new URL("http://localhost:"+server.getLocalPort()+"/foo");
URL url = new URL("http://" + server.getAuthority() + "/foo");
URLConnection conn = url.openConnection();
int i = conn.getContentLength();
long l = conn.getContentLengthLong();
Expand Down
6 changes: 6 additions & 0 deletions jdk/test/lib/testlibrary/jdk/testlibrary/net/URIBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public URIBuilder host(String host) {
return this;
}

public URIBuilder host(InetAddress address) {
String hostaddr = address.isAnyLocalAddress()
? "localhost" : address.getHostAddress();
return host(hostaddr);
}

public URIBuilder loopback() {
return host(InetAddress.getLoopbackAddress().getHostAddress());
}
Expand Down
8 changes: 6 additions & 2 deletions jdk/test/sun/net/ftp/TestFtpClientNameListWithNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
Expand All @@ -52,7 +53,8 @@ public static void main(String[] args) throws Exception {
FtpClient client = FtpClient.create()) {
(new Thread(server)).start();
int port = server.getPort();
client.connect(new InetSocketAddress("localhost", port));
InetAddress loopback = InetAddress.getLoopbackAddress();
client.connect(new InetSocketAddress(loopback, port));
client.nameList(null);
} finally {
if (commandHasArgs) {
Expand All @@ -66,7 +68,9 @@ private static class FtpServer implements AutoCloseable, Runnable {
private final ServerSocket serverSocket;

FtpServer() throws IOException {
serverSocket = new ServerSocket(0);
InetAddress loopback = InetAddress.getLoopbackAddress();
serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress(loopback, 0));
}

public void handleClient(Socket client) throws IOException {
Expand Down
Loading