diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ContainerRequestContextTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ContainerRequestContextTest.java new file mode 100644 index 0000000000000..9943372efa324 --- /dev/null +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ContainerRequestContextTest.java @@ -0,0 +1,65 @@ +package io.quarkus.resteasy.reactive.server.test.resource.basic; + +import static org.hamcrest.Matchers.equalTo; + +import java.io.IOException; +import java.util.function.Supplier; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.ext.Provider; + +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 ContainerRequestContextTest { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .setArchiveProducer(new Supplier<>() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class) + .addClass(HelloResource.class); + } + }); + + @Test + public void helloWorldTest() { + RestAssured.get("/hello") + .then() + .body(equalTo("hello foo")); + } + + @Path("/hello") + public static class HelloResource { + + private final ContainerRequestContext containerRequestContext; + + public HelloResource(ContainerRequestContext containerRequestContext) { + this.containerRequestContext = containerRequestContext; + } + + @GET + public String hello() { + return "hello " + containerRequestContext.getProperty("name"); + } + + } + + @Provider + public static class TestFilter implements ContainerRequestFilter { + + @Override + public void filter(ContainerRequestContext context) throws IOException { + context.setProperty("name", "foo"); + } + } +} diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/injection/ContextProducers.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/injection/ContextProducers.java index 9d75017dd3cc4..829306f0baa60 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/injection/ContextProducers.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/injection/ContextProducers.java @@ -4,6 +4,7 @@ import javax.enterprise.context.RequestScoped; import javax.enterprise.inject.Produces; import javax.inject.Singleton; +import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ResourceContext; import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.Application; @@ -51,6 +52,13 @@ HttpHeaders headers() { return getContext().getHttpHeaders(); } + // this is added for compatibility reasons + @RequestScoped + @Produces + ContainerRequestContext containerRequestContext() { + return getContext().getContainerRequestContext(); + } + @ApplicationScoped @Produces Sse sse() {