Fine-tuned assertions and related polishing in WebFlux builders
This commit is contained in:
@@ -125,14 +125,10 @@ public final class MultipartBodyBuilder {
|
||||
* @param elementClass the type of elements contained in the publisher
|
||||
* @return builder that allows for further customization of part headers
|
||||
*/
|
||||
public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publisher,
|
||||
Class<T> elementClass) {
|
||||
|
||||
Assert.notNull(elementClass, "'elementClass' must not be null");
|
||||
ResolvableType elementType = ResolvableType.forClass(elementClass);
|
||||
public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publisher, Class<T> elementClass) {
|
||||
Assert.hasLength(name, "'name' must not be empty");
|
||||
Assert.notNull(publisher, "'publisher' must not be null");
|
||||
Assert.notNull(elementType, "'elementType' must not be null");
|
||||
Assert.notNull(elementClass, "'elementClass' must not be null");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
PublisherPartBuilder<T, P> builder = new PublisherPartBuilder<>(headers, publisher, elementClass);
|
||||
@@ -150,14 +146,12 @@ public final class MultipartBodyBuilder {
|
||||
* @param typeReference the type of elements contained in the publisher
|
||||
* @return builder that allows for further customization of part headers
|
||||
*/
|
||||
public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publisher,
|
||||
ParameterizedTypeReference<T> typeReference) {
|
||||
public <T, P extends Publisher<T>> PartBuilder asyncPart(
|
||||
String name, P publisher, ParameterizedTypeReference<T> typeReference) {
|
||||
|
||||
Assert.notNull(typeReference, "'typeReference' must not be null");
|
||||
ResolvableType elementType1 = ResolvableType.forType(typeReference);
|
||||
Assert.hasLength(name, "'name' must not be empty");
|
||||
Assert.notNull(publisher, "'publisher' must not be null");
|
||||
Assert.notNull(elementType1, "'typeReference' must not be null");
|
||||
Assert.notNull(typeReference, "'typeReference' must not be null");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
PublisherPartBuilder<T, P> builder = new PublisherPartBuilder<>(headers, publisher, typeReference);
|
||||
@@ -210,7 +204,6 @@ public final class MultipartBodyBuilder {
|
||||
@Nullable
|
||||
protected final Object body;
|
||||
|
||||
|
||||
public DefaultPartBuilder(HttpHeaders headers, @Nullable Object body) {
|
||||
this.headers = headers;
|
||||
this.body = body;
|
||||
@@ -224,7 +217,6 @@ public final class MultipartBodyBuilder {
|
||||
|
||||
@Override
|
||||
public PartBuilder headers(Consumer<HttpHeaders> headersConsumer) {
|
||||
Assert.notNull(headersConsumer, "'headersConsumer' must not be null");
|
||||
headersConsumer.accept(this.headers);
|
||||
return this;
|
||||
}
|
||||
@@ -239,7 +231,6 @@ public final class MultipartBodyBuilder {
|
||||
|
||||
private final ResolvableType resolvableType;
|
||||
|
||||
|
||||
public PublisherPartBuilder(HttpHeaders headers, P body, Class<S> elementClass) {
|
||||
super(headers, body);
|
||||
this.resolvableType = ResolvableType.forClass(elementClass);
|
||||
@@ -255,12 +246,11 @@ public final class MultipartBodyBuilder {
|
||||
this.resolvableType = other.getResolvableType();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public HttpEntity<?> build() {
|
||||
P publisher = (P) this.body;
|
||||
Assert.state(publisher != null, "'publisher' must not be null");
|
||||
Assert.state(publisher != null, "Publisher must not be null");
|
||||
return new PublisherEntity<>(this.headers, publisher, this.resolvableType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.server.reactive;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
*/
|
||||
public class HttpHeadResponseDecorator extends ServerHttpResponseDecorator {
|
||||
|
||||
|
||||
public HttpHeadResponseDecorator(ServerHttpResponse delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
@@ -45,9 +45,7 @@ public class HttpHeadResponseDecorator extends ServerHttpResponseDecorator {
|
||||
*/
|
||||
@Override
|
||||
public final Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
|
||||
|
||||
// After Reactor Netty #171 is fixed we can return without delegating
|
||||
|
||||
return getDelegate().writeWith(
|
||||
Flux.from(body)
|
||||
.reduce(0, (current, buffer) -> {
|
||||
@@ -61,7 +59,6 @@ public class HttpHeadResponseDecorator extends ServerHttpResponseDecorator {
|
||||
|
||||
/**
|
||||
* Invoke {@link #setComplete()} without writing.
|
||||
*
|
||||
* <p>RFC 7302 allows HTTP HEAD response without content-length and it's not
|
||||
* something that can be computed on a streaming response.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -43,7 +43,7 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
|
||||
|
||||
|
||||
public ServerHttpRequestDecorator(ServerHttpRequest delegate) {
|
||||
Assert.notNull(delegate, "ServerHttpRequest delegate is required.");
|
||||
Assert.notNull(delegate, "Delegate is required");
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -42,7 +42,7 @@ public class ServerHttpResponseDecorator implements ServerHttpResponse {
|
||||
|
||||
|
||||
public ServerHttpResponseDecorator(ServerHttpResponse delegate) {
|
||||
Assert.notNull(delegate, "ServerHttpResponse delegate is required.");
|
||||
Assert.notNull(delegate, "Delegate is required");
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,7 +310,8 @@ public class PathPattern implements Comparable<PathPattern> {
|
||||
}
|
||||
}
|
||||
resultPath = PathContainer.parsePath(buf.toString());
|
||||
} else if (startIndex >= endIndex) {
|
||||
}
|
||||
else if (startIndex >= endIndex) {
|
||||
resultPath = PathContainer.parsePath("");
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user