equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 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. |
41 final static int LEN = 16 * 1024; |
41 final static int LEN = 16 * 1024; |
42 |
42 |
43 public static void main(String[] args) throws Exception { |
43 public static void main(String[] args) throws Exception { |
44 |
44 |
45 TestCache.reset(); |
45 TestCache.reset(); |
46 HttpServer s = HttpServer.create (new InetSocketAddress(0), 10); |
46 InetAddress loopback = InetAddress.getLoopbackAddress(); |
47 s.createContext ("/", new HttpHandler () { |
47 HttpServer s = HttpServer.create(new InetSocketAddress(loopback, 0), 10); |
48 public void handle (HttpExchange e) { |
48 s.createContext("/", new HttpHandler() { |
|
49 public void handle(HttpExchange e) { |
49 try { |
50 try { |
50 byte[] buf = new byte [LEN]; |
51 byte[] buf = new byte [LEN]; |
51 OutputStream o = e.getResponseBody(); |
52 OutputStream o = e.getResponseBody(); |
52 e.sendResponseHeaders(200, LEN); |
53 e.sendResponseHeaders(200, LEN); |
53 o.write (buf); |
54 o.write(buf); |
54 e.close(); |
55 e.close(); |
55 } catch (IOException ex) { |
56 } catch (IOException ex) { |
56 ex.printStackTrace(); |
57 ex.printStackTrace(); |
57 TestCache.fail = true; |
58 TestCache.fail = true; |
58 } |
59 } |
89 } |
90 } |
90 s.stop(0); |
91 s.stop(0); |
91 } |
92 } |
92 |
93 |
93 if (TestCache.fail) { |
94 if (TestCache.fail) { |
94 System.out.println ("TEST FAILED"); |
95 System.out.println("TEST FAILED"); |
95 throw new RuntimeException (); |
96 throw new RuntimeException(); |
96 } else { |
97 } else { |
97 System.out.println ("TEST OK"); |
98 System.out.println("TEST OK"); |
98 } |
99 } |
99 } |
100 } |
100 } |
101 } |