提交 d421112a 编写于 作者: R Rossen Stoyanchev

Polish ServerWebExchange builder and ServerHttpResponse

Remove duplicated ServerHttpResponse#setComplete also declard in the
parent ReactiveHttpOutputMessage interface.

Also rename:
ServerWebExchange.MutativeBuilder --> ServerWebExchange.Builder
上级 7193686b
......@@ -76,7 +76,7 @@ public class ModelAttributeMethodArgumentResolverTests {
public void setUp() throws Exception {
MockServerHttpResponse response = new MockServerHttpResponse();
this.exchange = new DefaultServerWebExchange(this.request, response, new MockWebSessionManager());
this.exchange = this.exchange.mutate().setFormData(Mono.just(this.formData)).build();
this.exchange = this.exchange.mutate().formData(Mono.just(this.formData)).build();
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
......
......@@ -18,8 +18,6 @@ package org.springframework.http.server.reactive;
import java.util.function.Function;
import reactor.core.publisher.Mono;
import org.springframework.http.HttpStatus;
import org.springframework.http.ReactiveHttpOutputMessage;
import org.springframework.http.ResponseCookie;
......@@ -70,15 +68,4 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage {
*/
void registerUrlEncoder(Function<String, String> encoder);
/**
* Indicate that request handling is complete, allowing for any cleanup or
* end-of-processing tasks to be performed such as applying header changes
* made via {@link #getHeaders()} to the underlying server response (if not
* applied already).
* <p>This method should be automatically invoked at the end of request
* processing so typically applications should not have to invoke it.
* If invoked multiple times it should have no side effects.
*/
Mono<Void> setComplete();
}
......@@ -25,13 +25,12 @@ import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
/**
* Default implementation of
* {@link org.springframework.web.server.ServerWebExchange.MutativeBuilder}.
*
* Package private implementation of {@link ServerWebExchange.Builder}.
*
* @author Rossen Stoyanchev
* @since 5.0
*/
class DefaultServerWebExchangeMutativeBuilder implements ServerWebExchange.MutativeBuilder {
class DefaultServerWebExchangeBuilder implements ServerWebExchange.Builder {
private final ServerWebExchange delegate;
......@@ -46,38 +45,38 @@ class DefaultServerWebExchangeMutativeBuilder implements ServerWebExchange.Mutat
private Mono<MultiValueMap<String, String>> formData;
public DefaultServerWebExchangeMutativeBuilder(ServerWebExchange delegate) {
public DefaultServerWebExchangeBuilder(ServerWebExchange delegate) {
Assert.notNull(delegate, "'delegate' is required.");
this.delegate = delegate;
}
@Override
public ServerWebExchange.MutativeBuilder setRequest(ServerHttpRequest request) {
public ServerWebExchange.Builder request(ServerHttpRequest request) {
this.request = request;
return this;
}
@Override
public ServerWebExchange.MutativeBuilder setResponse(ServerHttpResponse response) {
public ServerWebExchange.Builder response(ServerHttpResponse response) {
this.response = response;
return this;
}
@Override
public ServerWebExchange.MutativeBuilder setPrincipal(Mono<Principal> user) {
public ServerWebExchange.Builder principal(Mono<Principal> user) {
this.user = user;
return this;
}
@Override
public ServerWebExchange.MutativeBuilder setSession(Mono<WebSession> session) {
public ServerWebExchange.Builder session(Mono<WebSession> session) {
this.session = session;
return this;
}
@Override
public ServerWebExchange.MutativeBuilder setFormData(Mono<MultiValueMap<String, String>> formData) {
public ServerWebExchange.Builder formData(Mono<MultiValueMap<String, String>> formData) {
this.formData = formData;
return this;
}
......
......@@ -129,43 +129,42 @@ public interface ServerWebExchange {
/**
* Return a builder to mutate properties of this exchange. The resulting
* new exchange is an immutable {@link ServerWebExchangeDecorator decorator}
* around the current exchange instance that returns mutated values, where
* provided, or delegating to the decorated instance otherwise.
* around the current exchange instance returning mutated values.
*/
default MutativeBuilder mutate() {
return new DefaultServerWebExchangeMutativeBuilder(this);
default Builder mutate() {
return new DefaultServerWebExchangeBuilder(this);
}
/**
* Builder for mutating properties of a {@link ServerWebExchange}.
* Builder for mutating the properties of a {@link ServerWebExchange}.
*/
interface MutativeBuilder {
interface Builder {
/**
* Set the request to use.
*/
MutativeBuilder setRequest(ServerHttpRequest request);
Builder request(ServerHttpRequest request);
/**
* Set the response to use.
*/
MutativeBuilder setResponse(ServerHttpResponse response);
Builder response(ServerHttpResponse response);
/**
* Set the principal to use.
*/
MutativeBuilder setPrincipal(Mono<Principal> user);
Builder principal(Mono<Principal> user);
/**
* Set the session to use.
*/
MutativeBuilder setSession(Mono<WebSession> session);
Builder session(Mono<WebSession> session);
/**
* Set the form data.
*/
MutativeBuilder setFormData(Mono<MultiValueMap<String, String>> formData);
Builder formData(Mono<MultiValueMap<String, String>> formData);
/**
* Build an immutable wrapper that returning the mutated properties.
......
......@@ -32,8 +32,8 @@ import org.springframework.util.MultiValueMap;
* {@link ServerWebExchange}. Pre-implements all methods by delegating to the
* wrapped instance.
*
* <p>Note that if the purpose for wrapping is simply to override specific
* properties, e.g. {@link #getPrincipal()}, consider using
* <p><strong>Note:</strong> if the purpose for using a decorator is to override
* properties like {@link #getPrincipal()}, consider using
* {@link ServerWebExchange#mutate()} instead.
*
* @author Rossen Stoyanchev
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册