From 067011ef0d9889d0d99ce8f9ff8ebe067c2d27ef Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 9 Mar 2023 09:59:55 +0200 Subject: [PATCH] Make request scoped beans work properly in ReaderInterceptors Fixes: #31692 --- .../handlers/RequestDeserializeHandler.java | 1 + .../test/BodyPayloadBlockingAllowedTest.java | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java index 768e1612ab778..e6b3a0b7379e0 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java @@ -47,6 +47,7 @@ public RequestDeserializeHandler(Class type, Type genericType, List ShrinkWrap.create(JavaArchive.class) - .addClasses(TestResource.class)); + .addClasses(TestResource.class, TestInterceptor.class, TestRequestScopedBean.class)); @Test void testSmallRequestForNonBlocking() { @@ -81,4 +88,29 @@ public Boolean blocking(String request) { } } + + // the interceptor is used in order to test that a request scoped bean works properly no matter what thread the payload is read from + + @Provider + public static class TestInterceptor implements ReaderInterceptor { + + @Inject + protected TestRequestScopedBean testRequestScopedBean; + + @Override + public Object aroundReadFrom(final ReaderInterceptorContext context) throws IOException, WebApplicationException { + var entity = context.proceed(); + testRequestScopedBean.log((String) entity); + return entity; + } + } + + @RequestScoped + public static class TestRequestScopedBean { + + public void log(final String ignored) { + + } + } + }