diff --git a/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/JakartaRestInterceptor.java b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/JakartaRestInterceptor.java new file mode 100644 index 000000000..f496a19e5 --- /dev/null +++ b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/JakartaRestInterceptor.java @@ -0,0 +1,27 @@ +package io.quarkus.ts.http.minimum.reactive; + +import java.io.IOException; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; + +import org.jboss.logging.Logger; + +@Provider +@ApplicationScoped +public class JakartaRestInterceptor implements ReaderInterceptor { + + private static final Logger LOG = Logger.getLogger(JakartaRestInterceptor.class); + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + LOG.info("Before reading " + context.getGenericType()); + Object entity = context.proceed(); + LOG.info("After reading " + entity); + return entity; + } +} diff --git a/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/Operator.java b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/Operator.java new file mode 100644 index 000000000..0f5f8b916 --- /dev/null +++ b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/Operator.java @@ -0,0 +1,22 @@ + +package io.quarkus.ts.http.minimum.reactive; + +public class Operator { + private String name; + + public Operator() { + this.name = null; + } + + public Operator(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/OperatorResource.java b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/OperatorResource.java new file mode 100644 index 000000000..c9eda0f8b --- /dev/null +++ b/http/http-minimum-reactive/src/main/java/io/quarkus/ts/http/minimum/reactive/OperatorResource.java @@ -0,0 +1,24 @@ +package io.quarkus.ts.http.minimum.reactive; + +import jakarta.interceptor.Interceptors; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +import io.smallrye.mutiny.Uni; + +@Path("/operator") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Interceptors({ JakartaRestInterceptor.class }) +public class OperatorResource { + + @POST + public Uni postOperator(Operator operator) { + return Uni.createFrom().item(Response.status(Response.Status.OK) + .entity("Hello " + operator.getName()).build()); + } +} diff --git a/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpMinimumReactiveIT.java b/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpMinimumReactiveIT.java index 158e4e8c1..10746e1aa 100644 --- a/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpMinimumReactiveIT.java +++ b/http/http-minimum-reactive/src/test/java/io/quarkus/ts/http/minimum/reactive/HttpMinimumReactiveIT.java @@ -5,6 +5,9 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; import jakarta.ws.rs.core.MediaType; @@ -12,13 +15,18 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import io.quarkus.test.bootstrap.RestService; import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.services.QuarkusApplication; +import io.restassured.http.ContentType; +import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; @QuarkusScenario public class HttpMinimumReactiveIT { - private RequestSpecification HTTP_CLIENT_SPEC = given(); + @QuarkusApplication + static RestService app = new RestService(); @Test public void httpServer() { @@ -78,7 +86,28 @@ public void shortRecordReturnedDirectly() { .body("data", is("ok")); } + @Test + @Tag("https://github.com/quarkusio/quarkus/issues/44564") + void interceptedMethodFound() { + Response operator = givenSpec() + .when() + .contentType(ContentType.JSON) + .body(new Operator("operator")) + .post("/api/operator"); + + assertEquals(200, operator.statusCode(), "Intercepted request was not processed"); + assertEquals("Hello operator", operator.body().asString(), "Intercepted request was not processed properly"); + List logs = app.getLogs(); + boolean startFlag = false; + boolean endFlag = false; + for (String line : logs) { + startFlag = startFlag || line.contains("Before reading "); + endFlag = endFlag || line.contains("After reading "); + } + assertTrue(startFlag && endFlag, "The message was not intercepted, full logs: " + logs); + } + protected RequestSpecification givenSpec() { - return HTTP_CLIENT_SPEC; + return app.given(); } }