mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-14 23:49:49 +00:00
8231504: Update networking tests to avoid implicit dependency on the system proxies
Reviewed-by: dfuchs
This commit is contained in:
parent
6212eb36c3
commit
0b881387f2
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2016, 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
|
||||
@ -28,7 +28,7 @@ import java.io.OutputStream;
|
||||
import java.net.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
/*
|
||||
* @test
|
||||
@ -52,7 +52,7 @@ public class LocalHostCookie {
|
||||
s = new Server();
|
||||
s.startServer();
|
||||
URL url = new URL("http","localhost", s.getPort(), "/");
|
||||
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(NO_PROXY);
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.setDoOutput(true);
|
||||
urlConnection.connect();
|
||||
|
||||
@ -40,6 +40,7 @@ import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
/*
|
||||
* @test
|
||||
@ -296,7 +297,7 @@ public class HTTPTest {
|
||||
HttpURLConnection conn = (HttpURLConnection)
|
||||
(authType == HttpAuthType.PROXY
|
||||
? url.openConnection(proxy)
|
||||
: url.openConnection());
|
||||
: url.openConnection(NO_PROXY));
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
* @bug 6215885
|
||||
* @library /test/lib
|
||||
* @summary URLConnection.openConnection NPE if ProxySelector.setDefault is set to null
|
||||
* @run main/othervm NullSelector
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
|
||||
@ -33,6 +33,7 @@ import java.net.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class B6181108 implements Runnable {
|
||||
ServerSocket ss;
|
||||
@ -105,7 +106,7 @@ public class B6181108 implements Runnable {
|
||||
.toString();
|
||||
urlWithSpace = base + "/space%20test/page1.html";
|
||||
URL url = new URL(urlWithSpace);
|
||||
URLConnection urlc = url.openConnection();
|
||||
URLConnection urlc = url.openConnection(NO_PROXY);
|
||||
int i = ((HttpURLConnection)(urlc)).getResponseCode();
|
||||
System.out.println("response code = " + i);
|
||||
ResponseCache.setDefault(null);
|
||||
|
||||
@ -33,6 +33,7 @@ import java.util.*;
|
||||
import java.io.*;
|
||||
import javax.net.ssl.*;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
/**
|
||||
* Request should get serviced by the cache handler. Response get
|
||||
@ -137,7 +138,7 @@ public class ResponseCacheTest implements Runnable {
|
||||
.port(ss.getLocalPort())
|
||||
.path("/file2.1")
|
||||
.toURL();
|
||||
http = (HttpURLConnection)url2.openConnection();
|
||||
http = (HttpURLConnection)url2.openConnection(NO_PROXY);
|
||||
System.out.println("responsecode2 is :"+http.getResponseCode());
|
||||
Map<String,List<String>> headers2 = http.getHeaderFields();
|
||||
|
||||
|
||||
@ -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
|
||||
@ -30,6 +30,7 @@
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
|
||||
/**
|
||||
@ -43,7 +44,7 @@ public class getResponseCode {
|
||||
|
||||
getResponseCode() throws Exception {
|
||||
url = new URL("http://localhost/file1.cache");
|
||||
HttpURLConnection http = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection http = (HttpURLConnection)url.openConnection(NO_PROXY);
|
||||
int respCode = http.getResponseCode();
|
||||
http.disconnect();
|
||||
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import sun.net.www.protocol.file.FileURLConnection;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class B5052093 implements HttpCallback {
|
||||
private static TestHttpServer server;
|
||||
@ -68,7 +69,7 @@ public class B5052093 implements HttpCallback {
|
||||
server = new TestHttpServer(new B5052093(), 1, 10, loopback, 0);
|
||||
try {
|
||||
URL url = new URL("http://" + server.getAuthority() + "/foo");
|
||||
URLConnection conn = url.openConnection();
|
||||
URLConnection conn = url.openConnection(NO_PROXY);
|
||||
int i = conn.getContentLength();
|
||||
long l = conn.getContentLengthLong();
|
||||
if (i != -1 || l != testSize) {
|
||||
|
||||
@ -33,8 +33,7 @@ import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
|
||||
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class DisconnectAfterEOF {
|
||||
|
||||
@ -217,7 +216,7 @@ public class DisconnectAfterEOF {
|
||||
}
|
||||
|
||||
static URLConnection doRequest(String uri) throws IOException {
|
||||
URLConnection uc = (new URL(uri)).openConnection();
|
||||
URLConnection uc = (new URL(uri)).openConnection(NO_PROXY);
|
||||
uc.setDoOutput(true);
|
||||
OutputStream out = uc.getOutputStream();
|
||||
out.write(new byte[16000]);
|
||||
|
||||
@ -38,8 +38,8 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class HttpContinueStackOverflow {
|
||||
|
||||
@ -93,7 +93,7 @@ public class HttpContinueStackOverflow {
|
||||
.path("/anything.html")
|
||||
.toURL();
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection(NO_PROXY);
|
||||
conn.getResponseCode();
|
||||
System.out.println("TEST PASSED");
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@
|
||||
*/
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
class RedirServer extends Thread {
|
||||
|
||||
@ -113,7 +113,7 @@ public class Redirect307Test {
|
||||
.loopback()
|
||||
.port(port)
|
||||
.toURL();
|
||||
URLConnection conURL = url.openConnection();
|
||||
URLConnection conURL = url.openConnection(NO_PROXY);
|
||||
conURL.setDoInput(true);
|
||||
conURL.setAllowUserInteraction(false);
|
||||
conURL.setUseCaches(false);
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class Responses {
|
||||
|
||||
@ -149,7 +150,7 @@ public class Responses {
|
||||
System.out.println("Test with response: >" + tests[i][0] + "<");
|
||||
|
||||
URL url = new URL("http://" + authority + "/" + i);
|
||||
HttpURLConnection http = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection http = (HttpURLConnection)url.openConnection(NO_PROXY);
|
||||
|
||||
try {
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ import java.net.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class URLConnectionHeaders {
|
||||
|
||||
@ -94,7 +95,7 @@ public class URLConnectionHeaders {
|
||||
.port(port)
|
||||
.path("/index.html")
|
||||
.toURL();
|
||||
URLConnection uc = url.openConnection();
|
||||
URLConnection uc = url.openConnection(NO_PROXY);
|
||||
|
||||
// add request properties
|
||||
uc.addRequestProperty("Cookie", "cookie1");
|
||||
|
||||
@ -40,6 +40,7 @@ import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class UserContentHandler implements Runnable {
|
||||
|
||||
@ -98,7 +99,7 @@ public class UserContentHandler implements Runnable {
|
||||
.path("/anything.txt")
|
||||
.toURL();
|
||||
|
||||
if (!(u.openConnection().getContent() instanceof String)) {
|
||||
if (!(u.openConnection(NO_PROXY).getContent() instanceof String)) {
|
||||
throw new RuntimeException("Load user defined content handler failed.");
|
||||
} else {
|
||||
System.err.println("Load user defined content handler succeed!");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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
|
||||
@ -31,6 +31,7 @@
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class OpenURL {
|
||||
|
||||
@ -46,7 +47,7 @@ public class OpenURL {
|
||||
.path("/a/b")
|
||||
.toURL();
|
||||
System.out.println("URL: " + url);
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(NO_PROXY);
|
||||
InputStream is = urlc.getInputStream();
|
||||
// error will throw exception other than SecurityException
|
||||
} catch (SecurityException e) {
|
||||
|
||||
@ -74,6 +74,7 @@ import java.util.Random;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class ManyRequestsLegacy {
|
||||
|
||||
@ -159,7 +160,7 @@ public class ManyRequestsLegacy {
|
||||
long start = System.nanoTime();
|
||||
try {
|
||||
CompletableFuture<LegacyHttpResponse> cf = new CompletableFuture<>();
|
||||
URLConnection urlc = r.uri().toURL().openConnection();
|
||||
URLConnection urlc = r.uri().toURL().openConnection(NO_PROXY);
|
||||
HttpURLConnection httpc = (HttpURLConnection)urlc;
|
||||
httpc.setRequestMethod(r.method());
|
||||
for (String s : r.headers().map().keySet()) {
|
||||
|
||||
@ -44,6 +44,7 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.stream.Collectors;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -139,7 +140,7 @@ public class PlainProxyConnectionTest {
|
||||
throws IOException {
|
||||
connections.clear();
|
||||
System.out.println("Verifying communication with server");
|
||||
try (InputStream is = uri.toURL().openConnection().getInputStream()) {
|
||||
try (InputStream is = uri.toURL().openConnection(NO_PROXY).getInputStream()) {
|
||||
String resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
|
||||
System.out.println(resp);
|
||||
if (!RESPONSE.equals(resp)) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 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
|
||||
@ -57,6 +57,7 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -167,7 +168,7 @@ public class ProxyTest {
|
||||
System.out.println("Verifying communication with server");
|
||||
URI uri = new URI("https://localhost:"
|
||||
+ server.getAddress().getPort() + PATH + "x");
|
||||
try (InputStream is = uri.toURL().openConnection().getInputStream()) {
|
||||
try (InputStream is = uri.toURL().openConnection(NO_PROXY).getInputStream()) {
|
||||
String resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
|
||||
System.out.println(resp);
|
||||
if (!RESPONSE.equals(resp)) {
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class KeepAliveTimerThread {
|
||||
static class Fetcher implements Runnable {
|
||||
@ -44,7 +45,7 @@ public class KeepAliveTimerThread {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
InputStream in = url.openConnection().getInputStream();
|
||||
InputStream in = url.openConnection(NO_PROXY).getInputStream();
|
||||
byte b[] = new byte[128];
|
||||
int n;
|
||||
do {
|
||||
|
||||
@ -35,7 +35,7 @@ import java.util.*;
|
||||
import java.io.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class UserAuth
|
||||
{
|
||||
@ -61,7 +61,7 @@ public class UserAuth
|
||||
|
||||
// GET Request
|
||||
URL url = new URL("http://" + address.getHostName() + ":" + address.getPort() + "/redirect/");
|
||||
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection uc = (HttpURLConnection)url.openConnection(NO_PROXY);
|
||||
uc.setRequestProperty("Authorization", "testString:ValueDoesNotMatter");
|
||||
int resp = uc.getResponseCode();
|
||||
|
||||
|
||||
@ -33,6 +33,7 @@ import java.net.*;
|
||||
import com.sun.net.httpserver.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
public class UserCookie
|
||||
{
|
||||
@ -59,7 +60,7 @@ public class UserCookie
|
||||
InetSocketAddress address = httpServer.getAddress();
|
||||
|
||||
URL url = new URL("http://" + address.getHostName() + ":" + address.getPort() + "/test/");
|
||||
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
|
||||
HttpURLConnection uc = (HttpURLConnection)url.openConnection(NO_PROXY);
|
||||
uc.setRequestProperty("Cookie", "value=ValueDoesNotMatter");
|
||||
int resp = uc.getResponseCode();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user