test/jdk/java/net/Authenticator/B4962064.java
changeset 55399 46049b8a5658
parent 47216 71c04702a3d5
equal deleted inserted replaced
55398:e53ec3b362f4 55399:46049b8a5658
    26  * @bug 4962064
    26  * @bug 4962064
    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/
    29  * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction
    29  * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction
    30  * @run main/othervm B4962064
    30  * @run main/othervm B4962064
       
    31  * @run main/othervm -Djava.net.preferIPv6Addresses=true B4962064
    31  * @summary Extend Authenticator to provide access to request URI and server/proxy
    32  * @summary Extend Authenticator to provide access to request URI and server/proxy
    32  */
    33  */
    33 
    34 
    34 import java.io.*;
    35 import java.io.*;
    35 import java.net.*;
    36 import java.net.*;
    89     static TestHttpServer server;
    90     static TestHttpServer server;
    90     static URL urlsave;
    91     static URL urlsave;
    91 
    92 
    92     public static void main (String[] args) throws Exception {
    93     public static void main (String[] args) throws Exception {
    93         try {
    94         try {
    94             server = new TestHttpServer (new B4962064(), 1, 10, 0);
    95             InetAddress address = InetAddress.getLoopbackAddress();
       
    96             InetAddress resolved = InetAddress.getByName(address.getHostName());
       
    97             System.out.println("Lookup: " + address + " -> \""
       
    98                                + address.getHostName() + "\" -> "
       
    99                                + resolved);
       
   100             server = new TestHttpServer (new B4962064(), 1, 10, address, 0);
    95             int port = server.getLocalPort();
   101             int port = server.getLocalPort();
    96             System.setProperty ("http.proxyHost", "localhost");
   102             String proxyHost = address.equals(resolved)
       
   103                 ? address.getHostName()
       
   104                 : address.getHostAddress();
       
   105             System.setProperty ("http.proxyHost", proxyHost);
    97             System.setProperty ("http.proxyPort", Integer.toString (port));
   106             System.setProperty ("http.proxyPort", Integer.toString (port));
    98             MyAuthenticator auth = new MyAuthenticator ();
   107             MyAuthenticator auth = new MyAuthenticator ();
    99             Authenticator.setDefault (auth);
   108             Authenticator.setDefault (auth);
   100             System.out.println ("Server started: listening on port: " + port);
   109             System.out.println ("Server started: listening on port: " + port);
   101             //String s = new String ("http://localhost:"+port+"/d1/d2/d3/foo.html");
       
   102             String s = new String ("http://foo.com/d1/d2/d3/foo.html");
   110             String s = new String ("http://foo.com/d1/d2/d3/foo.html");
   103             urlsave = new URL (s);
   111             urlsave = new URL (s);
   104             client (s);
   112             client (s);
   105             //s = new String ("http://localhost:"+port+"/dr/d3/foo.html");
       
   106             s = new String ("http://bar.com/dr/d3/foo.html");
   113             s = new String ("http://bar.com/dr/d3/foo.html");
   107             urlsave = new URL (s);
   114             urlsave = new URL (s);
   108             client (s);
   115             client (s);
   109         } catch (Exception e) {
   116         } catch (Exception e) {
   110             if (server != null) {
   117             if (server != null) {