1 /* |
1 /* |
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2018, 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. |
53 ConsoleHandler c = new ConsoleHandler(); |
53 ConsoleHandler c = new ConsoleHandler(); |
54 c.setLevel (Level.WARNING); |
54 c.setLevel (Level.WARNING); |
55 logger.addHandler (c); |
55 logger.addHandler (c); |
56 logger.setLevel (Level.WARNING); |
56 logger.setLevel (Level.WARNING); |
57 Handler handler = new Handler(); |
57 Handler handler = new Handler(); |
58 InetSocketAddress addr = new InetSocketAddress (0); |
58 InetSocketAddress addr = new InetSocketAddress (InetAddress.getLoopbackAddress(), 0); |
59 HttpServer server = HttpServer.create (addr, 0); |
59 HttpServer server = HttpServer.create (addr, 0); |
60 HttpContext ctx = server.createContext ("/test", handler); |
60 HttpContext ctx = server.createContext ("/test", handler); |
61 ExecutorService executor = Executors.newCachedThreadPool(); |
61 ExecutorService executor = Executors.newCachedThreadPool(); |
62 server.setExecutor (executor); |
62 server.setExecutor (executor); |
63 server.start (); |
63 server.start (); |
64 |
64 |
65 URI uri = new URI("http://localhost:"+server.getAddress().getPort()+"/test/foo.html"); |
65 URI uri = new URI("http", null, |
|
66 server.getAddress().getHostString(), |
|
67 server.getAddress().getPort(), |
|
68 "/test/foo.html", null, null); |
66 |
69 |
67 try { |
70 try { |
68 HttpClient client = HttpClient.newHttpClient(); |
71 HttpClient client = HttpClient.newHttpClient(); |
69 HttpRequest request = HttpRequest.newBuilder(uri) |
72 HttpRequest request = HttpRequest.newBuilder(uri) |
70 .GET() |
73 .GET() |