From 8960603a701b33c01e32f77c89ab9335b16ada1e Mon Sep 17 00:00:00 2001 From: Stephane Epardaud Date: Wed, 19 Jan 2022 10:00:03 +0100 Subject: [PATCH] RR: Fix abort chain order for #22408 --- .../test/simple/Issue22408TestCase.java | 61 +++++++++++++++++++ .../startup/RuntimeDeploymentManager.java | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/simple/Issue22408TestCase.java diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/simple/Issue22408TestCase.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/simple/Issue22408TestCase.java new file mode 100644 index 0000000000000..86e7d8a5a79f2 --- /dev/null +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/simple/Issue22408TestCase.java @@ -0,0 +1,61 @@ +package io.quarkus.resteasy.reactive.server.test.simple; + +import java.util.function.Supplier; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.reactive.server.ServerExceptionMapper; +import org.jboss.resteasy.reactive.server.ServerResponseFilter; +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.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class Issue22408TestCase { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .setArchiveProducer(new Supplier() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(MyFilters.class, MyResource.class); + } + }); + + @Test + public void simpleTest() { + RestAssured.get("/") + .then().statusCode(204); + } + + public static class MyFilters { + + @ServerExceptionMapper + public Response mapException(RuntimeException x) { + // this should get us a 204 which masks the original 405 + return null; + } + + @ServerResponseFilter + public void responseFilter(ContainerResponseContext ctx) { + // NPE because the response was not set yet + ctx.getEntity(); + } + } + + @Path("/") + public static class MyResource { + // by calling a GET here we generate a 405 + @POST + public String get() { + return "Hello"; + } + } +} diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeDeploymentManager.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeDeploymentManager.java index 1968a4e55682e..71206c15072ee 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeDeploymentManager.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeDeploymentManager.java @@ -150,10 +150,10 @@ public BeanFactory.BeanInstance apply(Class aClass) { abortHandlingChain.add(interceptorDeployment.getGlobalInterceptorHandler()); } abortHandlingChain.add(new ExceptionHandler()); + abortHandlingChain.add(ResponseHandler.NO_CUSTOMIZER_INSTANCE); if (!interceptors.getContainerResponseFilters().getGlobalResourceInterceptors().isEmpty()) { abortHandlingChain.addAll(interceptorDeployment.getGlobalResponseInterceptorHandlers()); } - abortHandlingChain.add(ResponseHandler.NO_CUSTOMIZER_INSTANCE); abortHandlingChain.add(new ResponseWriterHandler(dynamicEntityWriter)); // sanitise the prefix for our usage to make it either an empty string, or something which starts with a / and does not // end with one