52
52
* by delegating to an {@link HttpClientAdapter} to perform actual requests.
53
53
*
54
54
* @author Rossen Stoyanchev
55
+ * @author Sebastien Deleuze
55
56
* @since 6.0
56
57
*/
57
58
final class HttpServiceMethod {
@@ -311,14 +312,15 @@ public static ResponseFunction create(
311
312
312
313
MethodParameter returnParam = new MethodParameter (method , -1 );
313
314
Class <?> returnType = returnParam .getParameterType ();
314
- if (KotlinDetector .isSuspendingFunction (method )) {
315
+ boolean isSuspending = KotlinDetector .isSuspendingFunction (method );
316
+ if (isSuspending ) {
315
317
returnType = Mono .class ;
316
318
}
317
319
318
320
ReactiveAdapter reactiveAdapter = reactiveRegistry .getAdapter (returnType );
319
321
320
322
MethodParameter actualParam = (reactiveAdapter != null ? returnParam .nested () : returnParam .nestedIfOptional ());
321
- Class <?> actualType = actualParam .getNestedParameterType ();
323
+ Class <?> actualType = isSuspending ? actualParam . getParameterType () : actualParam .getNestedParameterType ();
322
324
323
325
Function <HttpRequestValues , Publisher <?>> responseFunction ;
324
326
if (actualType .equals (void .class ) || actualType .equals (Void .class )) {
@@ -331,27 +333,27 @@ else if (actualType.equals(HttpHeaders.class)) {
331
333
responseFunction = client ::requestToHeaders ;
332
334
}
333
335
else if (actualType .equals (ResponseEntity .class )) {
334
- MethodParameter bodyParam = actualParam .nested ();
336
+ MethodParameter bodyParam = isSuspending ? actualParam : actualParam .nested ();
335
337
Class <?> bodyType = bodyParam .getNestedParameterType ();
336
338
if (bodyType .equals (Void .class )) {
337
339
responseFunction = client ::requestToBodilessEntity ;
338
340
}
339
341
else {
340
342
ReactiveAdapter bodyAdapter = reactiveRegistry .getAdapter (bodyType );
341
- responseFunction = initResponseEntityFunction (client , bodyParam , bodyAdapter );
343
+ responseFunction = initResponseEntityFunction (client , bodyParam , bodyAdapter , isSuspending );
342
344
}
343
345
}
344
346
else {
345
- responseFunction = initBodyFunction (client , actualParam , reactiveAdapter );
347
+ responseFunction = initBodyFunction (client , actualParam , reactiveAdapter , isSuspending );
346
348
}
347
349
348
350
boolean blockForOptional = returnType .equals (Optional .class );
349
351
return new ResponseFunction (responseFunction , reactiveAdapter , blockForOptional , blockTimeout );
350
352
}
351
353
352
354
@ SuppressWarnings ("ConstantConditions" )
353
- private static Function <HttpRequestValues , Publisher <?>> initResponseEntityFunction (
354
- HttpClientAdapter client , MethodParameter methodParam , @ Nullable ReactiveAdapter reactiveAdapter ) {
355
+ private static Function <HttpRequestValues , Publisher <?>> initResponseEntityFunction (HttpClientAdapter client ,
356
+ MethodParameter methodParam , @ Nullable ReactiveAdapter reactiveAdapter , boolean isSuspending ) {
355
357
356
358
if (reactiveAdapter == null ) {
357
359
return request -> client .requestToEntity (
@@ -362,7 +364,8 @@ private static Function<HttpRequestValues, Publisher<?>> initResponseEntityFunct
362
364
"ResponseEntity body must be a concrete value or a multi-value Publisher" );
363
365
364
366
ParameterizedTypeReference <?> bodyType =
365
- ParameterizedTypeReference .forType (methodParam .nested ().getNestedGenericParameterType ());
367
+ ParameterizedTypeReference .forType (isSuspending ? methodParam .nested ().getGenericParameterType () :
368
+ methodParam .nested ().getNestedGenericParameterType ());
366
369
367
370
// Shortcut for Flux
368
371
if (reactiveAdapter .getReactiveType ().equals (Flux .class )) {
@@ -376,11 +379,12 @@ private static Function<HttpRequestValues, Publisher<?>> initResponseEntityFunct
376
379
});
377
380
}
378
381
379
- private static Function <HttpRequestValues , Publisher <?>> initBodyFunction (
380
- HttpClientAdapter client , MethodParameter methodParam , @ Nullable ReactiveAdapter reactiveAdapter ) {
382
+ private static Function <HttpRequestValues , Publisher <?>> initBodyFunction (HttpClientAdapter client ,
383
+ MethodParameter methodParam , @ Nullable ReactiveAdapter reactiveAdapter , boolean isSuspending ) {
381
384
382
385
ParameterizedTypeReference <?> bodyType =
383
- ParameterizedTypeReference .forType (methodParam .getNestedGenericParameterType ());
386
+ ParameterizedTypeReference .forType (isSuspending ? methodParam .getGenericParameterType () :
387
+ methodParam .getNestedGenericParameterType ());
384
388
385
389
return (reactiveAdapter != null && reactiveAdapter .isMultiValue () ?
386
390
request -> client .requestToBodyFlux (request , bodyType ) :
0 commit comments