/* * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
assertEquals(response.statusCode(), 200);
assertEquals(response.body().getFileName().toString(), expectedFilename);
assertTrue(response.headers().firstValue("Content-Disposition").isPresent());
assertEquals(response.headers().firstValue("Content-Disposition").get(),
contentDispositionValue);
assertEquals(fileContents, "May the luck of the Irish be with you!");
// additional checks unrelated to file download
caseInsensitivityOfHeaders(request.headers());
caseInsensitivityOfHeaders(response.headers());
} finally {
client = null;
System.gc(); while (!ref.refersTo(null)) {
System.gc(); if (queue.remove(100) == ref) break;
}
AssertionError failed = TRACKER.checkShutdown(1000); if (failed != null) throw failed;
}
}
@BeforeTest publicvoid setup() throws Exception {
tempDir = Paths.get("asFileDownloadTest.tmp.dir"); if (Files.exists(tempDir)) thrownew AssertionError("Unexpected test work dir existence: " + tempDir.toString());
Files.createDirectory(tempDir); // Unique dirs per test run, based on the URI path
Files.createDirectories(tempDir.resolve("http1/afdt/"));
Files.createDirectories(tempDir.resolve("https1/afdt/"));
Files.createDirectories(tempDir.resolve("http2/afdt/"));
Files.createDirectories(tempDir.resolve("https2/afdt/"));
// HTTP/1.1 server logging in case of security exceptions ( uncomment if needed ) //Logger logger = Logger.getLogger("com.sun.net.httpserver"); //ConsoleHandler ch = new ConsoleHandler(); //logger.setLevel(Level.ALL); //ch.setLevel(Level.ALL); //logger.addHandler(ch);
sslContext = new SimpleSSLContext().get(); if (sslContext == null) thrownew AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
httpTestServer = HttpServer.create(sa, 0);
httpTestServer.createContext("/http1/afdt", new Http1FileDispoHandler());
httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/afdt";
if (System.getSecurityManager() == null && Files.exists(tempDir)) { // clean up before next run with security manager
FileUtils.deleteFileTreeWithRetry(tempDir);
}
}
String value = contentDispositionValueFromURI(t.getRequestURI()); if (!value.equals("<<NOT_PRESENT>>"))
t.getResponseHeaders().set("Content-Disposition", value);
String value = contentDispositionValueFromURI(t.getRequestURI()); if (!value.equals("<<NOT_PRESENT>>"))
t.getResponseHeaders().addHeader("Content-Disposition", value);
// Asserts case-insensitivity of headers (nothing to do with file // download, just convenient as we have a couple of header instances. ) staticvoid caseInsensitivityOfHeaders(HttpHeaders headers) { try { for (Map.Entry<String, List<String>> entry : headers.map().entrySet()) {
String headerName = entry.getKey();
List<String> headerValue = entry.getValue();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.