test/jdk/java/net/httpclient/EscapedOctetsInURI.java
branchhttp-client-branch
changeset 56265 ec34ae013fbe
parent 56201 533a1310dc46
child 56425 9236d0fb75b9
equal deleted inserted replaced
56264:c012b93297b0 56265:ec34ae013fbe
    45 import com.sun.net.httpserver.HttpsConfigurator;
    45 import com.sun.net.httpserver.HttpsConfigurator;
    46 import com.sun.net.httpserver.HttpsServer;
    46 import com.sun.net.httpserver.HttpsServer;
    47 import java.io.IOException;
    47 import java.io.IOException;
    48 import java.io.InputStream;
    48 import java.io.InputStream;
    49 import java.io.OutputStream;
    49 import java.io.OutputStream;
       
    50 import java.net.InetAddress;
    50 import java.net.InetSocketAddress;
    51 import java.net.InetSocketAddress;
    51 import java.net.URI;
    52 import java.net.URI;
    52 import javax.net.ssl.SSLContext;
    53 import javax.net.ssl.SSLContext;
    53 import java.net.http.HttpClient;
    54 import java.net.http.HttpClient;
    54 import java.net.http.HttpRequest;
    55 import java.net.http.HttpRequest;
   163                       assertEquals(retrievedURI.getRawQuery(), uri.getRawQuery()); })
   164                       assertEquals(retrievedURI.getRawQuery(), uri.getRawQuery()); })
   164                   .join();
   165                   .join();
   165         }
   166         }
   166     }
   167     }
   167 
   168 
   168 
   169     static String serverAuthority(HttpServer server) {
       
   170         return InetAddress.getLoopbackAddress().getHostName() + ":"
       
   171                 + server.getAddress().getPort();
       
   172     }
   169 
   173 
   170     @BeforeTest
   174     @BeforeTest
   171     public void setup() throws Exception {
   175     public void setup() throws Exception {
   172         sslContext = new SimpleSSLContext().get();
   176         sslContext = new SimpleSSLContext().get();
   173         if (sslContext == null)
   177         if (sslContext == null)
   174             throw new AssertionError("Unexpected null sslContext");
   178             throw new AssertionError("Unexpected null sslContext");
   175 
   179 
   176         InetSocketAddress sa = new InetSocketAddress("localhost", 0);
   180         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
   177         httpTestServer = HttpServer.create(sa, 0);
   181         httpTestServer = HttpServer.create(sa, 0);
   178         httpTestServer.createContext("/http1", new Http1ASCIIUriStringHandler());
   182         httpTestServer.createContext("/http1", new Http1ASCIIUriStringHandler());
   179         httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1";
   183         httpURI = "http://" + serverAuthority(httpTestServer) + "/http1";
   180 
   184 
   181         httpsTestServer = HttpsServer.create(sa, 0);
   185         httpsTestServer = HttpsServer.create(sa, 0);
   182         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
   186         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
   183         httpsTestServer.createContext("/https1", new Http1ASCIIUriStringHandler());
   187         httpsTestServer.createContext("/https1", new Http1ASCIIUriStringHandler());
   184         httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1";
   188         httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1";
   185 
   189 
   186         http2TestServer = new Http2TestServer("127.0.0.1", false, 0);
   190         http2TestServer = new Http2TestServer("localhost", false, 0);
   187         http2TestServer.addHandler(new HttpASCIIUriStringHandler(), "/http2");
   191         http2TestServer.addHandler(new HttpASCIIUriStringHandler(), "/http2");
   188         int port = http2TestServer.getAddress().getPort();
   192         http2URI = "http://" + http2TestServer.serverAuthority() + "/http2";
   189         http2URI = "http://127.0.0.1:" + port + "/http2";
   193 
   190 
   194         https2TestServer = new Http2TestServer("localhost", true, 0);
   191         https2TestServer = new Http2TestServer("127.0.0.1", true, 0);
       
   192         https2TestServer.addHandler(new HttpASCIIUriStringHandler(), "/https2");
   195         https2TestServer.addHandler(new HttpASCIIUriStringHandler(), "/https2");
   193         port = https2TestServer.getAddress().getPort();
   196         https2URI = "https://" + https2TestServer.serverAuthority() + "/https2";
   194         https2URI = "https://127.0.0.1:" + port + "/https2";
       
   195 
   197 
   196         httpTestServer.start();
   198         httpTestServer.start();
   197         httpsTestServer.start();
   199         httpsTestServer.start();
   198         http2TestServer.start();
   200         http2TestServer.start();
   199         https2TestServer.start();
   201         https2TestServer.start();