test/jdk/java/net/httpclient/MultiAuthTest.java
branchhttp-client-branch
changeset 56265 ec34ae013fbe
parent 56167 96fa4f49a9ff
child 56451 9585061fdb04
equal deleted inserted replaced
56264:c012b93297b0 56265:ec34ae013fbe
    37 import com.sun.net.httpserver.HttpHandler;
    37 import com.sun.net.httpserver.HttpHandler;
    38 import com.sun.net.httpserver.HttpServer;
    38 import com.sun.net.httpserver.HttpServer;
    39 import java.io.IOException;
    39 import java.io.IOException;
    40 import java.io.InputStream;
    40 import java.io.InputStream;
    41 import java.io.OutputStream;
    41 import java.io.OutputStream;
       
    42 import java.net.InetAddress;
    42 import java.net.InetSocketAddress;
    43 import java.net.InetSocketAddress;
    43 import java.net.PasswordAuthentication;
    44 import java.net.PasswordAuthentication;
    44 import java.net.URI;
    45 import java.net.URI;
    45 import java.net.http.HttpClient;
    46 import java.net.http.HttpClient;
    46 import java.net.http.HttpRequest;
    47 import java.net.http.HttpRequest;
    59     static volatile boolean ok;
    60     static volatile boolean ok;
    60     static final String RESPONSE = "Hello world";
    61     static final String RESPONSE = "Hello world";
    61     static final String POST_BODY = "This is the POST body " + UUID.randomUUID();
    62     static final String POST_BODY = "This is the POST body " + UUID.randomUUID();
    62 
    63 
    63     static HttpServer createServer(ExecutorService e, BasicAuthenticator sa) throws Exception {
    64     static HttpServer createServer(ExecutorService e, BasicAuthenticator sa) throws Exception {
    64         HttpServer server = HttpServer.create(new InetSocketAddress(0), 10);
    65         InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
       
    66         HttpServer server = HttpServer.create(addr, 10);
    65         Handler h = new Handler();
    67         Handler h = new Handler();
    66         HttpContext serverContext = server.createContext("/test", h);
    68         HttpContext serverContext = server.createContext("/test", h);
    67         serverContext.setAuthenticator(sa);
    69         serverContext.setAuthenticator(sa);
    68         server.setExecutor(e);
    70         server.setExecutor(e);
    69         server.start();
    71         server.start();
    93                                        .authenticator(ca)
    95                                        .authenticator(ca)
    94                                        .build();
    96                                        .build();
    95         HttpClient client3 = HttpClient.newHttpClient();
    97         HttpClient client3 = HttpClient.newHttpClient();
    96 
    98 
    97         try {
    99         try {
    98             URI uri = new URI("http://127.0.0.1:" + port + "/test/foo");
   100             URI uri = new URI("http://localhost:" + port + "/test/foo");
    99             System.out.println("URI: " + uri);
   101             System.out.println("URI: " + uri);
   100 
   102 
   101             System.out.println("\nTesting with client #1, Authenticator #1");
   103             System.out.println("\nTesting with client #1, Authenticator #1");
   102             test(client1, ca, uri, 1, null);
   104             test(client1, ca, uri, 1, null);
   103             System.out.println("Testing again with client #1, Authenticator #1");
   105             System.out.println("Testing again with client #1, Authenticator #1");