Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make request scoped beans work properly in ReaderInterceptors #31712

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public RequestDeserializeHandler(Class<?> type, Type genericType, List<MediaType

@Override
public void handle(ResteasyReactiveRequestContext requestContext) throws Exception {
requestContext.requireCDIRequestScope();
MediaType effectiveRequestType = null;
Object requestType = requestContext.getHeader(HttpHeaders.CONTENT_TYPE, true);
if (requestType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;

import java.io.IOException;
import java.util.Base64;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.Provider;
import jakarta.ws.rs.ext.ReaderInterceptor;
import jakarta.ws.rs.ext.ReaderInterceptorContext;

import org.jboss.resteasy.reactive.server.core.BlockingOperationSupport;
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest;
Expand All @@ -25,7 +32,7 @@ public class BodyPayloadBlockingAllowedTest {
@RegisterExtension
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(TestResource.class));
.addClasses(TestResource.class, TestInterceptor.class, TestRequestScopedBean.class));

@Test
void testSmallRequestForNonBlocking() {
Expand Down Expand Up @@ -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) {

}
}

}