Skip to content

Commit cef1b7e

Browse files
committed
Polishing in HTTP interface argument resolvers
1 parent 51de84e commit cef1b7e

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

framework-docs/modules/ROOT/pages/integration/rest-clients.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,13 @@ method parameters:
978978
`MultiValueMap<String, ?>` with multiple cookies, a `Collection<?>` of values, or an
979979
individual value. Type conversion is supported for non-String values.
980980

981-
The parameters can't be null unless they are set as not required through the annotation,
982-
annotated with `@Nullable` or they are `Optional`.
983-
984981
|===
985982

983+
Method parameters cannot be `null` unless the `required` attribute (where available on a
984+
parameter annotation) is set to `false`, or the parameter is marked optional as determined by
985+
{spring-framework-api}/core/MethodParameter.html#isOptional()[`MethodParameter#isOptional`].
986+
987+
986988

987989
[[rest-http-interface-return-values]]
988990
=== Return Values

framework-docs/modules/ROOT/pages/rsocket.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,9 @@ method parameters:
11151115
| `@Payload`
11161116
| Set the input payload(s) for the request. This can be a concrete value, or any producer
11171117
of values that can be adapted to a Reactive Streams `Publisher` via
1118-
`ReactiveAdapterRegistry`. The payload can't be null unless it's set as not required
1119-
through the annotation, annotated with `@Nullable` or it is `Optional`.
1118+
`ReactiveAdapterRegistry`. A payload must be provided unless the `required` attribute
1119+
is set to `false`, or the parameter is marked optional as determined by
1120+
{spring-framework-api}/core/MethodParameter.html#isOptional()[`MethodParameter#isOptional`].
11201121

11211122
| `Object`, if followed by `MimeType`
11221123
| The value for a metadata entry in the input payload. This can be any `Object` as long

spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolver.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ public boolean resolve(
5656
}
5757

5858
if (argument == null) {
59-
boolean required = (annot == null || annot.required()) && !parameter.isOptional();
60-
Assert.isTrue(!required, () -> "Missing payload");
59+
boolean isOptional = ((annot != null && !annot.required()) || parameter.isOptional());
60+
Assert.isTrue(isOptional, () -> "Missing payload");
6161
return true;
6262
}
6363

64-
ReactiveAdapter reactiveAdapter = this.reactiveAdapterRegistry
65-
.getAdapter(parameter.getParameterType());
66-
if (reactiveAdapter == null) {
64+
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(parameter.getParameterType());
65+
if (adapter == null) {
6766
requestValues.setPayloadValue(argument);
6867
}
6968
else {
7069
MethodParameter nestedParameter = parameter.nested();
7170

7271
String message = "Async type for @Payload should produce value(s)";
7372
Assert.isTrue(nestedParameter.getNestedParameterType() != Void.class, message);
74-
Assert.isTrue(!reactiveAdapter.isNoValue(), message);
73+
Assert.isTrue(!adapter.isNoValue(), message);
7574

7675
requestValues.setPayload(
77-
reactiveAdapter.toPublisher(argument),
76+
adapter.toPublisher(argument),
7877
ParameterizedTypeReference.forType(nestedParameter.getNestedGenericParameterType()));
7978
}
79+
8080
return true;
8181
}
8282
}

spring-web/src/main/java/org/springframework/web/service/invoker/HttpMethodArgumentResolver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public boolean resolve(
6363
if (logger.isTraceEnabled()) {
6464
logger.trace("Resolved HTTP method to: " + httpMethod.name());
6565
}
66+
6667
return true;
6768
}
6869

spring-web/src/main/java/org/springframework/web/service/invoker/RequestBodyArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public boolean resolve(
8181
}
8282

8383
if (this.reactiveAdapterRegistry != null) {
84-
ReactiveAdapter adapter = this.reactiveAdapterRegistry
85-
.getAdapter(parameter.getParameterType());
84+
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(parameter.getParameterType());
8685
if (adapter != null) {
8786
MethodParameter nestedParameter = parameter.nested();
8887

@@ -102,6 +101,7 @@ public boolean resolve(
102101
return true;
103102
}
104103
}
104+
105105
// Not a reactive type
106106
requestValues.setBodyValue(argument);
107107
return true;

0 commit comments

Comments
 (0)