Skip to content

Commit 457333c

Browse files
authored
Merge pull request #30132 from geoand/#30078
Fixes #30078
2 parents 8ddf9f3 + ca03e79 commit 457333c

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,28 @@ public void accept(EndpointIndexer.ResourceMethodCallbackData entry) {
314314
QuarkusResteasyReactiveDotNames.IGNORE_METHOD_FOR_REFLECTION_PREDICATE)
315315
.source(source)
316316
.build());
317+
318+
// if there is a body parameter type, register it for reflection
319+
ResourceMethod resourceMethod = entry.getResourceMethod();
320+
MethodParameter[] methodParameters = resourceMethod.getParameters();
321+
if (methodParameters != null) {
322+
for (int i = 0; i < methodParameters.length; i++) {
323+
MethodParameter methodParameter = methodParameters[i];
324+
if (methodParameter.getParameterType() == ParameterType.BODY) {
325+
reflectiveHierarchyBuildItemBuildProducer.produce(new ReflectiveHierarchyBuildItem.Builder()
326+
.type(method.parameterType(i))
327+
.index(index)
328+
.ignoreTypePredicate(
329+
QuarkusResteasyReactiveDotNames.IGNORE_TYPE_FOR_REFLECTION_PREDICATE)
330+
.ignoreFieldPredicate(
331+
QuarkusResteasyReactiveDotNames.IGNORE_FIELD_FOR_REFLECTION_PREDICATE)
332+
.ignoreMethodPredicate(
333+
QuarkusResteasyReactiveDotNames.IGNORE_METHOD_FOR_REFLECTION_PREDICATE)
334+
.source(source)
335+
.build());
336+
}
337+
}
338+
}
317339
}
318340
})
319341
.build();

integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/ClientCallingResource.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ void init(@Observes Router router) {
118118
router.post("/hello").handler(rc -> rc.response().putHeader("content-type", MediaType.TEXT_PLAIN)
119119
.end("Hello, " + (rc.getBodyAsString()).repeat(getCount(rc))));
120120

121+
router.post("/hello/fromMessage").handler(rc -> rc.response().putHeader("content-type", MediaType.TEXT_PLAIN)
122+
.end(rc.body().asJsonObject().getString("message")));
123+
121124
router.route("/call-hello-client").blockingHandler(rc -> {
122125
String url = rc.getBody().toString();
123126
HelloClient client = RestClientBuilder.newBuilder().baseUri(URI.create(url))
@@ -126,6 +129,14 @@ void init(@Observes Router router) {
126129
rc.response().end(greeting);
127130
});
128131

132+
router.route("/call-helloFromMessage-client").blockingHandler(rc -> {
133+
String url = rc.getBody().toString();
134+
HelloClient client = RestClientBuilder.newBuilder().baseUri(URI.create(url))
135+
.build(HelloClient.class);
136+
String greeting = client.fromMessage(new HelloClient.Message("Hello world"));
137+
rc.response().end(greeting);
138+
});
139+
129140
router.post("/params/param").handler(rc -> rc.response().putHeader("content-type", MediaType.TEXT_PLAIN)
130141
.end(getParam(rc)));
131142

integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/HelloClient.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import javax.ws.rs.core.MediaType;
1010
import javax.ws.rs.core.Response;
1111

12+
import com.fasterxml.jackson.annotation.JsonCreator;
13+
1214
import io.quarkus.rest.client.reactive.ClientExceptionMapper;
1315

1416
@Path("")
@@ -18,6 +20,12 @@ public interface HelloClient {
1820
@Consumes(MediaType.TEXT_PLAIN)
1921
String greeting(String name, @QueryParam("count") int count);
2022

23+
@Path("fromMessage")
24+
@POST
25+
@Produces(MediaType.TEXT_PLAIN)
26+
@Consumes(MediaType.APPLICATION_JSON)
27+
String fromMessage(Message message);
28+
2129
// this isn't used, but it makes sure that the generated provider can be properly instantiated in native mode
2230
@ClientExceptionMapper
2331
static RuntimeException toException(Response response) {
@@ -26,4 +34,18 @@ static RuntimeException toException(Response response) {
2634
}
2735
return null;
2836
}
37+
38+
class Message {
39+
40+
private final String message;
41+
42+
@JsonCreator
43+
public Message(String message) {
44+
this.message = message;
45+
}
46+
47+
public String getMessage() {
48+
return message;
49+
}
50+
}
2951
}

integration-tests/rest-client-reactive/src/test/java/io/quarkus/it/rest/client/BasicTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public void shouldMakeTextRequest() {
4242
assertThat(response.asString()).isEqualTo("Hello, JohnJohn");
4343
}
4444

45+
@Test
46+
public void shouldMakeJsonRequestAndGetTextResponse() {
47+
Response response = RestAssured.with().body(helloUrl).post("/call-helloFromMessage-client");
48+
assertThat(response.asString()).isEqualTo("Hello world");
49+
}
50+
4551
@Test
4652
public void restResponseShouldWorkWithNonSuccessfulResponse() {
4753
Response response = RestAssured.with().body(helloUrl).post("/rest-response");

0 commit comments

Comments
 (0)