Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, 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
Expand Down Expand Up @@ -38,6 +38,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.xml.catalog.Catalog;
import javax.xml.catalog.CatalogException;
Expand All @@ -49,20 +51,21 @@
import static java.nio.file.StandardOpenOption.CREATE;
import static jaxp.library.JAXPTestUtilities.getSystemProperty;

import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
import jdk.test.lib.net.URIBuilder;
import jdk.test.lib.util.JarUtils;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.InputSource;
import jdk.test.lib.net.SimpleHttpServer;

/*
* @test
* @bug 8151154 8171243
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest /test/lib
* @build jdk.test.lib.net.SimpleHttpServer
* @run testng/othervm catalog.CatalogFileInputTest
* @summary Verifies that the Catalog API accepts valid URIs only;
* Verifies that the CatalogFeatures' builder throws
Expand All @@ -81,9 +84,9 @@ public class CatalogFileInputTest extends CatalogSupportBase {
final static String SCHEME_JARFILE = "jar:";
static final String REMOTE_FILE_LOCATION = "/jar/META-INF";
static final String DOCROOT = SRC_DIR;
static final String TESTCONTEXT = REMOTE_FILE_LOCATION; //mapped to local file path
private SimpleHttpServer httpserver;
private HttpServer httpserver;
private String remoteFilePath;
private ExecutorService executor;

/*
* Initializing fields
Expand All @@ -92,15 +95,23 @@ public class CatalogFileInputTest extends CatalogSupportBase {
public void setUpClass() throws Exception {
super.setUp();
// set up HttpServer
httpserver = new SimpleHttpServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), TESTCONTEXT, DOCROOT);
httpserver = SimpleFileServer.createFileServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0),
Path.of(DOCROOT), SimpleFileServer.OutputLevel.INFO);
executor = Executors.newCachedThreadPool();
httpserver.setExecutor(executor);
httpserver.start();
remoteFilePath = httpserver.getAddress() + REMOTE_FILE_LOCATION;
remoteFilePath = URIBuilder.newBuilder()
.scheme("http")
.host(httpserver.getAddress().getAddress())
.port(httpserver.getAddress().getPort())
.build().toString() + REMOTE_FILE_LOCATION;
}

@AfterClass
protected void tearDown() {
if (httpserver != null) {
httpserver.stop();
httpserver.stop(0);
executor.shutdown();
}
}

Expand Down
71 changes: 0 additions & 71 deletions test/jdk/com/sun/net/httpserver/SimpleFileServer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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
Expand Down Expand Up @@ -28,9 +28,7 @@
* @library /lib/testlibrary/java/util/jar /test/lib
* @modules jdk.jartool
* jdk.compiler
* jdk.httpserver
* @build CreateMultiReleaseTestJars
* jdk.test.lib.net.SimpleHttpServer
* jdk.test.lib.compiler.Compiler
* jdk.test.lib.util.JarBuilder
* @run testng MultiReleaseJarHttpProperties
Expand All @@ -51,29 +49,36 @@
import java.net.InetSocketAddress;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import jdk.test.lib.net.SimpleHttpServer;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
import jdk.test.lib.net.URIBuilder;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class MultiReleaseJarHttpProperties extends MultiReleaseJarProperties {
private SimpleHttpServer server;
private HttpServer server;
private ExecutorService executor;
static final String TESTCONTEXT = "/multi-release.jar"; //mapped to local file path

@BeforeClass
public void initialize() throws Exception {
server = new SimpleHttpServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), TESTCONTEXT,
System.getProperty("user.dir", "."));
server = SimpleFileServer.createFileServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0),
Path.of(System.getProperty("user.dir", ".")), SimpleFileServer.OutputLevel.INFO);
executor = Executors.newCachedThreadPool();
server.setExecutor(executor);
server.start();
super.initialize();
}

@Override
protected void initializeClassLoader() throws Exception {
URL[] urls = new URL[]{
URIBuilder.newBuilder().scheme("http").port(server.getPort()).loopback()
URIBuilder.newBuilder().scheme("http").port(server.getAddress().getPort()).loopback()
.path(TESTCONTEXT).toURL(),
};
cldr = new URLClassLoader(urls);
Expand All @@ -84,8 +89,10 @@ protected void initializeClassLoader() throws Exception {
@AfterClass
public void close() throws IOException {
// Windows requires server to stop before file is deleted
if (server != null)
server.stop();
if (server != null) {
server.stop(0);
executor.shutdown();
}
super.close();
}

Expand Down
27 changes: 17 additions & 10 deletions test/jdk/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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
Expand Down Expand Up @@ -27,10 +27,8 @@
* @summary Test that URL connections to multi-release jars can be runtime versioned
* @library /lib/testlibrary/java/util/jar /test/lib
* @modules jdk.compiler
* jdk.httpserver
* jdk.jartool
* @build CreateMultiReleaseTestJars
* jdk.test.lib.net.SimpleHttpServer
* jdk.test.lib.util.JarBuilder
* jdk.test.lib.compiler.Compiler
* @run testng MultiReleaseJarURLConnection
Expand All @@ -51,11 +49,15 @@
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.jar.JarFile;

import jdk.test.lib.net.SimpleHttpServer;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
import jdk.test.lib.net.URIBuilder;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
Expand All @@ -68,8 +70,8 @@ public class MultiReleaseJarURLConnection {
String unversioned = userdir + "/unversioned.jar";
String unsigned = userdir + "/multi-release.jar";
String signed = userdir + "/signed-multi-release.jar";
static final String TESTCONTEXT = "/multi-release.jar";
SimpleHttpServer server;
HttpServer server;
ExecutorService executor;

@BeforeClass
public void initialize() throws Exception {
Expand All @@ -78,15 +80,20 @@ public void initialize() throws Exception {
creator.buildUnversionedJar();
creator.buildMultiReleaseJar();
creator.buildSignedMultiReleaseJar();
server = new SimpleHttpServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), TESTCONTEXT, System.getProperty("user.dir", "."));
server = SimpleFileServer.createFileServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0),
Path.of(System.getProperty("user.dir", ".")), SimpleFileServer.OutputLevel.INFO);
executor = Executors.newCachedThreadPool();
server.setExecutor(executor);
server.start();
}

@AfterClass
public void close() throws IOException {
// Windows requires server to stop before file is deleted
if (server != null)
server.stop();
server.stop(0);
executor.shutdown();

Files.delete(Paths.get(unversioned));
Files.delete(Paths.get(unsigned));
Files.delete(Paths.get(signed));
Expand Down Expand Up @@ -176,8 +183,8 @@ public Object[][] createResourceData() throws Exception {
{"unsigned", new URL("jar:file:" + unsigned + "!/")},
{"signed", new URL("jar:file:" + signed + "!/")},
// external jar received via http protocol
{"http", toHttpJarURL(server.getPort(), "/multi-release.jar", "!/")},
{"http", URIBuilder.newBuilder().scheme("http").port(server.getPort())
{"http", toHttpJarURL(server.getAddress().getPort(), "/multi-release.jar", "!/")},
{"http", URIBuilder.newBuilder().scheme("http").port(server.getAddress().getPort())
.loopback().path("/multi-release.jar").toURL()},
};
}
Expand Down
Loading