jdk/test/java/net/ProxySelector/ProxyTest.java
changeset 13788 3f38e525f30a
parent 5506 202f599c92aa
child 14342 8435a30053c1
equal deleted inserted replaced
13787:19d54bca65d7 13788:3f38e525f30a
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 4696512
    26  * @bug 4696512
    27  * @summary HTTP client: Improve proxy server configuration and selection
    27  * @summary HTTP client: Improve proxy server configuration and selection
    28  * @library ../../../sun/net/www/httptest/
    28  * @library ../../../sun/net/www/httptest/
    29  * @build ClosedChannelList HttpServer HttpTransaction HttpCallback
    29  * @build ClosedChannelList TestHttpServer HttpTransaction HttpCallback
    30  * @compile ProxyTest.java
    30  * @compile ProxyTest.java
    31  * @run main/othervm -Dhttp.proxyHost=inexistant -Dhttp.proxyPort=8080 ProxyTest
    31  * @run main/othervm -Dhttp.proxyHost=inexistant -Dhttp.proxyPort=8080 ProxyTest
    32  */
    32  */
    33 
    33 
    34 import java.net.*;
    34 import java.net.*;
    35 import java.io.*;
    35 import java.io.*;
    36 import java.util.ArrayList;
    36 import java.util.ArrayList;
    37 
    37 
    38 public class ProxyTest implements HttpCallback {
    38 public class ProxyTest implements HttpCallback {
    39     static HttpServer server;
    39     static TestHttpServer server;
    40 
    40 
    41     public ProxyTest() {
    41     public ProxyTest() {
    42     }
    42     }
    43 
    43 
    44     public void request (HttpTransaction req) {
    44     public void request (HttpTransaction req) {
    72         ProxySelector defSelector = ProxySelector.getDefault();
    72         ProxySelector defSelector = ProxySelector.getDefault();
    73         if (defSelector == null)
    73         if (defSelector == null)
    74             throw new RuntimeException("Default ProxySelector is null");
    74             throw new RuntimeException("Default ProxySelector is null");
    75         ProxySelector.setDefault(new MyProxySelector());
    75         ProxySelector.setDefault(new MyProxySelector());
    76         try {
    76         try {
    77             server = new HttpServer (new ProxyTest(), 1, 10, 0);
    77             server = new TestHttpServer (new ProxyTest(), 1, 10, 0);
    78             URL url = new URL("http://localhost:"+server.getLocalPort());
    78             URL url = new URL("http://localhost:"+server.getLocalPort());
    79             System.out.println ("client opening connection to: " + url);
    79             System.out.println ("client opening connection to: " + url);
    80             HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
    80             HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
    81             InputStream is = urlc.getInputStream ();
    81             InputStream is = urlc.getInputStream ();
    82             is.close();
    82             is.close();