From 6e7b0935ea28069806a7871f3bba969e39d5000d Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Thu, 4 Nov 2021 14:47:48 +0100 Subject: [PATCH 1/3] Update to Vert.x 4.2.1 and related projects. Dependencies: - Update to Vert.x 4.2.1 - Update to Stork 1.0.0.Beta1 - Update to Vert.x Mutiny Bindings 2.15.0 - Update to Quarkus HTTP 4.1.4 Core and HTTP: - New cookie-related methods - Relocation of the CACHE_DIR_BASE_PROP_NAME constant - Update native image configuration for Vert.x Data Source: - New preparedQuery method in Pool Redis: - Signature changes of the lpop, psync and rpop command - The workaround done in Quarkus does not break compatibility Amazon Lambda: - Relocation of the CACHE_DIR_BASE_PROP_NAME constant --- bom/application/pom.xml | 8 ++-- .../deployment/AmazonLambdaHttpProcessor.java | 5 ++- .../deployment/AmazonLambdaHttpProcessor.java | 5 ++- .../reactive/datasource/runtime/TestPool.java | 6 +++ .../io/quarkus/redis/client/RedisClient.java | 6 +++ .../client/reactive/ReactiveRedisClient.java | 12 ++++++ .../runtime/ReactiveRedisClientImpl.java | 38 +++++++++++++++++-- .../redis/client/runtime/RedisClientImpl.java | 21 ++++++++-- .../graphql/runtime/VertxGraphqlRecorder.java | 2 +- ...DevConsoleConfigEditorBodyHandlerTest.java | 14 +++++-- .../DevConsoleConfigEditorTest.java | 20 ++++++---- .../hotreload/HotReloadWithFilterTest.java | 16 +++++--- .../hotreload/HotReloadWithRouteTest.java | 18 ++++++--- .../http/hotreload/VertxInjectionTest.java | 10 ++++- .../http/runtime/AbstractRequestWrapper.java | 28 ++++++++++++++ .../ForwardedServerRequestWrapper.java | 18 +++++++++ .../filters/AbstractResponseWrapper.java | 23 ++++++++++- .../filters/QuarkusRequestWrapper.java | 18 +++++++++ .../runtime/security/QuarkusHttpUser.java | 17 ++++++++- .../core/deployment/VertxCoreProcessor.java | 3 +- .../vertx/core/runtime/VertxCoreRecorder.java | 4 +- .../runtime/WebJarLocatorRecorder.java | 2 +- .../resteasy-reactive/pom.xml | 2 +- .../VertxResteasyReactiveRequestContext.java | 2 +- 24 files changed, 250 insertions(+), 48 deletions(-) diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 520924073232e..6cac84a53bc45 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -30,7 +30,7 @@ 1.7.0 1.7.0-alpha 1.6.0 - 4.1.3 + 4.1.4 1.7.5 0.22.0 2.0 @@ -53,9 +53,9 @@ 1.2.2 1.0.13 2.6.0 - 2.14.1 + 2.15.0 3.10.1 - 1.0.0.Alpha7 + 1.0.0.Beta1 1.2.1 1.3.5 3.0.4 @@ -108,7 +108,7 @@ 1.17.2.Final 1.8.7.Final 3.4.2.Final - 4.1.5 + 4.2.1 4.5.13 4.4.14 4.1.4 diff --git a/extensions/amazon-lambda-http/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java b/extensions/amazon-lambda-http/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java index b2912010e6cf8..1e54978bb89f7 100644 --- a/extensions/amazon-lambda-http/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java +++ b/extensions/amazon-lambda-http/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java @@ -1,5 +1,7 @@ package io.quarkus.amazon.lambda.http.deployment; +import static io.vertx.core.file.impl.FileResolverImpl.CACHE_DIR_BASE_PROP_NAME; + import org.jboss.logging.Logger; import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; @@ -20,7 +22,6 @@ import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem; import io.quarkus.vertx.http.deployment.RequireVirtualHttpBuildItem; -import io.vertx.core.file.impl.FileResolver; public class AmazonLambdaHttpProcessor { private static final Logger log = Logger.getLogger(AmazonLambdaHttpProcessor.class); @@ -67,7 +68,7 @@ public void registerReflectionClasses(BuildProducer re */ @BuildStep void setTempDir(BuildProducer systemProperty) { - systemProperty.produce(new SystemPropertyBuildItem(FileResolver.CACHE_DIR_BASE_PROP_NAME, "/tmp/quarkus")); + systemProperty.produce(new SystemPropertyBuildItem(CACHE_DIR_BASE_PROP_NAME, "/tmp/quarkus")); } @BuildStep diff --git a/extensions/amazon-lambda-rest/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java b/extensions/amazon-lambda-rest/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java index 822459c06fe63..898a2a65b0004 100644 --- a/extensions/amazon-lambda-rest/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java +++ b/extensions/amazon-lambda-rest/deployment/src/main/java/io/quarkus/amazon/lambda/http/deployment/AmazonLambdaHttpProcessor.java @@ -1,5 +1,7 @@ package io.quarkus.amazon.lambda.http.deployment; +import static io.vertx.core.file.impl.FileResolverImpl.CACHE_DIR_BASE_PROP_NAME; + import org.jboss.logging.Logger; import io.quarkus.amazon.lambda.deployment.LambdaUtil; @@ -25,7 +27,6 @@ import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem; import io.quarkus.vertx.http.deployment.RequireVirtualHttpBuildItem; -import io.vertx.core.file.impl.FileResolver; public class AmazonLambdaHttpProcessor { private static final Logger log = Logger.getLogger(AmazonLambdaHttpProcessor.class); @@ -74,7 +75,7 @@ public void registerReflectionClasses(BuildProducer re */ @BuildStep void setTempDir(BuildProducer systemProperty) { - systemProperty.produce(new SystemPropertyBuildItem(FileResolver.CACHE_DIR_BASE_PROP_NAME, "/tmp/quarkus")); + systemProperty.produce(new SystemPropertyBuildItem(CACHE_DIR_BASE_PROP_NAME, "/tmp/quarkus")); } @BuildStep diff --git a/extensions/reactive-datasource/deployment/src/test/java/io/quarkus/reactive/datasource/runtime/TestPool.java b/extensions/reactive-datasource/deployment/src/test/java/io/quarkus/reactive/datasource/runtime/TestPool.java index cd37078248609..1dcb0b40e7aa9 100644 --- a/extensions/reactive-datasource/deployment/src/test/java/io/quarkus/reactive/datasource/runtime/TestPool.java +++ b/extensions/reactive-datasource/deployment/src/test/java/io/quarkus/reactive/datasource/runtime/TestPool.java @@ -9,6 +9,7 @@ import io.vertx.core.Handler; import io.vertx.core.Promise; import io.vertx.sqlclient.Pool; +import io.vertx.sqlclient.PrepareOptions; import io.vertx.sqlclient.PreparedQuery; import io.vertx.sqlclient.Query; import io.vertx.sqlclient.Row; @@ -33,6 +34,11 @@ public PreparedQuery> preparedQuery(String s) { return null; } + @Override + public PreparedQuery> preparedQuery(String sql, PrepareOptions options) { + return null; + } + @Override public Future getConnection() { Promise promise = Promise.promise(); diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java index 37fc5e842da67..9c5d64eb5110c 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java @@ -186,6 +186,8 @@ static RedisClient createClient(String name) { Response lpop(String arg0); + Response lpop(List args); + Response lpush(List args); Response lpushx(List args); @@ -244,6 +246,8 @@ static RedisClient createClient(String name) { Response psync(String arg0, String arg1); + Response psync(List args); + Response pttl(String arg0); Response publish(String arg0, String arg1); @@ -274,6 +278,8 @@ static RedisClient createClient(String name) { Response rpop(String arg0); + Response rpop(List args); + Response rpoplpush(String arg0, String arg1); Response rpush(List args); diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java index aeb7e23ef26c2..9cdf513e836bc 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java @@ -332,8 +332,12 @@ static ReactiveRedisClient createClient(String name) { Uni lpop(String arg0); + Uni lpop(List arg0); + Response lpopAndAwait(String arg0); + Response lpopAndAwait(List arg0); + Uni lpush(List args); Response lpushAndAwait(List args); @@ -448,8 +452,12 @@ static ReactiveRedisClient createClient(String name) { Uni psync(String arg0, String arg1); + Uni psync(List args); + Response psyncAndAwait(String arg0, String arg1); + Response psyncAndAwait(List args); + Uni pttl(String arg0); Response pttlAndAwait(String arg0); @@ -508,8 +516,12 @@ static ReactiveRedisClient createClient(String name) { Uni rpop(String arg0); + Uni rpop(List args); + Response rpopAndAwait(String arg0); + Response rpopAndAwait(List args); + Uni rpoplpush(String arg0, String arg1); Response rpoplpushAndAwait(String arg0, String arg1); diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/ReactiveRedisClientImpl.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/ReactiveRedisClientImpl.java index 992dc33545760..8dd94d4e6232d 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/ReactiveRedisClientImpl.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/ReactiveRedisClientImpl.java @@ -751,11 +751,21 @@ public Response lolwutAndAwait(List args) { @Override public Uni lpop(String arg0) { + return redisAPI.lpop(List.of(arg0)); + } + + @Override + public Uni lpop(List arg0) { return redisAPI.lpop(arg0); } @Override public Response lpopAndAwait(String arg0) { + return redisAPI.lpopAndAwait(List.of(arg0)); + } + + @Override + public Response lpopAndAwait(List arg0) { return redisAPI.lpopAndAwait(arg0); } @@ -1041,12 +1051,22 @@ public Response psubscribeAndAwait(List args) { @Override public Uni psync(String arg0, String arg1) { - return redisAPI.psync(arg0, arg1); + return redisAPI.psync(List.of(arg0, arg1)); + } + + @Override + public Uni psync(List args) { + return redisAPI.psync(args); + } + + @Override + public Response psyncAndAwait(List args) { + return redisAPI.psyncAndAwait(args); } @Override public Response psyncAndAwait(String arg0, String arg1) { - return redisAPI.psyncAndAwait(arg0, arg1); + return redisAPI.psyncAndAwait(List.of(arg0, arg1)); } @Override @@ -1191,12 +1211,22 @@ public Response roleAndAwait() { @Override public Uni rpop(String arg0) { - return redisAPI.rpop(arg0); + return redisAPI.rpop(List.of(arg0)); + } + + @Override + public Uni rpop(List args) { + return redisAPI.rpop(args); + } + + @Override + public Response rpopAndAwait(List args) { + return redisAPI.rpopAndAwait(args); } @Override public Response rpopAndAwait(String arg0) { - return redisAPI.rpopAndAwait(arg0); + return redisAPI.rpopAndAwait(List.of(arg0)); } @Override diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientImpl.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientImpl.java index 42aa4cd1166ab..d9871c6a2bbc4 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientImpl.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientImpl.java @@ -389,7 +389,12 @@ public Response lolwut(List args) { @Override public Response lpop(String arg0) { - return await(redisAPI.lpop(arg0)); + return await(redisAPI.lpop(List.of(arg0))); + } + + @Override + public Response lpop(List args) { + return await(redisAPI.lpop(args)); } @Override @@ -534,7 +539,12 @@ public Response psubscribe(List args) { @Override public Response psync(String arg0, String arg1) { - return await(redisAPI.psync(arg0, arg1)); + return await(redisAPI.psync(List.of(arg0, arg1))); + } + + @Override + public Response psync(List args) { + return await(redisAPI.psync(args)); } @Override @@ -609,7 +619,12 @@ public Response role() { @Override public Response rpop(String arg0) { - return await(redisAPI.rpop(arg0)); + return await(redisAPI.rpop(List.of(arg0))); + } + + @Override + public Response rpop(List args) { + return await(redisAPI.rpop(args)); } @Override diff --git a/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java b/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java index 79e2fea1c9504..7ca208a914672 100644 --- a/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java +++ b/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java @@ -22,7 +22,7 @@ public Handler handler() { return new Handler() { @Override public void handle(RoutingContext event) { - if (event.normalisedPath().length() == (event.currentRoute().getPath().length() + if (event.normalizedPath().length() == (event.currentRoute().getPath().length() + (event.mountPoint() == null ? 0 : event.mountPoint().length() - 1))) { event.response().setStatusCode(302); event.response().headers().set(HttpHeaders.LOCATION, (event.mountPoint() == null ? "" : event.mountPoint()) diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java index 7583b859445c5..f28b31a2a5a43 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java @@ -1,9 +1,12 @@ package io.quarkus.vertx.http.devconsole; +import java.net.URL; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; +import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; /** @@ -19,25 +22,28 @@ public class DevConsoleConfigEditorBodyHandlerTest { static final QuarkusDevModeTest config = new QuarkusDevModeTest() .withApplicationRoot((jar) -> jar.addClass(BodyHandlerBean.class)); + @TestHTTPResource + URL url; + @Test public void testChangeHttpRoute() { RestAssured.with() - .get("q/arc/beans") + .get("http://localhost:" + url.getPort() + "/q/arc/beans") .then() .statusCode(200); RestAssured.with().formParam("name", "quarkus.http.root-path") .formParam("value", "/foo") .formParam("action", "updateProperty") .redirects().follow(false) - .post("q/dev/io.quarkus.quarkus-vertx-http/config") + .post("http://localhost:" + url.getPort() + "/q/dev/io.quarkus.quarkus-vertx-http/config") .then() .statusCode(303); RestAssured.with() - .get("q/arc/beans") + .get("http://localhost:" + url.getPort() + "/q/arc/beans") .then() .statusCode(404); RestAssured.with() - .get("foo/q/arc/beans") + .get("http://localhost:" + url.getPort() + "/foo/q/arc/beans") .then() .statusCode(200); diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java index bfa4de214ebcf..253d3d57afcd0 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java @@ -1,9 +1,12 @@ package io.quarkus.vertx.http.devconsole; +import java.net.URL; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; +import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class DevConsoleConfigEditorTest { @@ -12,25 +15,28 @@ public class DevConsoleConfigEditorTest { static final QuarkusDevModeTest config = new QuarkusDevModeTest() .withEmptyApplication(); + @TestHTTPResource + URL url; + @Test public void testChangeHttpRoute() { RestAssured.with() - .get("q/arc/beans") + .get("http://localhost:" + url.getPort() + "/q/arc/beans") .then() .statusCode(200); RestAssured.with().formParam("name", "quarkus.http.root-path") .formParam("value", "/foo") .formParam("action", "updateProperty") .redirects().follow(false) - .post("q/dev/io.quarkus.quarkus-vertx-http/config") + .post("http://localhost:" + url.getPort() + "/q/dev/io.quarkus.quarkus-vertx-http/config") .then() .statusCode(303); RestAssured.with() - .get("q/arc/beans") + .get("http://localhost:" + url.getPort() + "/q/arc/beans") .then() .statusCode(404); RestAssured.with() - .get("foo/q/arc/beans") + .get("http://localhost:" + url.getPort() + "/foo/q/arc/beans") .then() .statusCode(200); @@ -39,18 +45,18 @@ public void testChangeHttpRoute() { @Test public void testSetEmptyValue() { RestAssured.with() - .get("q/arc/beans") + .get("http://localhost:" + url.getPort() + "/q/arc/beans") .then() .statusCode(200); RestAssured.with().formParam("name", "quarkus.http.root-path") .formParam("value", "") .formParam("action", "updateProperty") .redirects().follow(false) - .post("q/dev/io.quarkus.quarkus-vertx-http/config") + .post("http://localhost:" + url.getPort() + "/q/dev/io.quarkus.quarkus-vertx-http/config") .then() .statusCode(303); RestAssured.with() - .get("q/arc/beans") + .get("http://localhost:" + url.getPort() + "/q/arc/beans") .then() .statusCode(200); } diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java index e5bfb068a807d..fd384bf45c98a 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java @@ -2,10 +2,13 @@ import static org.hamcrest.core.Is.is; +import java.net.URL; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; +import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class HotReloadWithFilterTest { @@ -19,29 +22,32 @@ public class HotReloadWithFilterTest { private static final String USER_FILE = "DevBean.java"; private static final String USER_FILTER = "DevFilter.java"; + @TestHTTPResource + URL url; + @Test public void testFilterChange() { - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(200) .body(is("Hello World")) .header("X-Header", is("AAAA")); test.modifySourceFile(USER_FILTER, s -> s.replace("AAAA", "BBBB")); - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(200) .body(is("Hello World")) .header("X-Header", is("BBBB")); test.modifySourceFile(USER_FILE, s -> s.replace("World", "Quarkus")); - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(200) .body(is("Hello Quarkus")) .header("X-Header", is("BBBB")); test.modifySourceFile(USER_FILTER, s -> s.replace("BBBB", "CCC")); - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(200) .body(is("Hello Quarkus")) .header("X-Header", is("CCC")); @@ -52,7 +58,7 @@ public void testFilterChange() { public void testAddFilter() { test.addSourceFile(NewFilter.class); - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(200) .body(is("Hello World")) .header("X-Header", is("AAAA")) diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java index d3e760de8ed01..1ba8fa0bdbf3e 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java @@ -2,10 +2,13 @@ import static org.hamcrest.core.Is.is; +import java.net.URL; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; +import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class HotReloadWithRouteTest { @@ -15,36 +18,39 @@ public class HotReloadWithRouteTest { .withApplicationRoot((jar) -> jar.addClass(DevBean.class)); private static final String USER_FILE = "DevBean.java"; + @TestHTTPResource + URL url; + @Test public void testRouteChange() { - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(200) .body(is("Hello World")); test.modifySourceFile(USER_FILE, s -> s.replace("Hello World", "Hello Quarkus")); - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(200) .body(is("Hello Quarkus")); test.modifySourceFile("DevBean.java", s -> s.replace("/dev", "/new")); - RestAssured.when().get("/dev").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() .statusCode(404); - RestAssured.when().get("/new").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/new").then() .statusCode(200) .body(is("Hello Quarkus")); } @Test public void testAddBean() { - RestAssured.when().get("/bean").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/bean").then() .statusCode(404); test.addSourceFile(NewBean.class); - RestAssured.when().get("/bean").then() + RestAssured.when().get("http://localhost:" + url.getPort() + "/bean").then() .statusCode(200) .body(is("Hello New World")); } diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java index f91b3ce0410ff..6465a3094b756 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java @@ -2,10 +2,13 @@ import static org.hamcrest.CoreMatchers.containsString; +import java.net.URL; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; +import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class VertxInjectionTest { @@ -15,14 +18,17 @@ public class VertxInjectionTest { .withApplicationRoot((jar) -> jar .addClasses(VertxEventBusConsumer.class, VertxEventBusProducer.class)); + @TestHTTPResource + URL url; + @Test public void testEditingBeanUsingVertx() { - RestAssured.get("/").then() + RestAssured.get("http://localhost:" + url.getPort() + "/").then() .statusCode(200) .body(containsString("hello")); TEST.modifySourceFile("VertxEventBusConsumer.java", s -> s.replace("hello", "bonjour")); - RestAssured.get("/").then() + RestAssured.get("http://localhost:" + url.getPort() + "/").then() .statusCode(200) .body(containsString("bonjour")); } diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/AbstractRequestWrapper.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/AbstractRequestWrapper.java index 6be6eac1ca9bb..7cf2aca85b47f 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/AbstractRequestWrapper.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/AbstractRequestWrapper.java @@ -1,6 +1,7 @@ package io.quarkus.vertx.http.runtime; import java.util.Map; +import java.util.Set; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; @@ -143,6 +144,7 @@ public SocketAddress localAddress() { } @Override + @Deprecated public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException { return delegate.peerCertificateChain(); } @@ -243,10 +245,36 @@ public int cookieCount() { } @Override + @Deprecated public Map cookieMap() { return delegate.cookieMap(); } + @Override + public String getParam(String paramName, String defaultValue) { + return delegate.getParam(paramName, defaultValue); + } + + @Override + public int streamId() { + return delegate.streamId(); + } + + @Override + public Cookie getCookie(String name, String domain, String path) { + return delegate.getCookie(name, domain, path); + } + + @Override + public Set cookies(String name) { + return delegate.cookies(name); + } + + @Override + public Set cookies() { + return delegate.cookies(); + } + @Override public HttpServerRequest body(Handler> handler) { return delegate.body(handler); diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedServerRequestWrapper.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedServerRequestWrapper.java index f1b9cb2d6892a..dc35f709eb0e0 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedServerRequestWrapper.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedServerRequestWrapper.java @@ -1,6 +1,7 @@ package io.quarkus.vertx.http.runtime; import java.util.Map; +import java.util.Set; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; @@ -196,6 +197,7 @@ public SocketAddress localAddress() { } @Override + @Deprecated public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException { return delegate.peerCertificateChain(); } @@ -312,10 +314,26 @@ public int cookieCount() { } @Override + @Deprecated public Map cookieMap() { return delegate.cookieMap(); } + @Override + public Cookie getCookie(String name, String domain, String path) { + return delegate.getCookie(name, domain, path); + } + + @Override + public Set cookies(String name) { + return delegate.cookies(name); + } + + @Override + public Set cookies() { + return delegate.cookies(); + } + @Override public HttpServerRequest body(Handler> handler) { return delegate.body(handler); diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/AbstractResponseWrapper.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/AbstractResponseWrapper.java index 175e44e79e96d..d64a3311bfcd9 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/AbstractResponseWrapper.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/AbstractResponseWrapper.java @@ -1,5 +1,7 @@ package io.quarkus.vertx.http.runtime.filters; +import java.util.Set; + import io.vertx.core.AsyncResult; import io.vertx.core.Future; import io.vertx.core.Handler; @@ -444,7 +446,6 @@ public HttpServerResponse addCookie(Cookie cookie) { } @Override - public Cookie removeCookie(String name) { return delegate.removeCookie(name); } @@ -455,6 +456,26 @@ public Cookie removeCookie(String name, boolean invalidate) { return delegate.removeCookie(name, invalidate); } + @Override + public Set removeCookies(String name) { + return delegate.removeCookies(name); + } + + @Override + public Set removeCookies(String name, boolean invalidate) { + return delegate.removeCookies(name, invalidate); + } + + @Override + public Cookie removeCookie(String name, String domain, String path) { + return delegate.removeCookie(name, domain, path); + } + + @Override + public Cookie removeCookie(String name, String domain, String path, boolean invalidate) { + return delegate.removeCookie(name, domain, path, invalidate); + } + @Override public void end(Handler> handler) { delegate.end(handler); diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/QuarkusRequestWrapper.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/QuarkusRequestWrapper.java index 15efa520877ec..8ec30b3390928 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/QuarkusRequestWrapper.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/filters/QuarkusRequestWrapper.java @@ -1,7 +1,9 @@ package io.quarkus.vertx.http.runtime.filters; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.function.BiConsumer; @@ -89,6 +91,22 @@ public Cookie getCookie(String name) { return super.getCookie(name); } + @Override + public Cookie getCookie(String name, String domain, String path) { + if (name.equals(FAKE_COOKIE_NAME)) { + return new QuarkusCookie(); + } + return super.getCookie(name, domain, path); + } + + @Override + public Set cookies(String name) { + if (name.equals(FAKE_COOKIE_NAME)) { + return Collections.singleton(new QuarkusCookie()); + } + return super.cookies(name); + } + class ResponseWrapper extends AbstractResponseWrapper { final HttpServerRequest request; diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/security/QuarkusHttpUser.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/security/QuarkusHttpUser.java index e4b0d9a8c6dd8..edf4c1975180a 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/security/QuarkusHttpUser.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/security/QuarkusHttpUser.java @@ -25,7 +25,7 @@ public class QuarkusHttpUser implements User { /** * The key that stores a BiConsumer that handles auth failures * - * This can be overriden by downstream handlers such as Undertow to control auth failure handling. + * This can be overridden by downstream handlers such as Undertow to control auth failure handling. */ public static final String AUTH_FAILURE_HANDLER = "io.quarkus.vertx.http.auth-failure-handler"; @@ -53,6 +53,7 @@ public User isAuthorized(String authority, Handler> resultH } @Override + @Deprecated public User clearCache() { return this; } @@ -65,6 +66,7 @@ public JsonObject principal() { } @Override + @Deprecated public void setAuthProvider(AuthProvider authProvider) { } @@ -95,6 +97,19 @@ public static SecurityIdentity getSecurityIdentityBlocking(RoutingContext routin return null; } + @Override + public User merge(User other) { + if (other == null) { + return this; + } + + principal() + // merge in the rhs + .mergeIn(other.principal()); + + return this; + } + /** * Gets the current user from the routing context. If an IPM is provided this method will return the anonymous * identity if there is no active user, otherwise the Uni will resolve to null if there is no user. diff --git a/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/core/deployment/VertxCoreProcessor.java b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/core/deployment/VertxCoreProcessor.java index 608b4ac884962..2d716efbe07c7 100644 --- a/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/core/deployment/VertxCoreProcessor.java +++ b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/core/deployment/VertxCoreProcessor.java @@ -58,7 +58,8 @@ class VertxCoreProcessor { NativeImageConfigBuildItem build(BuildProducer reflectiveClass) { reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, VertxLogDelegateFactory.class.getName())); return NativeImageConfigBuildItem.builder() - .addRuntimeInitializedClass("io.vertx.core.net.impl.PartialPooledByteBufAllocator") + .addRuntimeInitializedClass("io.vertx.core.buffer.impl.VertxByteBufAllocator") + .addRuntimeInitializedClass("io.vertx.core.buffer.impl.PartialPooledByteBufAllocator") .addRuntimeInitializedClass("io.vertx.core.http.impl.VertxHttp2ClientUpgradeCodec") .addRuntimeInitializedClass("io.vertx.core.eventbus.impl.clustered.ClusteredEventBus") diff --git a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java index d7a0e74e66729..01ab418b3de6a 100644 --- a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java +++ b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java @@ -5,6 +5,7 @@ import static io.quarkus.vertx.core.runtime.SSLConfigHelper.configurePemTrustOptions; import static io.quarkus.vertx.core.runtime.SSLConfigHelper.configurePfxKeyCertOptions; import static io.quarkus.vertx.core.runtime.SSLConfigHelper.configurePfxTrustOptions; +import static io.vertx.core.file.impl.FileResolverImpl.CACHE_DIR_BASE_PROP_NAME; import java.io.File; import java.util.ArrayList; @@ -47,7 +48,6 @@ import io.vertx.core.dns.AddressResolverOptions; import io.vertx.core.eventbus.EventBusOptions; import io.vertx.core.file.FileSystemOptions; -import io.vertx.core.file.impl.FileResolver; import io.vertx.core.http.ClientAuth; import io.vertx.core.impl.ContextInternal; import io.vertx.core.impl.VertxBuilder; @@ -299,7 +299,7 @@ private static VertxOptions convertToVertxOptions(VertxConfiguration conf, Vertx initializeClusterOptions(conf, options); } - String fileCacheDir = System.getProperty(FileResolver.CACHE_DIR_BASE_PROP_NAME); + String fileCacheDir = System.getProperty(CACHE_DIR_BASE_PROP_NAME); if (fileCacheDir == null) { File tmp = new File(System.getProperty("java.io.tmpdir", ".") + File.separator + VERTX_CACHE); if (!tmp.isDirectory()) { diff --git a/extensions/webjars-locator/runtime/src/main/java/io/quarkus/webjar/locator/runtime/WebJarLocatorRecorder.java b/extensions/webjars-locator/runtime/src/main/java/io/quarkus/webjar/locator/runtime/WebJarLocatorRecorder.java index 2e7360518e065..813f4e920f830 100644 --- a/extensions/webjars-locator/runtime/src/main/java/io/quarkus/webjar/locator/runtime/WebJarLocatorRecorder.java +++ b/extensions/webjars-locator/runtime/src/main/java/io/quarkus/webjar/locator/runtime/WebJarLocatorRecorder.java @@ -11,7 +11,7 @@ public class WebJarLocatorRecorder { public Handler getHandler(String webjarsRootUrl, Map webjarNameToVersionMap) { return (event) -> { - String path = event.normalisedPath(); + String path = event.normalizedPath(); if (path.startsWith(webjarsRootUrl)) { String rest = path.substring(webjarsRootUrl.length()); String webjar = rest.substring(0, rest.indexOf('/')); diff --git a/independent-projects/resteasy-reactive/pom.xml b/independent-projects/resteasy-reactive/pom.xml index a64d4abe241c2..9a2aa138d9d26 100644 --- a/independent-projects/resteasy-reactive/pom.xml +++ b/independent-projects/resteasy-reactive/pom.xml @@ -52,7 +52,7 @@ 1.1.6 1.1.1 1.8.0 - 4.1.5 + 4.2.1 4.4.0 1.0.0.Final 2.0.0.Final diff --git a/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxResteasyReactiveRequestContext.java b/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxResteasyReactiveRequestContext.java index 055795164fba9..4f238feae173a 100644 --- a/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxResteasyReactiveRequestContext.java +++ b/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxResteasyReactiveRequestContext.java @@ -160,7 +160,7 @@ public String getRequestMethod() { @Override public String getRequestNormalisedPath() { - return context.normalisedPath(); + return context.normalizedPath(); } @Override From 86d0b27829a424745bdc174c51f138fcff2c05cc Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Thu, 4 Nov 2021 17:49:17 +0100 Subject: [PATCH 2/3] Update Redis client native build configuration --- .../quarkus/redis/client/deployment/RedisClientProcessor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java index a0a58881accb2..e262fc4af1237 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java @@ -87,8 +87,10 @@ public void registerRuntimeInitializedClasses(BuildProducer Date: Fri, 5 Nov 2021 12:01:01 +1100 Subject: [PATCH 3/3] Fix Vert.x random port handling Also clear the config after augmentation, which could cause issues when attempting to inject URL's into dev mode tests, as they could see a left over 8081 URL instead of 8080. --- .../runner/bootstrap/AugmentActionImpl.java | 2 + ...DevConsoleConfigEditorBodyHandlerTest.java | 14 +- .../DevConsoleConfigEditorTest.java | 20 +-- .../hotreload/HotReloadWithFilterTest.java | 16 +-- .../hotreload/HotReloadWithRouteTest.java | 18 +-- .../http/hotreload/VertxInjectionTest.java | 10 +- .../vertx/http/runtime/VertxHttpRecorder.java | 134 ++++++++++-------- 7 files changed, 97 insertions(+), 117 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java index 309a616ef4abe..02d64f13967b2 100644 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java +++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java @@ -52,6 +52,7 @@ import io.quarkus.dev.spi.DevModeType; import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.configuration.ProfileManager; +import io.quarkus.runtime.configuration.QuarkusConfigFactory; /** * The augmentation task that produces the application. @@ -331,6 +332,7 @@ private BuildResult runAugment(boolean firstRun, Set changedResources, } finally { ProfileManager.setRuntimeDefaultProfile(null); Thread.currentThread().setContextClassLoader(old); + QuarkusConfigFactory.setConfig(null); } } diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java index f28b31a2a5a43..7583b859445c5 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorBodyHandlerTest.java @@ -1,12 +1,9 @@ package io.quarkus.vertx.http.devconsole; -import java.net.URL; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; -import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; /** @@ -22,28 +19,25 @@ public class DevConsoleConfigEditorBodyHandlerTest { static final QuarkusDevModeTest config = new QuarkusDevModeTest() .withApplicationRoot((jar) -> jar.addClass(BodyHandlerBean.class)); - @TestHTTPResource - URL url; - @Test public void testChangeHttpRoute() { RestAssured.with() - .get("http://localhost:" + url.getPort() + "/q/arc/beans") + .get("q/arc/beans") .then() .statusCode(200); RestAssured.with().formParam("name", "quarkus.http.root-path") .formParam("value", "/foo") .formParam("action", "updateProperty") .redirects().follow(false) - .post("http://localhost:" + url.getPort() + "/q/dev/io.quarkus.quarkus-vertx-http/config") + .post("q/dev/io.quarkus.quarkus-vertx-http/config") .then() .statusCode(303); RestAssured.with() - .get("http://localhost:" + url.getPort() + "/q/arc/beans") + .get("q/arc/beans") .then() .statusCode(404); RestAssured.with() - .get("http://localhost:" + url.getPort() + "/foo/q/arc/beans") + .get("foo/q/arc/beans") .then() .statusCode(200); diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java index 253d3d57afcd0..bfa4de214ebcf 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devconsole/DevConsoleConfigEditorTest.java @@ -1,12 +1,9 @@ package io.quarkus.vertx.http.devconsole; -import java.net.URL; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; -import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class DevConsoleConfigEditorTest { @@ -15,28 +12,25 @@ public class DevConsoleConfigEditorTest { static final QuarkusDevModeTest config = new QuarkusDevModeTest() .withEmptyApplication(); - @TestHTTPResource - URL url; - @Test public void testChangeHttpRoute() { RestAssured.with() - .get("http://localhost:" + url.getPort() + "/q/arc/beans") + .get("q/arc/beans") .then() .statusCode(200); RestAssured.with().formParam("name", "quarkus.http.root-path") .formParam("value", "/foo") .formParam("action", "updateProperty") .redirects().follow(false) - .post("http://localhost:" + url.getPort() + "/q/dev/io.quarkus.quarkus-vertx-http/config") + .post("q/dev/io.quarkus.quarkus-vertx-http/config") .then() .statusCode(303); RestAssured.with() - .get("http://localhost:" + url.getPort() + "/q/arc/beans") + .get("q/arc/beans") .then() .statusCode(404); RestAssured.with() - .get("http://localhost:" + url.getPort() + "/foo/q/arc/beans") + .get("foo/q/arc/beans") .then() .statusCode(200); @@ -45,18 +39,18 @@ public void testChangeHttpRoute() { @Test public void testSetEmptyValue() { RestAssured.with() - .get("http://localhost:" + url.getPort() + "/q/arc/beans") + .get("q/arc/beans") .then() .statusCode(200); RestAssured.with().formParam("name", "quarkus.http.root-path") .formParam("value", "") .formParam("action", "updateProperty") .redirects().follow(false) - .post("http://localhost:" + url.getPort() + "/q/dev/io.quarkus.quarkus-vertx-http/config") + .post("q/dev/io.quarkus.quarkus-vertx-http/config") .then() .statusCode(303); RestAssured.with() - .get("http://localhost:" + url.getPort() + "/q/arc/beans") + .get("q/arc/beans") .then() .statusCode(200); } diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java index fd384bf45c98a..e5bfb068a807d 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithFilterTest.java @@ -2,13 +2,10 @@ import static org.hamcrest.core.Is.is; -import java.net.URL; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; -import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class HotReloadWithFilterTest { @@ -22,32 +19,29 @@ public class HotReloadWithFilterTest { private static final String USER_FILE = "DevBean.java"; private static final String USER_FILTER = "DevFilter.java"; - @TestHTTPResource - URL url; - @Test public void testFilterChange() { - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(200) .body(is("Hello World")) .header("X-Header", is("AAAA")); test.modifySourceFile(USER_FILTER, s -> s.replace("AAAA", "BBBB")); - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(200) .body(is("Hello World")) .header("X-Header", is("BBBB")); test.modifySourceFile(USER_FILE, s -> s.replace("World", "Quarkus")); - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(200) .body(is("Hello Quarkus")) .header("X-Header", is("BBBB")); test.modifySourceFile(USER_FILTER, s -> s.replace("BBBB", "CCC")); - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(200) .body(is("Hello Quarkus")) .header("X-Header", is("CCC")); @@ -58,7 +52,7 @@ public void testFilterChange() { public void testAddFilter() { test.addSourceFile(NewFilter.class); - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(200) .body(is("Hello World")) .header("X-Header", is("AAAA")) diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java index 1ba8fa0bdbf3e..d3e760de8ed01 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/HotReloadWithRouteTest.java @@ -2,13 +2,10 @@ import static org.hamcrest.core.Is.is; -import java.net.URL; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; -import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class HotReloadWithRouteTest { @@ -18,39 +15,36 @@ public class HotReloadWithRouteTest { .withApplicationRoot((jar) -> jar.addClass(DevBean.class)); private static final String USER_FILE = "DevBean.java"; - @TestHTTPResource - URL url; - @Test public void testRouteChange() { - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(200) .body(is("Hello World")); test.modifySourceFile(USER_FILE, s -> s.replace("Hello World", "Hello Quarkus")); - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(200) .body(is("Hello Quarkus")); test.modifySourceFile("DevBean.java", s -> s.replace("/dev", "/new")); - RestAssured.when().get("http://localhost:" + url.getPort() + "/dev").then() + RestAssured.when().get("/dev").then() .statusCode(404); - RestAssured.when().get("http://localhost:" + url.getPort() + "/new").then() + RestAssured.when().get("/new").then() .statusCode(200) .body(is("Hello Quarkus")); } @Test public void testAddBean() { - RestAssured.when().get("http://localhost:" + url.getPort() + "/bean").then() + RestAssured.when().get("/bean").then() .statusCode(404); test.addSourceFile(NewBean.class); - RestAssured.when().get("http://localhost:" + url.getPort() + "/bean").then() + RestAssured.when().get("/bean").then() .statusCode(200) .body(is("Hello New World")); } diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java index 6465a3094b756..f91b3ce0410ff 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/hotreload/VertxInjectionTest.java @@ -2,13 +2,10 @@ import static org.hamcrest.CoreMatchers.containsString; -import java.net.URL; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.test.QuarkusDevModeTest; -import io.quarkus.test.common.http.TestHTTPResource; import io.restassured.RestAssured; public class VertxInjectionTest { @@ -18,17 +15,14 @@ public class VertxInjectionTest { .withApplicationRoot((jar) -> jar .addClasses(VertxEventBusConsumer.class, VertxEventBusProducer.class)); - @TestHTTPResource - URL url; - @Test public void testEditingBeanUsingVertx() { - RestAssured.get("http://localhost:" + url.getPort() + "/").then() + RestAssured.get("/").then() .statusCode(200) .body(containsString("hello")); TEST.modifySourceFile("VertxEventBusConsumer.java", s -> s.replace("hello", "bonjour")); - RestAssured.get("http://localhost:" + url.getPort() + "/").then() + RestAssured.get("/").then() .statusCode(200) .body(containsString("bonjour")); } diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java index 35dfa4d7713d1..609ec34135bd8 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java @@ -712,7 +712,8 @@ private static HttpServerOptions createSslOptions(HttpBuildTimeConfig buildTimeC serverOptions.setSsl(true); serverOptions.setSni(sslConfig.sni); serverOptions.setHost(httpConfiguration.host); - serverOptions.setPort(httpConfiguration.determineSslPort(launchMode)); + int sslPort = httpConfiguration.determineSslPort(launchMode); + serverOptions.setPort(sslPort == 0 ? -1 : sslPort); serverOptions.setClientAuth(buildTimeConfig.tlsClientAuth); serverOptions.setReusePort(httpConfiguration.soReusePort); serverOptions.setTcpQuickAck(httpConfiguration.tcpQuickAck); @@ -813,7 +814,8 @@ private static HttpServerOptions createHttpServerOptions(HttpConfiguration httpC // TODO other config properties HttpServerOptions options = new HttpServerOptions(); options.setHost(httpConfiguration.host); - options.setPort(httpConfiguration.determinePort(launchMode)); + int port = httpConfiguration.determinePort(launchMode); + options.setPort(port == 0 ? -1 : port); setIdleTimeout(httpConfiguration, options); options.setMaxHeaderSize(httpConfiguration.limits.maxHeaderSize.asBigInteger().intValueExact()); options.setMaxChunkSize(httpConfiguration.limits.maxChunkSize.asBigInteger().intValueExact()); @@ -1043,49 +1045,51 @@ public void handle(Void event) { } else { // Port may be random, so set the actual port int actualPort = event.result().actualPort(); - if (actualPort != options.getPort()) { - // Override quarkus.http(s)?.(test-)?port - String schema; - if (https) { - clearHttpsProperty = true; - schema = "https"; - } else { - clearHttpProperty = true; - actualHttpPort = actualPort; - schema = "http"; - } - portPropertiesToRestore = new HashMap<>(); - String portPropertyValue = String.valueOf(actualPort); - //we always set the .port property, even if we are in test mode, so this will always - //reflect the current port - String portPropertyName = "quarkus." + schema + ".port"; - String prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); - if (!Objects.equals(prevPortPropertyValue, portPropertyValue)) { - portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue); - } - if (launchMode == LaunchMode.TEST) { - //we also set the test-port property in a test - String testPropName = "quarkus." + schema + ".test-port"; - String prevTestPropPrevValue = System.setProperty(testPropName, portPropertyValue); - if (!Objects.equals(prevTestPropPrevValue, portPropertyValue)) { - portPropertiesToRestore.put(testPropName, prevTestPropPrevValue); - } - } - if (launchMode.isDevOrTest()) { - // set the profile property as well to make sure we don't have any inconsistencies - portPropertyName = propertyWithProfilePrefix(portPropertyName); - prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); - if (!Objects.equals(prevPortPropertyValue, portPropertyValue)) { - portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue); - } - } - } + if (https) { actualHttpsPort = actualPort; } else { actualHttpPort = actualPort; } if (remainingCount.decrementAndGet() == 0) { + //make sure we only set the properties once + if (actualPort != options.getPort()) { + // Override quarkus.http(s)?.(test-)?port + String schema; + if (https) { + clearHttpsProperty = true; + schema = "https"; + } else { + clearHttpProperty = true; + actualHttpPort = actualPort; + schema = "http"; + } + portPropertiesToRestore = new HashMap<>(); + String portPropertyValue = String.valueOf(actualPort); + //we always set the .port property, even if we are in test mode, so this will always + //reflect the current port + String portPropertyName = "quarkus." + schema + ".port"; + String prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); + if (!Objects.equals(prevPortPropertyValue, portPropertyValue)) { + portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue); + } + if (launchMode == LaunchMode.TEST) { + //we also set the test-port property in a test + String testPropName = "quarkus." + schema + ".test-port"; + String prevTestPropPrevValue = System.setProperty(testPropName, portPropertyValue); + if (!Objects.equals(prevTestPropPrevValue, portPropertyValue)) { + portPropertiesToRestore.put(testPropName, prevTestPropPrevValue); + } + } + if (launchMode.isDevOrTest()) { + // set the profile property as well to make sure we don't have any inconsistencies + portPropertyName = propertyWithProfilePrefix(portPropertyName); + prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); + if (!Objects.equals(prevPortPropertyValue, portPropertyValue)) { + portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue); + } + } + } startFuture.complete(null); } @@ -1095,30 +1099,6 @@ public void handle(Void event) { @Override public void stop(Promise stopFuture) { - if (clearHttpProperty) { - String portPropertyName = launchMode == LaunchMode.TEST ? "quarkus.http.test-port" : "quarkus.http.port"; - System.clearProperty(portPropertyName); - if (launchMode.isDevOrTest()) { - System.clearProperty(propertyWithProfilePrefix(portPropertyName)); - } - - } - if (clearHttpsProperty) { - String portPropertyName = launchMode == LaunchMode.TEST ? "quarkus.https.test-port" : "quarkus.https.port"; - System.clearProperty(portPropertyName); - if (launchMode.isDevOrTest()) { - System.clearProperty(propertyWithProfilePrefix(portPropertyName)); - } - } - if (portPropertiesToRestore != null) { - for (Map.Entry entry : portPropertiesToRestore.entrySet()) { - if (entry.getValue() == null) { - System.clearProperty(entry.getKey()); - } else { - System.setProperty(entry.getKey(), entry.getValue()); - } - } - } final AtomicInteger remainingCount = new AtomicInteger(0); if (httpServer != null) { @@ -1133,6 +1113,34 @@ public void stop(Promise stopFuture) { Handler> handleClose = event -> { if (remainingCount.decrementAndGet() == 0) { + + if (clearHttpProperty) { + String portPropertyName = launchMode == LaunchMode.TEST ? "quarkus.http.test-port" + : "quarkus.http.port"; + System.clearProperty(portPropertyName); + if (launchMode.isDevOrTest()) { + System.clearProperty(propertyWithProfilePrefix(portPropertyName)); + } + + } + if (clearHttpsProperty) { + String portPropertyName = launchMode == LaunchMode.TEST ? "quarkus.https.test-port" + : "quarkus.https.port"; + System.clearProperty(portPropertyName); + if (launchMode.isDevOrTest()) { + System.clearProperty(propertyWithProfilePrefix(portPropertyName)); + } + } + if (portPropertiesToRestore != null) { + for (Map.Entry entry : portPropertiesToRestore.entrySet()) { + if (entry.getValue() == null) { + System.clearProperty(entry.getKey()); + } else { + System.setProperty(entry.getKey(), entry.getValue()); + } + } + } + stopFuture.complete(); } };