1 /* |
1 /* |
2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 |
23 |
24 /** |
24 /** |
25 * @test |
25 * @test |
26 * @bug 4678055 |
26 * @bug 4678055 |
27 * @modules java.base/sun.net.www |
27 * @modules java.base/sun.net.www |
28 * @library ../../../sun/net/www/httptest/ |
28 * @library ../../../sun/net/www/httptest/ /test/lib |
29 * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction |
29 * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction |
30 * @run main B4678055 |
30 * @run main/othervm B4678055 |
|
31 * @run main/othervm -Djava.net.preferIPv6Addresses=true B4678055 |
31 * @summary Basic Authentication fails with multiple realms |
32 * @summary Basic Authentication fails with multiple realms |
32 */ |
33 */ |
33 |
34 |
34 import java.io.*; |
35 import java.io.*; |
35 import java.net.*; |
36 import java.net.*; |
|
37 import jdk.test.lib.net.URIBuilder; |
36 |
38 |
37 public class B4678055 implements HttpCallback { |
39 public class B4678055 implements HttpCallback { |
38 |
40 |
39 static int count = 0; |
41 static int count = 0; |
40 static String authstring; |
42 static String authstring; |
123 static TestHttpServer server; |
125 static TestHttpServer server; |
124 |
126 |
125 public static void main (String[] args) throws Exception { |
127 public static void main (String[] args) throws Exception { |
126 MyAuthenticator auth = new MyAuthenticator (); |
128 MyAuthenticator auth = new MyAuthenticator (); |
127 Authenticator.setDefault (auth); |
129 Authenticator.setDefault (auth); |
|
130 ProxySelector.setDefault(ProxySelector.of(null)); // no proxy |
128 try { |
131 try { |
129 server = new TestHttpServer (new B4678055(), 1, 10, 0); |
132 InetAddress loopback = InetAddress.getLoopbackAddress(); |
130 System.out.println ("Server: listening on port: " + server.getLocalPort()); |
133 server = new TestHttpServer(new B4678055(), 1, 10, loopback, 0); |
131 client ("http://localhost:"+server.getLocalPort()+"/d1/foo.html"); |
134 String serverURL = URIBuilder.newBuilder() |
132 client ("http://localhost:"+server.getLocalPort()+"/d2/foo.html"); |
135 .scheme("http") |
133 client ("http://localhost:"+server.getLocalPort()+"/d2/foo.html"); |
136 .loopback() |
|
137 .port(server.getLocalPort()) |
|
138 .path("/") |
|
139 .build() |
|
140 .toString(); |
|
141 System.out.println("Server: listening at: " + serverURL); |
|
142 client(serverURL + "d1/foo.html"); |
|
143 client(serverURL + "d2/foo.html"); |
|
144 client(serverURL + "d2/foo.html"); |
134 } catch (Exception e) { |
145 } catch (Exception e) { |
135 if (server != null) { |
146 if (server != null) { |
136 server.terminate(); |
147 server.terminate(); |
137 } |
148 } |
138 throw e; |
149 throw e; |