Polishing and minor refactoring

See gh-25884
This commit is contained in:
Rossen Stoyanchev
2020-10-12 11:32:48 +01:00
parent 66138f0dce
commit 5b1b20c8c0
12 changed files with 56 additions and 59 deletions

View File

@@ -57,9 +57,10 @@ public class ErrorsMethodArgumentResolver extends HandlerMethodArgumentResolverS
Object errors = getErrors(parameter, context);
// Initially Errors/BindingResult is a Mono in the model even if it cannot be declared
// as an async argument. That way it can be resolved first while the Mono can complete
// later at which point the model is also updated for further use.
// Initially ModelAttributeMethodArgumentResolver adds Errors/BindingResult as a
// Mono in the model even if it can't be declared as such on a controller method.
// This is done to enable early argument resolution here. When the Mono actually
// completes it is replaced in the model with the actual value.
if (Mono.class.isAssignableFrom(errors.getClass())) {
return ((Mono<?>) errors).cast(Object.class);

View File

@@ -119,13 +119,13 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR
return valueMono.flatMap(value -> {
WebExchangeDataBinder binder = context.createDataBinder(exchange, value, name);
return bindRequestParameters(binder, exchange)
.doOnError(ex -> bindingResultSink.emitError(ex, Sinks.EmitFailureHandler.FAIL_FAST))
.doOnError(bindingResultSink::tryEmitError)
.doOnSuccess(aVoid -> {
validateIfApplicable(binder, parameter);
BindingResult bindingResult = binder.getBindingResult();
model.put(BindingResult.MODEL_KEY_PREFIX + name, bindingResult);
model.put(name, value);
// serialized and buffered (should never fail)
// Ignore result: serialized and buffered (should never fail)
bindingResultSink.tryEmitValue(bindingResult);
})
.then(Mono.fromCallable(() -> {

View File

@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import javax.websocket.Session;
import org.apache.tomcat.websocket.WsSession;
import reactor.core.publisher.Sinks;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.web.reactive.socket.HandshakeInfo;
@@ -46,7 +47,14 @@ public class TomcatWebSocketSession extends StandardWebSocketSession {
super(session, info, factory);
}
@SuppressWarnings("deprecation")
public TomcatWebSocketSession(Session session, HandshakeInfo info, DataBufferFactory factory,
Sinks.Empty<Void> completionSink) {
super(session, info, factory, completionSink);
suspendReceiving();
}
@Deprecated
public TomcatWebSocketSession(Session session, HandshakeInfo info, DataBufferFactory factory,
reactor.core.publisher.MonoProcessor<Void> completionMono) {

View File

@@ -112,10 +112,10 @@ public class StandardWebSocketClient implements WebSocketClient {
}
private StandardWebSocketHandlerAdapter createEndpoint(URI url, WebSocketHandler handler,
Sinks.Empty<Void> completion, DefaultConfigurator configurator) {
Sinks.Empty<Void> completionSink, DefaultConfigurator configurator) {
return new StandardWebSocketHandlerAdapter(handler, session ->
createWebSocketSession(session, createHandshakeInfo(url, configurator), completion));
createWebSocketSession(session, createHandshakeInfo(url, configurator), completionSink));
}
private HandshakeInfo createHandshakeInfo(URI url, DefaultConfigurator configurator) {
@@ -124,21 +124,13 @@ public class StandardWebSocketClient implements WebSocketClient {
return new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol);
}
protected StandardWebSocketSession createWebSocketSession(Session session, HandshakeInfo info,
Sinks.Empty<Void> completionSink) {
protected StandardWebSocketSession createWebSocketSession(
Session session, HandshakeInfo info, Sinks.Empty<Void> completionSink) {
return new StandardWebSocketSession(
session, info, DefaultDataBufferFactory.sharedInstance, completionSink);
}
@Deprecated
protected StandardWebSocketSession createWebSocketSession(Session session, HandshakeInfo info,
reactor.core.publisher.MonoProcessor<Void> completionMono) {
return new StandardWebSocketSession(
session, info, DefaultDataBufferFactory.sharedInstance, completionMono);
}
private ClientEndpointConfig createEndpointConfig(Configurator configurator, List<String> subProtocols) {
return ClientEndpointConfig.Builder.create()
.configurator(configurator)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import org.apache.tomcat.websocket.WsWebSocketContainer;
import reactor.core.publisher.Sinks;
import org.springframework.web.reactive.socket.HandshakeInfo;
import org.springframework.web.reactive.socket.adapter.StandardWebSocketSession;
@@ -44,11 +45,10 @@ public class TomcatWebSocketClient extends StandardWebSocketClient {
@Override
@SuppressWarnings("deprecation")
protected StandardWebSocketSession createWebSocketSession(Session session,
HandshakeInfo info, reactor.core.publisher.MonoProcessor<Void> completionMono) {
protected StandardWebSocketSession createWebSocketSession(
Session session, HandshakeInfo info, Sinks.Empty<Void> completionSink) {
return new TomcatWebSocketSession(session, info, bufferFactory(), completionMono);
return new TomcatWebSocketSession(session, info, bufferFactory(), completionSink);
}
}