test/jdk/java/net/Authenticator/Deadlock.java
author dfuchs
Mon, 17 Jun 2019 20:03:34 +0100
changeset 55399 46049b8a5658
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225578: Replace wildcard address with loopback or local host in tests - part 16 Summary: Fixes java/net/Authenticator and java/net/CookieHandler to stop depending on the wildcard address, wherever possible. Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     1
/*
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
     2
 * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     4
 *
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     8
 *
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    13
 * accompanied this code).
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    14
 *
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5199
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5199
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5199
diff changeset
    21
 * questions.
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    22
 */
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    23
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    24
/**
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    25
 * @test
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    26
 * @bug 6648001
38883
d5de564f8089 8151913: Fix module dependencies in java/net tests
mli
parents: 5506
diff changeset
    27
 * @modules jdk.httpserver
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    28
 * @library /test/lib
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    29
 * @run main/othervm/timeout=20 -ea:sun.net.www.protocol.http.AuthenticationInfo -Dhttp.auth.serializeRequests=true Deadlock
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    30
 * @run main/othervm/timeout=20 -Djava.net.preferIPv6Addresses=true
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    31
 *                              -ea:sun.net.www.protocol.http.AuthenticationInfo -Dhttp.auth.serializeRequests=true Deadlock
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    32
 * @summary  cancelling HTTP authentication causes deadlock
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    33
 */
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    34
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    35
import java.util.concurrent.Executors;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    36
import java.util.concurrent.ExecutorService;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    37
import java.io.InputStream;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    38
import java.io.IOException;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    39
import java.net.HttpURLConnection;
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    40
import java.net.InetAddress;
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    41
import java.net.InetSocketAddress;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    42
import java.net.PasswordAuthentication;
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    43
import java.net.Proxy;
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    44
import java.net.URL;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    45
import com.sun.net.httpserver.BasicAuthenticator;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    46
import com.sun.net.httpserver.Headers;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    47
import com.sun.net.httpserver.HttpContext;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    48
import com.sun.net.httpserver.HttpExchange;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    49
import com.sun.net.httpserver.HttpHandler;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    50
import com.sun.net.httpserver.HttpPrincipal;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    51
import com.sun.net.httpserver.HttpServer;
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    52
import jdk.test.lib.net.URIBuilder;
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    53
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    54
public class Deadlock {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    55
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    56
    public static void main (String[] args) throws Exception {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    57
        Handler handler = new Handler();
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    58
        InetAddress loopback = InetAddress.getLoopbackAddress();
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
    59
        InetSocketAddress addr = new InetSocketAddress (loopback, 0);
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    60
        HttpServer server = HttpServer.create(addr, 0);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    61
        HttpContext ctx = server.createContext("/test", handler);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    62
        BasicAuthenticator a = new BasicAuthenticator("foobar@test.realm") {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    63
            @Override
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    64
            public boolean checkCredentials (String username, String pw) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    65
                return "fred".equals(username) && pw.charAt(0) == 'x';
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    66
            }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    67
        };
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    68
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    69
        ctx.setAuthenticator(a);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    70
        ExecutorService executor = Executors.newCachedThreadPool();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    71
        server.setExecutor(executor);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    72
        server.start ();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    73
        java.net.Authenticator.setDefault(new MyAuthenticator());
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    74
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    75
        System.out.print("Deadlock: " );
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    76
        for (int i=0; i<2; i++) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    77
            Runner t = new Runner(server, i);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    78
            t.start();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    79
            t.join();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    80
        }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    81
        server.stop(2);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    82
        executor.shutdown();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    83
        if (error) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    84
            throw new RuntimeException("test failed error");
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    85
        }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    86
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    87
        if (count != 2) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    88
            throw new RuntimeException("test failed count = " + count);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    89
        }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    90
        System.out.println("OK");
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    91
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    92
    }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    93
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    94
    static class Runner extends Thread {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    95
        HttpServer server;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    96
        int i;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    97
        Runner(HttpServer s, int i) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    98
            server = s;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
    99
            this.i = i;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   100
        }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   101
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   102
        @Override
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   103
        public void run() {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   104
            URL url;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   105
            HttpURLConnection urlc;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   106
            try {
55399
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
   107
                url = URIBuilder.newBuilder()
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
   108
                    .scheme("http")
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
   109
                    .loopback()
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
   110
                    .port(server.getAddress().getPort())
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
   111
                    .path("/test/foo.html")
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
   112
                    .toURLUnchecked();
46049b8a5658 8225578: Replace wildcard address with loopback or local host in tests - part 16
dfuchs
parents: 47216
diff changeset
   113
                urlc = (HttpURLConnection)url.openConnection (Proxy.NO_PROXY);
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   114
            } catch (IOException e) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   115
                error = true;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   116
                return;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   117
            }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   118
            InputStream is = null;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   119
            try {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   120
                is = urlc.getInputStream();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   121
                while (is.read()!= -1) {}
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   122
            } catch (IOException e) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   123
                if (i == 1) error = true;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   124
            } finally {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   125
                if (is != null) try { is.close(); } catch (IOException e) {}
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   126
            }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   127
        }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   128
    }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   129
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   130
    public static boolean error = false;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   131
    public static int count = 0;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   132
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   133
    static class MyAuthenticator extends java.net.Authenticator {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   134
        @Override
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   135
        public PasswordAuthentication getPasswordAuthentication() {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   136
            PasswordAuthentication pw;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   137
            if (!getRequestingPrompt().equals("foobar@test.realm")) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   138
                Deadlock.error = true;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   139
            }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   140
            if (count == 0) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   141
                pw = null;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   142
            } else {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   143
                pw = new PasswordAuthentication("fred", "xyz".toCharArray());
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   144
            }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   145
            count++;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   146
            return pw;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   147
        }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   148
    }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   149
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   150
    static class Handler implements HttpHandler {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   151
        int invocation = 1;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   152
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   153
        @Override
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   154
        public void handle (HttpExchange t)
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   155
            throws IOException
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   156
        {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   157
            InputStream is = t.getRequestBody();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   158
            Headers map = t.getRequestHeaders();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   159
            Headers rmap = t.getResponseHeaders();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   160
            while (is.read() != -1);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   161
            is.close();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   162
            t.sendResponseHeaders(200, -1);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   163
            HttpPrincipal p = t.getPrincipal();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   164
            if (!p.getUsername().equals("fred")) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   165
                error = true;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   166
            }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   167
            if (!p.getRealm().equals("foobar@test.realm")) {
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   168
                error = true;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   169
            }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   170
            t.close();
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   171
        }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   172
    }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents:
diff changeset
   173
}