21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @summary Basic test for asFileDownload |
26 * @summary Basic test for ofFileDownload |
27 * @bug 8196965 |
27 * @bug 8196965 |
28 * @modules java.base/sun.net.www.http |
28 * @modules java.base/sun.net.www.http |
29 * java.net.http/jdk.internal.net.http.common |
29 * java.net.http/jdk.internal.net.http.common |
30 * java.net.http/jdk.internal.net.http.frame |
30 * java.net.http/jdk.internal.net.http.frame |
31 * java.net.http/jdk.internal.net.http.hpack |
31 * java.net.http/jdk.internal.net.http.hpack |
35 * @build Http2TestServer |
35 * @build Http2TestServer |
36 * @build jdk.testlibrary.SimpleSSLContext |
36 * @build jdk.testlibrary.SimpleSSLContext |
37 * @build jdk.test.lib.Platform |
37 * @build jdk.test.lib.Platform |
38 * @build jdk.test.lib.util.FileUtils |
38 * @build jdk.test.lib.util.FileUtils |
39 * @run testng/othervm AsFileDownloadTest |
39 * @run testng/othervm AsFileDownloadTest |
|
40 * @run testng/othervm/java.security.policy=AsFileDownloadTest.policy AsFileDownloadTest |
40 */ |
41 */ |
41 |
42 |
42 import com.sun.net.httpserver.HttpExchange; |
43 import com.sun.net.httpserver.HttpExchange; |
43 import com.sun.net.httpserver.HttpHandler; |
44 import com.sun.net.httpserver.HttpHandler; |
44 import com.sun.net.httpserver.HttpServer; |
45 import com.sun.net.httpserver.HttpServer; |
59 import java.nio.file.Path; |
60 import java.nio.file.Path; |
60 import java.nio.file.Paths; |
61 import java.nio.file.Paths; |
61 import java.util.ArrayList; |
62 import java.util.ArrayList; |
62 import java.util.Arrays; |
63 import java.util.Arrays; |
63 import java.util.List; |
64 import java.util.List; |
|
65 import java.util.logging.ConsoleHandler; |
|
66 import java.util.logging.Level; |
|
67 import java.util.logging.Logger; |
64 import javax.net.ssl.SSLContext; |
68 import javax.net.ssl.SSLContext; |
65 import jdk.testlibrary.SimpleSSLContext; |
69 import jdk.testlibrary.SimpleSSLContext; |
66 import jdk.test.lib.util.FileUtils; |
70 import jdk.test.lib.util.FileUtils; |
67 import org.testng.annotations.AfterTest; |
71 import org.testng.annotations.AfterTest; |
68 import org.testng.annotations.BeforeTest; |
72 import org.testng.annotations.BeforeTest; |
249 // -- Infrastructure |
253 // -- Infrastructure |
250 |
254 |
251 @BeforeTest |
255 @BeforeTest |
252 public void setup() throws Exception { |
256 public void setup() throws Exception { |
253 tempDir = Paths.get("asFileDownloadTest.tmp.dir"); |
257 tempDir = Paths.get("asFileDownloadTest.tmp.dir"); |
254 FileUtils.deleteFileIfExistsWithRetry(tempDir); |
258 if (Files.exists(tempDir)) |
|
259 throw new AssertionError("Unexpected test work dir existence: " + tempDir.toString()); |
|
260 |
255 Files.createDirectory(tempDir); |
261 Files.createDirectory(tempDir); |
256 // Unique dirs per test run, based on the URI path |
262 // Unique dirs per test run, based on the URI path |
257 Files.createDirectories(tempDir.resolve("http1/afdt/")); |
263 Files.createDirectories(tempDir.resolve("http1/afdt/")); |
258 Files.createDirectories(tempDir.resolve("https1/afdt/")); |
264 Files.createDirectories(tempDir.resolve("https1/afdt/")); |
259 Files.createDirectories(tempDir.resolve("http2/afdt/")); |
265 Files.createDirectories(tempDir.resolve("http2/afdt/")); |
260 Files.createDirectories(tempDir.resolve("https2/afdt/")); |
266 Files.createDirectories(tempDir.resolve("https2/afdt/")); |
261 |
267 |
|
268 // HTTP/1.1 server logging in case of security exceptions ( uncomment if needed ) |
|
269 //Logger logger = Logger.getLogger("com.sun.net.httpserver"); |
|
270 //ConsoleHandler ch = new ConsoleHandler(); |
|
271 //logger.setLevel(Level.ALL); |
|
272 //ch.setLevel(Level.ALL); |
|
273 //logger.addHandler(ch); |
|
274 |
262 sslContext = new SimpleSSLContext().get(); |
275 sslContext = new SimpleSSLContext().get(); |
263 if (sslContext == null) |
276 if (sslContext == null) |
264 throw new AssertionError("Unexpected null sslContext"); |
277 throw new AssertionError("Unexpected null sslContext"); |
265 |
278 |
266 InetSocketAddress sa = new InetSocketAddress(0); |
279 InetSocketAddress sa = new InetSocketAddress(0); |
293 public void teardown() throws Exception { |
306 public void teardown() throws Exception { |
294 httpTestServer.stop(0); |
307 httpTestServer.stop(0); |
295 httpsTestServer.stop(0); |
308 httpsTestServer.stop(0); |
296 http2TestServer.stop(); |
309 http2TestServer.stop(); |
297 https2TestServer.stop(); |
310 https2TestServer.stop(); |
|
311 |
|
312 if (System.getSecurityManager() == null && Files.exists(tempDir)) { |
|
313 // clean up before next run with security manager |
|
314 FileUtils.deleteFileTreeWithRetry(tempDir); |
|
315 } |
298 } |
316 } |
299 |
317 |
300 static String contentDispositionValueFromURI(URI uri) { |
318 static String contentDispositionValueFromURI(URI uri) { |
301 String queryIndex = uri.getQuery(); |
319 String queryIndex = uri.getQuery(); |
302 String[][] values; |
320 String[][] values; |