Polishing in HTTP interface argument resolvers

This commit is contained in:
rstoyanchev 2024-08-12 21:00:17 +03:00
parent 51de84e148
commit cef1b7ea6d
5 changed files with 18 additions and 14 deletions

View File

@ -978,11 +978,13 @@ method parameters:
`MultiValueMap<String, ?>` with multiple cookies, a `Collection<?>` of values, or an
individual value. Type conversion is supported for non-String values.
The parameters can't be null unless they are set as not required through the annotation,
annotated with `@Nullable` or they are `Optional`.
|===
Method parameters cannot be `null` unless the `required` attribute (where available on a
parameter annotation) is set to `false`, or the parameter is marked optional as determined by
{spring-framework-api}/core/MethodParameter.html#isOptional()[`MethodParameter#isOptional`].
[[rest-http-interface-return-values]]
=== Return Values

View File

@ -1115,8 +1115,9 @@ method parameters:
| `@Payload`
| Set the input payload(s) for the request. This can be a concrete value, or any producer
of values that can be adapted to a Reactive Streams `Publisher` via
`ReactiveAdapterRegistry`. The payload can't be null unless it's set as not required
through the annotation, annotated with `@Nullable` or it is `Optional`.
`ReactiveAdapterRegistry`. A payload must be provided unless the `required` attribute
is set to `false`, or the parameter is marked optional as determined by
{spring-framework-api}/core/MethodParameter.html#isOptional()[`MethodParameter#isOptional`].
| `Object`, if followed by `MimeType`
| The value for a metadata entry in the input payload. This can be any `Object` as long

View File

@ -56,14 +56,13 @@ public class PayloadArgumentResolver implements RSocketServiceArgumentResolver {
}
if (argument == null) {
boolean required = (annot == null || annot.required()) && !parameter.isOptional();
Assert.isTrue(!required, () -> "Missing payload");
boolean isOptional = ((annot != null && !annot.required()) || parameter.isOptional());
Assert.isTrue(isOptional, () -> "Missing payload");
return true;
}
ReactiveAdapter reactiveAdapter = this.reactiveAdapterRegistry
.getAdapter(parameter.getParameterType());
if (reactiveAdapter == null) {
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(parameter.getParameterType());
if (adapter == null) {
requestValues.setPayloadValue(argument);
}
else {
@ -71,12 +70,13 @@ public class PayloadArgumentResolver implements RSocketServiceArgumentResolver {
String message = "Async type for @Payload should produce value(s)";
Assert.isTrue(nestedParameter.getNestedParameterType() != Void.class, message);
Assert.isTrue(!reactiveAdapter.isNoValue(), message);
Assert.isTrue(!adapter.isNoValue(), message);
requestValues.setPayload(
reactiveAdapter.toPublisher(argument),
adapter.toPublisher(argument),
ParameterizedTypeReference.forType(nestedParameter.getNestedGenericParameterType()));
}
return true;
}
}

View File

@ -63,6 +63,7 @@ public class HttpMethodArgumentResolver implements HttpServiceArgumentResolver {
if (logger.isTraceEnabled()) {
logger.trace("Resolved HTTP method to: " + httpMethod.name());
}
return true;
}

View File

@ -81,8 +81,7 @@ public class RequestBodyArgumentResolver implements HttpServiceArgumentResolver
}
if (this.reactiveAdapterRegistry != null) {
ReactiveAdapter adapter = this.reactiveAdapterRegistry
.getAdapter(parameter.getParameterType());
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(parameter.getParameterType());
if (adapter != null) {
MethodParameter nestedParameter = parameter.nested();
@ -102,6 +101,7 @@ public class RequestBodyArgumentResolver implements HttpServiceArgumentResolver
return true;
}
}
// Not a reactive type
requestValues.setBodyValue(argument);
return true;