0N/A/*
2362N/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 6422914
0N/A * @summary change httpserver exception printouts
0N/A */
0N/A
0N/Aimport com.sun.net.httpserver.*;
0N/A
0N/Aimport java.util.*;
0N/Aimport java.util.concurrent.*;
0N/Aimport java.util.logging.*;
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport java.security.*;
0N/Aimport java.security.cert.*;
0N/Aimport javax.net.ssl.*;
0N/A
0N/Apublic class TestLogging extends Test {
0N/A
0N/A public static void main (String[] args) throws Exception {
0N/A HttpServer s1 = null;
0N/A ExecutorService executor=null;
0N/A
0N/A try {
0N/A System.out.print ("Test9: ");
0N/A String root = System.getProperty ("test.src")+ "/docs";
0N/A InetSocketAddress addr = new InetSocketAddress (0);
0N/A Logger logger = Logger.getLogger ("com.sun.net.httpserver");
0N/A logger.setLevel (Level.ALL);
0N/A Handler h1 = new ConsoleHandler ();
0N/A h1.setLevel (Level.ALL);
0N/A logger.addHandler (h1);
0N/A s1 = HttpServer.create (addr, 0);
0N/A logger.info (root);
0N/A HttpHandler h = new FileServerHandler (root);
0N/A HttpContext c1 = s1.createContext ("/test1", h);
0N/A executor = Executors.newCachedThreadPool();
0N/A s1.setExecutor (executor);
0N/A s1.start();
0N/A
0N/A int p1 = s1.getAddress().getPort();
0N/A
0N/A URL url = new URL ("http://127.0.0.1:"+p1+"/test1/smallfile.txt");
0N/A HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
0N/A InputStream is = urlc.getInputStream();
0N/A while (is.read() != -1) ;
0N/A is.close();
0N/A
0N/A url = new URL ("http://127.0.0.1:"+p1+"/test1/doesntexist.txt");
0N/A urlc = (HttpURLConnection)url.openConnection();
0N/A try {
0N/A is = urlc.getInputStream();
0N/A while (is.read() != -1) ;
0N/A is.close();
0N/A } catch (IOException e) {
0N/A System.out.println ("caught expected exception");
0N/A }
0N/A
0N/A Socket s = new Socket ("127.0.0.1", p1);
0N/A OutputStream os = s.getOutputStream();
0N/A //os.write ("GET xxx HTTP/1.1\r\n".getBytes());
0N/A os.write ("HELLO WORLD\r\n".getBytes());
0N/A is = s.getInputStream();
0N/A while (is.read() != -1) ;
0N/A os.close(); is.close(); s.close();
0N/A System.out.println ("OK");
0N/A } finally {
0N/A delay();
1324N/A if (s1 != null)
1324N/A s1.stop(2);
1324N/A if (executor != null)
1324N/A executor.shutdown();
0N/A }
0N/A }
0N/A}