From 3c31743127517da92089f07376eda4a8f150be60 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 21 Aug 2023 16:40:24 +0300 Subject: [PATCH] Ensure that duplicate endpoints don't prevent hot-reload Fixes: #35355 --- .../deployment/ResteasyReactiveProcessor.java | 4 +- ...DuplicateResourceDetectionDevModeTest.java | 48 +++++++++++++++++++ .../test/duplicate/GreetingResource4.java | 24 ++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/DuplicateResourceDetectionDevModeTest.java create mode 100644 extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/GreetingResource4.java diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java index bc89dc610f42f..97a5c631905b6 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java @@ -37,6 +37,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import jakarta.enterprise.inject.spi.DeploymentException; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.Priorities; import jakarta.ws.rs.Produces; @@ -194,7 +195,6 @@ import io.quarkus.resteasy.reactive.spi.MessageBodyWriterOverrideBuildItem; import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.RuntimeValue; -import io.quarkus.runtime.configuration.ConfigurationException; import io.quarkus.security.AuthenticationCompletionException; import io.quarkus.security.AuthenticationFailedException; import io.quarkus.security.AuthenticationRedirectException; @@ -1356,7 +1356,7 @@ private void checkForDuplicateEndpoint(ResteasyReactiveConfig config, Map 0) { if (config.failOnDuplicate()) { - throw new ConfigurationException(message); + throw new DeploymentException(message); } log.warn(message); } diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/DuplicateResourceDetectionDevModeTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/DuplicateResourceDetectionDevModeTest.java new file mode 100644 index 0000000000000..f6ac6acbe5c74 --- /dev/null +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/DuplicateResourceDetectionDevModeTest.java @@ -0,0 +1,48 @@ +package io.quarkus.resteasy.reactive.server.test.duplicate; + +import static io.restassured.RestAssured.when; + +import java.util.function.Function; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusDevModeTest; + +public class DuplicateResourceDetectionDevModeTest { + + @RegisterExtension + static QuarkusDevModeTest TEST = new QuarkusDevModeTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClasses(GreetingResource3.class, GreetingResource4.class)) + .setAllowFailedStart(true); + + @Test + public void testRestarts() { + // The build should fail initially + when() + .get("/hello-resteasy") + .then() + .statusCode(500); + + TEST.modifySourceFile(GreetingResource4.class.getSimpleName() + ".java", new Function<>() { + @Override + public String apply(String s) { + return s.replace("hello-resteasy", "hello-resteasy2"); + } + }); + + // after changing the paths to remove the collision, the endpoints should work + when() + .get("/hello-resteasy") + .then() + .statusCode(200); + when() + .get("/hello-resteasy2") + .then() + .statusCode(200); + + } +} diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/GreetingResource4.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/GreetingResource4.java new file mode 100644 index 0000000000000..a2de24ecc5e2d --- /dev/null +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/duplicate/GreetingResource4.java @@ -0,0 +1,24 @@ +package io.quarkus.resteasy.reactive.server.test.duplicate; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/hello-resteasy") +public class GreetingResource4 { + + @GET + @Consumes(MediaType.APPLICATION_ATOM_XML) + public String helloGet(String tutu) { + return "Hello get"; + } + + @POST + @Produces(MediaType.TEXT_PLAIN) + public String helloPost(String yo) { + return "Hello post"; + } +}