File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed
extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment
integration-tests/rest-client-reactive/src
main/java/io/quarkus/it/rest/client/main
test/java/io/quarkus/it/rest/client Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -314,6 +314,28 @@ public void accept(EndpointIndexer.ResourceMethodCallbackData entry) {
314
314
QuarkusResteasyReactiveDotNames .IGNORE_METHOD_FOR_REFLECTION_PREDICATE )
315
315
.source (source )
316
316
.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
+ }
317
339
}
318
340
})
319
341
.build ();
Original file line number Diff line number Diff line change @@ -118,6 +118,9 @@ void init(@Observes Router router) {
118
118
router .post ("/hello" ).handler (rc -> rc .response ().putHeader ("content-type" , MediaType .TEXT_PLAIN )
119
119
.end ("Hello, " + (rc .getBodyAsString ()).repeat (getCount (rc ))));
120
120
121
+ router .post ("/hello/fromMessage" ).handler (rc -> rc .response ().putHeader ("content-type" , MediaType .TEXT_PLAIN )
122
+ .end (rc .body ().asJsonObject ().getString ("message" )));
123
+
121
124
router .route ("/call-hello-client" ).blockingHandler (rc -> {
122
125
String url = rc .getBody ().toString ();
123
126
HelloClient client = RestClientBuilder .newBuilder ().baseUri (URI .create (url ))
@@ -126,6 +129,14 @@ void init(@Observes Router router) {
126
129
rc .response ().end (greeting );
127
130
});
128
131
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
+
129
140
router .post ("/params/param" ).handler (rc -> rc .response ().putHeader ("content-type" , MediaType .TEXT_PLAIN )
130
141
.end (getParam (rc )));
131
142
Original file line number Diff line number Diff line change 9
9
import javax .ws .rs .core .MediaType ;
10
10
import javax .ws .rs .core .Response ;
11
11
12
+ import com .fasterxml .jackson .annotation .JsonCreator ;
13
+
12
14
import io .quarkus .rest .client .reactive .ClientExceptionMapper ;
13
15
14
16
@ Path ("" )
@@ -18,6 +20,12 @@ public interface HelloClient {
18
20
@ Consumes (MediaType .TEXT_PLAIN )
19
21
String greeting (String name , @ QueryParam ("count" ) int count );
20
22
23
+ @ Path ("fromMessage" )
24
+ @ POST
25
+ @ Produces (MediaType .TEXT_PLAIN )
26
+ @ Consumes (MediaType .APPLICATION_JSON )
27
+ String fromMessage (Message message );
28
+
21
29
// this isn't used, but it makes sure that the generated provider can be properly instantiated in native mode
22
30
@ ClientExceptionMapper
23
31
static RuntimeException toException (Response response ) {
@@ -26,4 +34,18 @@ static RuntimeException toException(Response response) {
26
34
}
27
35
return null ;
28
36
}
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
+ }
29
51
}
Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ public void shouldMakeTextRequest() {
42
42
assertThat (response .asString ()).isEqualTo ("Hello, JohnJohn" );
43
43
}
44
44
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
+
45
51
@ Test
46
52
public void restResponseShouldWorkWithNonSuccessfulResponse () {
47
53
Response response = RestAssured .with ().body (helloUrl ).post ("/rest-response" );
You can’t perform that action at this time.
0 commit comments