equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 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. |
58 void doClient() { |
58 void doClient() { |
59 try { |
59 try { |
60 InetSocketAddress address = httpServer.getAddress(); |
60 InetSocketAddress address = httpServer.getAddress(); |
61 |
61 |
62 URL url = new URL("http://" + address.getHostName() + ":" + address.getPort() + "/test/"); |
62 URL url = new URL("http://" + address.getHostName() + ":" + address.getPort() + "/test/"); |
63 HttpURLConnection uc = (HttpURLConnection)url.openConnection(); |
63 HttpURLConnection uc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY); |
64 |
64 |
65 uc.setDoOutput(true); |
65 uc.setDoOutput(true); |
66 uc.setFixedLengthStreamingMode(1); |
66 uc.setFixedLengthStreamingMode(1); |
67 OutputStream os1 = uc.getOutputStream(); |
67 OutputStream os1 = uc.getOutputStream(); |
68 OutputStream os2 = uc.getOutputStream(); |
68 OutputStream os2 = uc.getOutputStream(); |
85 } |
85 } |
86 /** |
86 /** |
87 * Http Server |
87 * Http Server |
88 */ |
88 */ |
89 void startHttpServer() throws IOException { |
89 void startHttpServer() throws IOException { |
90 httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(0), 0); |
90 InetAddress address = InetAddress.getLocalHost(); |
|
91 if (!InetAddress.getByName(address.getHostName()).equals(address)) { |
|
92 // if this happens then we should possibly change the client |
|
93 // side to use the address literal in its URL instead of |
|
94 // the host name. |
|
95 throw new IOException(address.getHostName() |
|
96 + " resolves to " |
|
97 + InetAddress.getByName(address.getHostName()) |
|
98 + " not to " |
|
99 + address + ": check host configuration."); |
|
100 } |
|
101 httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(address, 0), 0); |
91 HttpContext ctx = httpServer.createContext("/test/", new MyHandler()); |
102 HttpContext ctx = httpServer.createContext("/test/", new MyHandler()); |
92 httpServer.start(); |
103 httpServer.start(); |
93 } |
104 } |
94 |
105 |
95 class MyHandler implements HttpHandler { |
106 class MyHandler implements HttpHandler { |