Skip to content

Commit 73d30dd

Browse files
committed
Polishing contribution
Closes gh-30403
1 parent 033548a commit 73d30dd

File tree

6 files changed

+53
-50
lines changed

6 files changed

+53
-50
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,12 @@ Annotated, HTTP exchange methods support the following return values:
497497
TIP: You can also use any other async or reactive types registered in the
498498
`ReactiveAdapterRegistry`.
499499

500-
TIP: For non-reactive types, blocking from a reactive publisher is performed
501-
under the hood by the framework. By default, it is done without a timeout.
502-
You can set a timeout for blocking by calling `blockTimeout(Duration blockTimeout)`
503-
on `HttpServiceProxyFactory.Builder`.
500+
By default, the behavior of HTTP service methods with synchronous (blocking) method
501+
signature depends on connection and timeout settings of the underlying HTTP client.
502+
`HttpServiceProxyFactory.Builder` does expose a `blockTimeout` option that also lets you
503+
configure the maximum time to block for a response, but we recommend configuring timeout
504+
values directly on the underlying HTTP client, which likely provides more control over
505+
such settings.
504506

505507

506508
[[rest-http-interface-exceptions]]

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,9 @@ Annotated, RSocket exchange methods support return values that are concrete valu
10641064
any producer of value(s) that can be adapted to a Reactive Streams `Publisher` via
10651065
`ReactiveAdapterRegistry`.
10661066

1067-
TIP: For non-reactive types, blocking from a reactive publisher is performed
1068-
under the hood by the framework. By default, it is done without a timeout.
1069-
You can set a timeout for blocking by calling `blockTimeout(Duration blockTimeout)`
1070-
on `RSocketServiceProxyFactory.Builder`.
1067+
By default, the behavior of RSocket service methods with synchronous (blocking) method
1068+
signature depends on response timeout settings of the underlying RSocket `ClientTransport`
1069+
as well as RSocket keep-alive settings. `RSocketServiceProxyFactory.Builder` does expose a
1070+
`blockTimeout` option that also lets you configure the maximum time to block for a response,
1071+
but we recommend configuring timeout values at the RSocket level for more control.
1072+

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ final class RSocketServiceMethod {
7373
this.parameters = initMethodParameters(method);
7474
this.argumentResolvers = argumentResolvers;
7575
this.route = initRoute(method, containingClass, rsocketRequester.strategies(), embeddedValueResolver);
76-
this.responseFunction = initResponseFunction(
77-
rsocketRequester, method, reactiveRegistry, blockTimeout);
76+
this.responseFunction = initResponseFunction(rsocketRequester, method, reactiveRegistry, blockTimeout);
7877
}
7978

8079
private static MethodParameter[] initMethodParameters(Method method) {
@@ -163,11 +162,16 @@ else if (reactiveAdapter == null) {
163162
if (reactiveAdapter != null) {
164163
return reactiveAdapter.fromPublisher(responsePublisher);
165164
}
166-
return (blockForOptional ?
167-
(blockTimeout != null ? ((Mono<?>) responsePublisher).blockOptional(blockTimeout) :
168-
((Mono<?>) responsePublisher).blockOptional()) :
169-
(blockTimeout != null ? ((Mono<?>) responsePublisher).block(blockTimeout) :
170-
((Mono<?>) responsePublisher).block()));
165+
if (blockForOptional) {
166+
return (blockTimeout != null ?
167+
((Mono<?>) responsePublisher).blockOptional(blockTimeout) :
168+
((Mono<?>) responsePublisher).blockOptional());
169+
}
170+
else {
171+
return (blockTimeout != null ?
172+
((Mono<?>) responsePublisher).block(blockTimeout) :
173+
((Mono<?>) responsePublisher).block());
174+
}
171175
});
172176
}
173177

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,17 @@ public Builder reactiveAdapterRegistry(ReactiveAdapterRegistry registry) {
188188
}
189189

190190
/**
191-
* Configure how long to wait for a response for an HTTP service method
191+
* Configure how long to block for the response of an RSocket service method
192192
* with a synchronous (blocking) method signature.
193-
* <p>By default this is {@code null},
194-
* in which case means blocking on publishers is done without a timeout.
193+
* <p>By default this is not set, in which case the behavior depends on
194+
* connection and response timeout settings of the underlying RSocket
195+
* {@code ClientTransport} as well as RSocket keep-alive settings.
196+
* We recommend configuring timeout values at the RSocket level which
197+
* provides more control.
195198
* @param blockTimeout the timeout value
196199
* @return this same builder instance
197200
*/
198-
public Builder blockTimeout(Duration blockTimeout) {
201+
public Builder blockTimeout(@Nullable Duration blockTimeout) {
199202
this.blockTimeout = blockTimeout;
200203
return this;
201204
}
@@ -208,8 +211,7 @@ public RSocketServiceProxyFactory build() {
208211

209212
return new RSocketServiceProxyFactory(
210213
this.rsocketRequester, initArgumentResolvers(),
211-
this.embeddedValueResolver, this.reactiveAdapterRegistry,
212-
this.blockTimeout);
214+
this.embeddedValueResolver, this.reactiveAdapterRegistry, this.blockTimeout);
213215
}
214216

