author | chegar |
Fri, 27 Sep 2019 09:55:35 +0100 | |
changeset 58365 | 73950479184b |
parent 54681 | edd709e64ea1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54681
edd709e64ea1
8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5165 | 7 |
* published by the Free Software Foundation. |
2 | 8 |
* |
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 5052093 |
|
30820 | 27 |
* @modules java.base/sun.net.www java.base/sun.net.www.protocol.file |
2 | 28 |
* @library ../../../sun/net/www/httptest/ |
13788 | 29 |
* @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction |
2 | 30 |
* @run main B5052093 |
31 |
* @summary URLConnection doesn't support large files |
|
32 |
*/ |
|
33 |
import java.net.*; |
|
34 |
import java.io.*; |
|
35 |
import sun.net.www.protocol.file.FileURLConnection; |
|
58365
73950479184b
8231504: Update networking tests to avoid implicit dependency on the system proxies
chegar
parents:
54681
diff
changeset
|
36 |
import static java.net.Proxy.NO_PROXY; |
2 | 37 |
|
38 |
public class B5052093 implements HttpCallback { |
|
13788 | 39 |
private static TestHttpServer server; |
2 | 40 |
private static long testSize = ((long) (Integer.MAX_VALUE)) + 2; |
41 |
||
42 |
public static class LargeFile extends File { |
|
43 |
public LargeFile() { |
|
44 |
super("/dev/zero"); |
|
45 |
} |
|
46 |
||
47 |
public long length() { |
|
48 |
return testSize; |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
public static class LargeFileURLConnection extends FileURLConnection { |
|
53 |
public LargeFileURLConnection(LargeFile f) throws IOException { |
|
54 |
super(new URL("file:///dev/zero"), f); |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
public void request(HttpTransaction req) { |
|
59 |
try { |
|
60 |
req.setResponseHeader("content-length", Long.toString(testSize)); |
|
61 |
req.sendResponse(200, "OK"); |
|
62 |
} catch (IOException e) { |
|
63 |
e.printStackTrace(); |
|
64 |
} |
|
65 |
} |
|
66 |
||
67 |
public static void main(String[] args) throws Exception { |
|
54681
edd709e64ea1
8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents:
47216
diff
changeset
|
68 |
InetAddress loopback = InetAddress.getLoopbackAddress(); |
edd709e64ea1
8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents:
47216
diff
changeset
|
69 |
server = new TestHttpServer(new B5052093(), 1, 10, loopback, 0); |
5165 | 70 |
try { |
54681
edd709e64ea1
8223145: Replace wildcard address with loopback or local host in tests - part 1
dfuchs
parents:
47216
diff
changeset
|
71 |
URL url = new URL("http://" + server.getAuthority() + "/foo"); |
58365
73950479184b
8231504: Update networking tests to avoid implicit dependency on the system proxies
chegar
parents:
54681
diff
changeset
|
72 |
URLConnection conn = url.openConnection(NO_PROXY); |
5165 | 73 |
int i = conn.getContentLength(); |
74 |
long l = conn.getContentLengthLong(); |
|
75 |
if (i != -1 || l != testSize) { |
|
76 |
System.out.println("conn.getContentLength = " + i); |
|
77 |
System.out.println("conn.getContentLengthLong = " + l); |
|
78 |
System.out.println("testSize = " + testSize); |
|
79 |
throw new RuntimeException("Wrong content-length from http"); |
|
80 |
} |
|
2 | 81 |
|
5165 | 82 |
URLConnection fu = new LargeFileURLConnection(new LargeFile()); |
83 |
i = fu.getContentLength(); |
|
84 |
l = fu.getContentLengthLong(); |
|
85 |
if (i != -1 || l != testSize) { |
|
86 |
System.out.println("fu.getContentLength = " + i); |
|
87 |
System.out.println("fu.getContentLengthLong = " + l); |
|
88 |
System.out.println("testSize = " + testSize); |
|
89 |
throw new RuntimeException("Wrong content-length from file"); |
|
90 |
} |
|
91 |
} finally { |
|
92 |
server.terminate(); |
|
93 |
} |
|
2 | 94 |
} |
95 |
} |