diff --git a/org.jgrapes.http.freemarker/test/org/jgrapes/http/freemarker/test/GetTest.java b/org.jgrapes.http.freemarker/test/org/jgrapes/http/freemarker/test/GetTest.java index efb9cf29638..09f3f61bdca 100644 --- a/org.jgrapes.http.freemarker/test/org/jgrapes/http/freemarker/test/GetTest.java +++ b/org.jgrapes.http.freemarker/test/org/jgrapes/http/freemarker/test/GetTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.text.ParseException; @@ -82,11 +83,12 @@ public void stopServer() throws InterruptedException { @Test(timeout = 5000) public void testGetSimpleWithoutPrefix() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { server.attach(new ContentProvider(server.channel(), GetTest.class.getClassLoader(), "templates", URI.create("/"))); - URL url = new URL("http", "localhost", server.getPort(), - "/simple.ftl.html"); + URL url = new URI("http", null, "localhost", server.getPort(), + "/simple.ftl.html", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(4000); conn.setReadTimeout(4000); @@ -101,11 +103,12 @@ public void testGetSimpleWithoutPrefix() @Test(timeout = 5000) public void testGetStaticWithoutPrefix() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { server.attach(new ContentProvider(server.channel(), GetTest.class.getClassLoader(), "templates", URI.create("/"))); - URL url = new URL("http", "localhost", server.getPort(), - "/Readme.txt"); + URL url = new URI("http", null, "localhost", server.getPort(), + "/Readme.txt", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(4000); conn.setReadTimeout(4000); @@ -120,12 +123,13 @@ public void testGetStaticWithoutPrefix() @Test(timeout = 5000) public void testGetSimpleWithPrefix() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { server.attach(new ContentProvider(server.channel(), GetTest.class.getClassLoader(), "templates", URI.create("/generated/"))); - URL url = new URL("http", "localhost", server.getPort(), - "/generated/simple.ftl.html"); + URL url = new URI("http", null, "localhost", server.getPort(), + "/generated/simple.ftl.html", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(4000); conn.setReadTimeout(4000); @@ -140,12 +144,13 @@ public void testGetSimpleWithPrefix() @Test(timeout = 5000) public void testGetStaticWithPrefix() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { server.attach(new ContentProvider(server.channel(), GetTest.class.getClassLoader(), "templates", URI.create("/generated/"))); - URL url = new URL("http", "localhost", server.getPort(), - "/generated/Readme.txt"); + URL url = new URI("http", null, "localhost", server.getPort(), + "/generated/Readme.txt", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(4000); conn.setReadTimeout(4000); diff --git a/org.jgrapes.http/test/org/jgrapes/http/test/ClientTest.java b/org.jgrapes.http/test/org/jgrapes/http/test/ClientTest.java index a03c6d43164..78393cf3367 100644 --- a/org.jgrapes.http/test/org/jgrapes/http/test/ClientTest.java +++ b/org.jgrapes.http/test/org/jgrapes/http/test/ClientTest.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.CharBuffer; import java.text.ParseException; @@ -250,8 +252,10 @@ public static void stopApps() throws InterruptedException { @Test(timeout = 1500) public void testUnknownHost() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL(protocol, "never.ever.known", srvPort(), "/"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI(protocol, null, "never.ever.known", srvPort(), "/", + null, null).toURL(); WaitForTests doneWaiter = new WaitForTests<>(clntApp, ErrorReceived.class, clntApp.defaultCriterion()); clntApp.startRequest(new Request.Out.Get(url), channel -> { @@ -262,9 +266,11 @@ public void testUnknownHost() @Test(timeout = 1500) public void testConnectionRefused() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { // Though not impossible, it's highly unlikely to have a server here - URL url = new URL(protocol, "localhost", srvPort() + 1, "/top"); + URL url = new URI(protocol, null, "localhost", srvPort() + 1, "/top", + null, null).toURL(); WaitForTests doneWaiter = new WaitForTests<>(clntApp, ErrorReceived.class, clntApp.defaultCriterion()); clntApp.startRequest(new Request.Out.Get(url), channel -> { @@ -275,8 +281,10 @@ public void testConnectionRefused() @Test(timeout = 1500) public void testGetMatchTop() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL(protocol, "localhost", srvPort(), "/top"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI(protocol, null, "localhost", srvPort(), "/top", + null, null).toURL(); WaitForTests done = new WaitForTests<>(clntApp, InputReceived.class, clntApp.defaultCriterion()); clntApp.startRequest(new Request.Out.Get(url), channel -> { @@ -291,8 +299,10 @@ public void testGetMatchTop() @Test(timeout = 1500) public void testPost() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL(protocol, "localhost", srvPort(), "/reflect"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI(protocol, null, "localhost", srvPort(), "/reflect", + null, null).toURL(); Request.Out.Post post = new Request.Out.Post(url); post.httpRequest().setField("Content-Type", "text/plain; charset=utf-8"); @@ -318,9 +328,10 @@ public void testPost() @Test(timeout = 1500) public void testWsEcho() - throws IOException, InterruptedException, ExecutionException { - URL url - = new URL(protocol, "localhost", srvPort(), "/ws/echo?store=42"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI(protocol, null, "localhost", srvPort(), + "/ws/echo", "store=42", null).toURL(); Request.Out.Get upgrade = new Request.Out.Get(url); upgrade.httpRequest().setField(HttpField.UPGRADE, new StringList("websocket")); @@ -366,8 +377,10 @@ public void testWsEcho() @Test(timeout = 1500) public void testWsClientClose() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL(protocol, "localhost", srvPort(), "/ws/echo"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI(protocol, null, "localhost", srvPort(), "/ws/echo", + null, null).toURL(); Request.Out.Get upgrade = new Request.Out.Get(url); upgrade.httpRequest().setField(HttpField.UPGRADE, new StringList("websocket")); diff --git a/org.jgrapes.http/test/org/jgrapes/http/test/GetTest.java b/org.jgrapes.http/test/org/jgrapes/http/test/GetTest.java index 33254d64604..d71f2437e3e 100644 --- a/org.jgrapes.http/test/org/jgrapes/http/test/GetTest.java +++ b/org.jgrapes.http/test/org/jgrapes/http/test/GetTest.java @@ -24,6 +24,8 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLConnection; @@ -172,9 +174,11 @@ public static void stopServer() throws InterruptedException { @Test(timeout = 1500) public void testNoGetRoot() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { try { - URL url = new URL("http", "localhost", server.getPort(), "/"); + URL url = new URI("http", null, "localhost", server.getPort(), "/", + null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); @@ -188,10 +192,11 @@ public void testNoGetRoot() @Test(timeout = 1500) public void testNotFoundStatusOnly() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { try { - URL url = new URL("http", "localhost", server.getPort(), - "/not-found-status-only"); + URL url = new URI("http", null, "localhost", server.getPort(), + "/not-found-status-only", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); @@ -205,8 +210,10 @@ public void testNotFoundStatusOnly() @Test(timeout = 1500) public void testGetMatchTop() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL("http", "localhost", server.getPort(), "/top"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI("http", null, "localhost", server.getPort(), "/top", + null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); @@ -220,8 +227,10 @@ public void testGetMatchTop() @Test(timeout = 1500) public void testGetMatchTopPlus() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL("http", "localhost", server.getPort(), "/top/plus"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI("http", null, "localhost", server.getPort(), + "/top/plus", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); @@ -231,8 +240,10 @@ public void testGetMatchTopPlus() @Test(timeout = 1500) public void testGetMatchDynamic() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL("http", "localhost", server.getPort(), "/dynamic"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI("http", null, "localhost", server.getPort(), + "/dynamic", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); @@ -246,9 +257,10 @@ public void testGetMatchDynamic() @Test(timeout = 2500) public void testGetUnversionedStatic() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL("http", "localhost", server.getPort(), - "/static-content/index.html"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI("http", null, "localhost", server.getPort(), + "/static-content/index.html", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(2000); conn.setReadTimeout(2000); @@ -262,9 +274,10 @@ public void testGetUnversionedStatic() @Test(timeout = 2500) public void testGetVersionedStatic() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL("http", "localhost", server.getPort(), - "/static-content/versioned-1.0.0.html"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI("http", null, "localhost", server.getPort(), + "/static-content/versioned-1.0.0.html", null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(2000); conn.setReadTimeout(2000); @@ -278,9 +291,10 @@ public void testGetVersionedStatic() @Test(timeout = 2500) public void testGetFromJar() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL("http", "localhost", server.getPort(), - "/from-jar/static-content/index.html"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI("http", null, "localhost", server.getPort(), + "/from-jar/static-content/index.html", null, null).toURL(); // Unconditional fetch URLConnection conn = url.openConnection(); conn.setConnectTimeout(2000); diff --git a/org.jgrapes.http/test/org/jgrapes/http/test/NotFoundTests.java b/org.jgrapes.http/test/org/jgrapes/http/test/NotFoundTests.java index b80d41d8f2f..170df231cea 100644 --- a/org.jgrapes.http/test/org/jgrapes/http/test/NotFoundTests.java +++ b/org.jgrapes.http/test/org/jgrapes/http/test/NotFoundTests.java @@ -20,6 +20,8 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.util.concurrent.ExecutionException; @@ -59,9 +61,11 @@ public static void stopServer() throws InterruptedException { @Test(timeout = 1500) public void testGetRoot() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { try { - URL url = new URL("http", "localhost", server.getPort(), "/"); + URL url = new URI("http", null, "localhost", server.getPort(), "/", + null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); diff --git a/org.jgrapes.http/test/org/jgrapes/http/test/PostTest.java b/org.jgrapes.http/test/org/jgrapes/http/test/PostTest.java index 3c84e8a81ef..b426d7b3902 100644 --- a/org.jgrapes.http/test/org/jgrapes/http/test/PostTest.java +++ b/org.jgrapes.http/test/org/jgrapes/http/test/PostTest.java @@ -23,6 +23,8 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.concurrent.ExecutionException; import org.jgrapes.core.Channel; @@ -69,8 +71,10 @@ public static void stopServer() throws InterruptedException { @Test(timeout = 1500) public void testPost() - throws IOException, InterruptedException, ExecutionException { - URL url = new URL("http", "localhost", server.getPort(), "/reflect"); + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { + URL url = new URI("http", null, "localhost", server.getPort(), + "/reflect", null, null).toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); diff --git a/org.jgrapes.http/test/org/jgrapes/http/test/ServerTest.java b/org.jgrapes.http/test/org/jgrapes/http/test/ServerTest.java index a0b375419a4..e6998b90167 100644 --- a/org.jgrapes.http/test/org/jgrapes/http/test/ServerTest.java +++ b/org.jgrapes.http/test/org/jgrapes/http/test/ServerTest.java @@ -24,6 +24,8 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.InetSocketAddress; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Paths; import java.security.KeyManagementException; @@ -199,10 +201,11 @@ public static void stopServer() throws InterruptedException { @Test public void testConcurrentGetRoot() throws IOException, InterruptedException, ExecutionException, - TimeoutException { + TimeoutException, URISyntaxException { Waiter waiter = new Waiter(); - URL url = new URL("https", "localhost", server.getPort(), "/"); + URL url = new URI("https", null, "localhost", server.getPort(), "/", + null, null).toURL(); int threadCount = 1000; if (Boolean.parseBoolean( diff --git a/org.jgrapes.http/test/org/jgrapes/http/test/UnsupportedProtocolTests.java b/org.jgrapes.http/test/org/jgrapes/http/test/UnsupportedProtocolTests.java index fa810356419..8826aa4c3ba 100644 --- a/org.jgrapes.http/test/org/jgrapes/http/test/UnsupportedProtocolTests.java +++ b/org.jgrapes.http/test/org/jgrapes/http/test/UnsupportedProtocolTests.java @@ -19,6 +19,8 @@ package org.jgrapes.http.test; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.util.concurrent.ExecutionException; @@ -49,9 +51,11 @@ public static void stopServer() throws InterruptedException { @Test(timeout = 1500) public void testGetRoot() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException, ExecutionException, + URISyntaxException { try { - URL url = new URL("http", "localhost", server.getPort(), "/"); + URL url = new URI("http", null, "localhost", server.getPort(), "/", + null, null).toURL(); URLConnection conn = url.openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); diff --git a/org.jgrapes.io/src/org/jgrapes/io/util/ManagedBufferPool.java b/org.jgrapes.io/src/org/jgrapes/io/util/ManagedBufferPool.java index 5ca273e6bfb..99db6bac0b5 100644 --- a/org.jgrapes.io/src/org/jgrapes/io/util/ManagedBufferPool.java +++ b/org.jgrapes.io/src/org/jgrapes/io/util/ManagedBufferPool.java @@ -798,8 +798,7 @@ private static final class MBeanView implements ManagedBufferPoolMXBean { private static Set> allPools = Collections.synchronizedSet( - Collections.newSetFromMap( - new WeakHashMap, Boolean>())); + Collections.newSetFromMap(new WeakHashMap<>())); /** * Adds the pool.