215217
private List<RSocketServiceArgumentResolver> initArgumentResolvers() {

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

+15-23
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,13 @@ private void applyArguments(HttpRequestValues.Builder requestValues, Object[] ar
123123
}
124124
}
125125
int index = i;
126-
Assert.state(resolved, () -> formatArgumentError(this.parameters[index], "No suitable resolver"));
126+
Assert.state(resolved, () ->
127+
"Could not resolve parameter [" + this.parameters[index].getParameterIndex() + "] in " +
128+
this.parameters[index].getExecutable().toGenericString() +
129+
(StringUtils.hasText("No suitable resolver") ? ": " + "No suitable resolver" : ""));
127130
}
128131
}
129132

130-
private static String formatArgumentError(MethodParameter param, String message) {
131-
return "Could not resolve parameter [" + param.getParameterIndex() + "] in " +
132-
param.getExecutable().toGenericString() + (StringUtils.hasText(message) ? ": " + message : "");
133-
}
134-
135133

136134
/**
137135
* Factory for {@link HttpRequestValues} with values extracted from the type
@@ -277,17 +275,6 @@ private record ResponseFunction(
277275
@Nullable ReactiveAdapter returnTypeAdapter,
278276
boolean blockForOptional, @Nullable Duration blockTimeout) {
279277

280-
private ResponseFunction(
281-
Function<HttpRequestValues, Publisher<?>> responseFunction,
282-
@Nullable ReactiveAdapter returnTypeAdapter,
283-
boolean blockForOptional, Duration blockTimeout) {
284-
285-
this.responseFunction = responseFunction;
286-
this.returnTypeAdapter = returnTypeAdapter;
287-
this.blockForOptional = blockForOptional;
288-
this.blockTimeout = blockTimeout;
289-
}
290-
291278
@Nullable
292279
public Object execute(HttpRequestValues requestValues) {
293280

@@ -297,11 +284,16 @@ public Object execute(HttpRequestValues requestValues) {
297284
return this.returnTypeAdapter.fromPublisher(responsePublisher);
298285
}
299286

300-
return (this.blockForOptional ?
301-
(this.blockTimeout != null ? ((Mono<?>) responsePublisher).blockOptional(this.blockTimeout) :
302-
((Mono<?>) responsePublisher).blockOptional()) :
303-
(this.blockTimeout != null ? ((Mono<?>) responsePublisher).block(this.blockTimeout) :
304-
((Mono<?>) responsePublisher).block()));
287+
if (this.blockForOptional) {
288+
return (this.blockTimeout != null ?
289+
((Mono<?>) responsePublisher).blockOptional(this.blockTimeout) :
290+
((Mono<?>) responsePublisher).blockOptional());
291+
}
292+
else {
293+
return (this.blockTimeout != null ?
294+
((Mono<?>) responsePublisher).block(this.blockTimeout) :
295+
((Mono<?>) responsePublisher).block());
296+
}
305297
}
306298

307299

@@ -310,7 +302,7 @@ public Object execute(HttpRequestValues requestValues) {
310302
*/
311303
public static ResponseFunction create(
312304
HttpClientAdapter client, Method method, ReactiveAdapterRegistry reactiveRegistry,
313-
Duration blockTimeout) {
305+
@Nullable Duration blockTimeout) {
314306

315307
MethodParameter returnParam = new MethodParameter(method, -1);
316308
Class<?> returnType = returnParam.getParameterType();

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,16 @@ public Builder reactiveAdapterRegistry(ReactiveAdapterRegistry registry) {
207207
}
208208

209209
/**
210-
* Configure how long to wait for a response for an HTTP service method
210+
* Configure how long to block for the response of an HTTP service method
211211
* with a synchronous (blocking) method signature.
212-
* <p>By default this is {@code null},
213-
* in which case means blocking on publishers is done without a timeout.
212+
* <p>By default this is not set, in which case the behavior depends on
213+
* connection and request timeout settings of the underlying HTTP client.
214+
* We recommend configuring timeout values directly on the underlying HTTP
215+
* client, which provides more control over such settings.
214216
* @param blockTimeout the timeout value
215217
* @return this same builder instance
216218
*/
217-
public Builder blockTimeout(Duration blockTimeout) {
219+
public Builder blockTimeout(@Nullable Duration blockTimeout) {
218220
this.blockTimeout = blockTimeout;
219221
return this;
220222
}
@@ -227,8 +229,7 @@ public HttpServiceProxyFactory build() {
227229

228230
return new HttpServiceProxyFactory(
229231
this.clientAdapter, initArgumentResolvers(),
230-
this.embeddedValueResolver, this.reactiveAdapterRegistry,
231-
this.blockTimeout);
232+
this.embeddedValueResolver, this.reactiveAdapterRegistry, this.blockTimeout);
232233
}
233234

234235
private List<HttpServiceArgumentResolver> initArgumentResolvers() {

0 commit comments

Comments
 (0)