author | alanb |
Thu, 30 May 2019 07:19:19 +0100 | |
changeset 55102 | 59567035d279 |
parent 52121 | 934969c63223 |
child 55309 | 8081b181bba8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55102 | 2 |
* Copyright (c) 2005, 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 |
|
7 |
* published by the Free Software Foundation. |
|
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 6270015 |
|
52121
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
47216
diff
changeset
|
27 |
* @library /test/lib |
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
47216
diff
changeset
|
28 |
* @build jdk.test.lib.net.SimpleSSLContext |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
29 |
* @run main/othervm Test1 |
55102 | 30 |
* @run main/othervm -Djdk.net.usePlainSocketImpl Test1 |
7271 | 31 |
* @run main/othervm -Dsun.net.httpserver.maxReqTime=10 Test1 |
10130
254e206a89d8
7068416: Lightweight HTTP Server should support TCP_NODELAY
chegar
parents:
7668
diff
changeset
|
32 |
* @run main/othervm -Dsun.net.httpserver.nodelay=true Test1 |
2 | 33 |
* @summary Light weight HTTP server |
34 |
*/ |
|
35 |
||
36 |
import com.sun.net.httpserver.*; |
|
37 |
||
38 |
import java.util.concurrent.*; |
|
39 |
import java.io.*; |
|
40 |
import java.net.*; |
|
41 |
import javax.net.ssl.*; |
|
52121
934969c63223
8211978: Move testlibrary/jdk/testlibrary/SimpleSSLContext.java and testkeys to network testlibrary
jjiang
parents:
47216
diff
changeset
|
42 |
import jdk.test.lib.net.SimpleSSLContext; |
2 | 43 |
|
44 |
/* basic http/s connectivity test |
|
45 |
* Tests: |
|
46 |
* - client/server |
|
47 |
* - send/receive large/small file |
|
48 |
* - chunked encoding |
|
49 |
* - via http and https |
|
10130
254e206a89d8
7068416: Lightweight HTTP Server should support TCP_NODELAY
chegar
parents:
7668
diff
changeset
|
50 |
* |
254e206a89d8
7068416: Lightweight HTTP Server should support TCP_NODELAY
chegar
parents:
7668
diff
changeset
|
51 |
* The test is also run with sun.net.httpserver.nodelay simply to exercise |
254e206a89d8
7068416: Lightweight HTTP Server should support TCP_NODELAY
chegar
parents:
7668
diff
changeset
|
52 |
* this option. There is no specific pass or failure related to running with |
254e206a89d8
7068416: Lightweight HTTP Server should support TCP_NODELAY
chegar
parents:
7668
diff
changeset
|
53 |
* this option. |
2 | 54 |
*/ |
55 |
||
56 |
public class Test1 extends Test { |
|
57 |
||
58 |
static SSLContext ctx; |
|
59 |
||
60 |
public static void main (String[] args) throws Exception { |
|
61 |
HttpServer s1 = null; |
|
62 |
HttpsServer s2 = null; |
|
63 |
ExecutorService executor=null; |
|
64 |
try { |
|
65 |
String root = System.getProperty ("test.src")+ "/docs"; |
|
66 |
System.out.print ("Test1: "); |
|
67 |
InetSocketAddress addr = new InetSocketAddress (0); |
|
68 |
s1 = HttpServer.create (addr, 0); |
|
69 |
if (s1 instanceof HttpsServer) { |
|
70 |
throw new RuntimeException ("should not be httpsserver"); |
|
71 |
} |
|
72 |
s2 = HttpsServer.create (addr, 0); |
|
73 |
HttpHandler h = new FileServerHandler (root); |
|
74 |
HttpContext c1 = s1.createContext ("/test1", h); |
|
75 |
HttpContext c2 = s2.createContext ("/test1", h); |
|
76 |
executor = Executors.newCachedThreadPool(); |
|
77 |
s1.setExecutor (executor); |
|
78 |
s2.setExecutor (executor); |
|
26206
fb87c4051d65
8055747: Move SimpleSSLContext to jdk/testlibrary
michaelm
parents:
14342
diff
changeset
|
79 |
ctx = new SimpleSSLContext().get(); |
2 | 80 |
s2.setHttpsConfigurator(new HttpsConfigurator (ctx)); |
81 |
s1.start(); |
|
82 |
s2.start(); |
|
83 |
||
84 |
int port = s1.getAddress().getPort(); |
|
85 |
int httpsport = s2.getAddress().getPort(); |
|
86 |
test (true, "http", root+"/test1", port, "smallfile.txt", 23); |
|
87 |
test (true, "http", root+"/test1", port, "largefile.txt", 2730088); |
|
88 |
test (true, "https", root+"/test1", httpsport, "smallfile.txt", 23); |
|
89 |
test (true, "https", root+"/test1", httpsport, "largefile.txt", 2730088); |
|
90 |
test (false, "http", root+"/test1", port, "smallfile.txt", 23); |
|
91 |
test (false, "http", root+"/test1", port, "largefile.txt", 2730088); |
|
92 |
test (false, "https", root+"/test1", httpsport, "smallfile.txt", 23); |
|
93 |
test (false, "https", root+"/test1", httpsport, "largefile.txt", 2730088); |
|
94 |
System.out.println ("OK"); |
|
95 |
} finally { |
|
96 |
delay(); |
|
3070
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
97 |
if (s1 != null) |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
98 |
s1.stop(2); |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
99 |
if (s2 != null) |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
100 |
s2.stop(2); |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
101 |
if (executor != null) |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
102 |
executor.shutdown (); |
2 | 103 |
} |
104 |
} |
|
105 |
||
106 |
static void test (boolean fixedLen, String protocol, String root, int port, String f, int size) throws Exception { |
|
107 |
URL url = new URL (protocol+"://localhost:"+port+"/test1/"+f); |
|
108 |
HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); |
|
109 |
if (urlc instanceof HttpsURLConnection) { |
|
110 |
HttpsURLConnection urlcs = (HttpsURLConnection) urlc; |
|
111 |
urlcs.setHostnameVerifier (new HostnameVerifier () { |
|
112 |
public boolean verify (String s, SSLSession s1) { |
|
113 |
return true; |
|
114 |
} |
|
115 |
}); |
|
116 |
urlcs.setSSLSocketFactory (ctx.getSocketFactory()); |
|
117 |
} |
|
118 |
byte [] buf = new byte [4096]; |
|
119 |
||
120 |
if (fixedLen) { |
|
121 |
urlc.setRequestProperty ("XFixed", "yes"); |
|
122 |
} |
|
123 |
InputStream is = urlc.getInputStream(); |
|
124 |
File temp = File.createTempFile ("Test1", null); |
|
125 |
temp.deleteOnExit(); |
|
126 |
OutputStream fout = new BufferedOutputStream (new FileOutputStream(temp)); |
|
127 |
int c, count = 0; |
|
128 |
while ((c=is.read(buf)) != -1) { |
|
129 |
count += c; |
|
130 |
fout.write (buf, 0, c); |
|
131 |
} |
|
132 |
is.close(); |
|
133 |
fout.close(); |
|
134 |
||
135 |
if (count != size) { |
|
136 |
throw new RuntimeException ("wrong amount of data returned"); |
|
137 |
} |
|
138 |
String orig = root + "/" + f; |
|
139 |
compare (new File(orig), temp); |
|
140 |
temp.delete(); |
|
141 |
} |
|
142 |
||
143 |
/* compare the contents of the two files */ |
|
144 |
||
145 |
static void compare (File f1, File f2) throws IOException { |
|
146 |
InputStream i1 = new BufferedInputStream (new FileInputStream(f1)); |
|
147 |
InputStream i2 = new BufferedInputStream (new FileInputStream(f2)); |
|
148 |
||
149 |
int c1,c2; |
|
150 |
try { |
|
151 |
while ((c1=i1.read()) != -1) { |
|
152 |
c2 = i2.read(); |
|
153 |
if (c1 != c2) { |
|
154 |
throw new RuntimeException ("file compare failed 1"); |
|
155 |
} |
|
156 |
} |
|
157 |
if (i2.read() != -1) { |
|
158 |
throw new RuntimeException ("file compare failed 2"); |
|
159 |
} |
|
160 |
} finally { |
|
161 |
i1.close(); |
|
162 |
i2.close(); |
|
163 |
} |
|
164 |
} |
|
165 |
} |