B6341616.java revision 2362
325N/A/*
325N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/A/**
325N/A * @test
325N/A * @bug 6341616
325N/A * @summary Server doesnt send response if there is a RuntimeException in validate of BasicAuthFilter
325N/A */
325N/A
325N/Aimport com.sun.net.httpserver.*;
325N/A
325N/Aimport java.util.*;
325N/Aimport java.util.concurrent.*;
325N/Aimport java.io.*;
325N/Aimport java.net.*;
325N/Aimport java.security.*;
325N/Aimport java.security.cert.*;
325N/Aimport javax.net.ssl.*;
325N/A
325N/Apublic class B6341616 {
325N/A
325N/A public static void main (String[] args) throws Exception {
325N/A Handler handler = new Handler();
325N/A InetSocketAddress addr = new InetSocketAddress (0);
325N/A HttpServer server = HttpServer.create (addr, 0);
325N/A HttpContext ctx = server.createContext ("/test", handler);
325N/A BasicAuthenticator filter = new BasicAuthenticator ("foobar@test.realm") {
325N/A public boolean checkCredentials (String username, String pw) {
325N/A throw new RuntimeException ("");
325N/A }
325N/A };
325N/A
325N/A ctx.setAuthenticator (filter);
325N/A ExecutorService executor = Executors.newCachedThreadPool();
325N/A server.setExecutor (executor);
325N/A server.start ();
325N/A java.net.Authenticator.setDefault (new MyAuthenticator());
325N/A
325N/A URL url = new URL ("http://localhost:"+server.getAddress().getPort()+"/test/foo.html");
325N/A HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
325N/A try {
325N/A InputStream is = urlc.getInputStream();
325N/A int c = 0;
325N/A while (is.read()!= -1) {
325N/A c ++;
325N/A }
325N/A } catch (IOException e) {
325N/A server.stop(2);
325N/A executor.shutdown();
325N/A System.out.println ("OK");
325N/A }
325N/A }
325N/A
325N/A public static boolean error = false;
325N/A
325N/A static class MyAuthenticator extends java.net.Authenticator {
325N/A public PasswordAuthentication getPasswordAuthentication () {
325N/A PasswordAuthentication pw;
325N/A if (!getRequestingPrompt().equals ("foobar@test.realm")) {
325N/A B6341616.error = true;
325N/A }
325N/A pw = new PasswordAuthentication ("fred", "xyz".toCharArray());
325N/A return pw;
325N/A }
325N/A }
325N/A
325N/A static class Handler implements HttpHandler {
325N/A int invocation = 1;
325N/A public void handle (HttpExchange t)
325N/A throws IOException
325N/A {
325N/A InputStream is = t.getRequestBody();
325N/A Headers map = t.getRequestHeaders();
325N/A Headers rmap = t.getResponseHeaders();
325N/A while (is.read () != -1) ;
325N/A is.close();
325N/A t.sendResponseHeaders (200, -1);
325N/A t.close();
325N/A }
325N/A }
325N/A}
325N/A