Fine-tuned assertions and related polishing in WebFlux builders

This commit is contained in:
Juergen Hoeller 2018-04-27 23:36:58 +02:00
parent 6519e7b22a
commit 9bff5b48cf
32 changed files with 114 additions and 179 deletions

View File

@ -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);
}
}

View File

@ -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.
*/

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 {

View File

@ -212,7 +212,7 @@ public abstract class BodyInserters {
* @return the inserter that allows adding more form data
*/
public static FormInserter<String> fromFormData(String name, String value) {
Assert.notNull(name, "'key' must not be null");
Assert.notNull(name, "'name' must not be null");
Assert.notNull(value, "'value' must not be null");
return new DefaultFormInserter().with(name, value);
}
@ -221,11 +221,9 @@ public abstract class BodyInserters {
* Return a {@link MultipartInserter} that writes the given
* {@code MultiValueMap} as multipart data. Values in the map can be an
* Object or an {@link HttpEntity}.
*
* <p>Note that you can also build the multipart data externally with
* {@link MultipartBodyBuilder}, and pass the resulting map directly to the
* {@code syncBody(Object)} shortcut method in {@code WebClient}.
*
* @param multipartData the form data to write to the output message
* @return the inserter that allows adding more parts
* @see MultipartBodyBuilder
@ -239,17 +237,15 @@ public abstract class BodyInserters {
* Return a {@link MultipartInserter} that writes the given parts,
* as multipart data. Values in the map can be an Object or an
* {@link HttpEntity}.
*
* <p>Note that you can also build the multipart data externally with
* {@link MultipartBodyBuilder}, and pass the resulting map directly to the
* {@code syncBody(Object)} shortcut method in {@code WebClient}.
*
* @param name the part name
* @param value the part value, an Object or {@code HttpEntity}
* @return the inserter that allows adding more parts
*/
public static MultipartInserter fromMultipartData(String name, Object value) {
Assert.notNull(name, "'key' must not be null");
Assert.notNull(name, "'name' must not be null");
Assert.notNull(value, "'value' must not be null");
return new DefaultMultipartInserter().with(name, value);
}
@ -257,22 +253,16 @@ public abstract class BodyInserters {
/**
* Return a {@link MultipartInserter} that writes the given asynchronous parts,
* as multipart data.
*
* <p>Note that you can also build the multipart data externally with
* {@link MultipartBodyBuilder}, and pass the resulting map directly to the
* {@code syncBody(Object)} shortcut method in {@code WebClient}.
*
* @param name the part name
* @param publisher the publisher that forms the part value
* @param elementClass the class contained in the {@code publisher}
* @return the inserter that allows adding more parts
*/
public static <T, P extends Publisher<T>> MultipartInserter fromMultipartAsyncData(String name,
P publisher, Class<T> elementClass) {
Assert.notNull(name, "'key' must not be null");
Assert.notNull(publisher, "'publisher' must not be null");
Assert.notNull(elementClass, "'elementClass' must not be null");
public static <T, P extends Publisher<T>> MultipartInserter fromMultipartAsyncData(
String name, P publisher, Class<T> elementClass) {
return new DefaultMultipartInserter().withPublisher(name, publisher, elementClass);
}
@ -281,22 +271,16 @@ public abstract class BodyInserters {
* Variant of {@link #fromMultipartAsyncData(String, Publisher, Class)} that
* accepts a {@link ParameterizedTypeReference} for the element type, which
* allows specifying generic type information.
*
* <p>Note that you can also build the multipart data externally with
* {@link MultipartBodyBuilder}, and pass the resulting map directly to the
* {@code syncBody(Object)} shortcut method in {@code WebClient}.
*
* @param name the part name
* @param publisher the publisher that forms the part value
* @param typeReference the type contained in the {@code publisher}
* @return the inserter that allows adding more parts
*/
public static <T, P extends Publisher<T>> MultipartInserter fromMultipartAsyncData(String name,
P publisher, ParameterizedTypeReference<T> typeReference) {
Assert.notNull(name, "'key' must not be null");
Assert.notNull(publisher, "'publisher' must not be null");
Assert.notNull(typeReference, "'typeReference' must not be null");
public static <T, P extends Publisher<T>> MultipartInserter fromMultipartAsyncData(
String name, P publisher, ParameterizedTypeReference<T> typeReference) {
return new DefaultMultipartInserter().withPublisher(name, publisher, typeReference);
}
@ -312,7 +296,7 @@ public abstract class BodyInserters {
public static <T extends Publisher<DataBuffer>> BodyInserter<T, ReactiveHttpOutputMessage> fromDataBuffers(
T publisher) {
Assert.notNull(publisher, "'publisher' must not be null");
Assert.notNull(publisher, "Publisher must not be null");
return (outputMessage, context) -> outputMessage.writeWith(publisher);
}
@ -333,9 +317,9 @@ public abstract class BodyInserters {
return messageWriter.write(body, bodyType, bodyType, contentType,
serverRequest.get(), (ServerHttpResponse) outputMessage,
context.hints());
} else {
return messageWriter.write(body, bodyType, contentType, outputMessage,
context.hints());
}
else {
return messageWriter.write(body, bodyType, contentType, outputMessage, context.hints());
}
})
.orElseGet(() -> {
@ -500,4 +484,5 @@ public abstract class BodyInserters {
outputMessage, context.hints());
}
}
}

View File

@ -28,7 +28,6 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserter;
@ -109,7 +108,6 @@ public interface ClientRequest {
* @return the created builder
*/
static Builder from(ClientRequest other) {
Assert.notNull(other, "'other' must not be null");
return new DefaultClientRequestBuilder(other);
}

View File

@ -35,7 +35,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.http.client.reactive.ClientHttpResponse;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
@ -160,7 +159,6 @@ public interface ClientResponse {
* @return the created builder
*/
static Builder from(ClientResponse other) {
Assert.notNull(other, "Other ClientResponse must not be null");
return new DefaultClientResponseBuilder(other);
}

View File

@ -47,7 +47,7 @@ import org.springframework.web.reactive.function.BodyInserters;
* @author Arjen Poutsma
* @since 5.0
*/
class DefaultClientRequestBuilder implements ClientRequest.Builder {
final class DefaultClientRequestBuilder implements ClientRequest.Builder {
private final HttpHeaders headers = new HttpHeaders();
@ -63,18 +63,21 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
public DefaultClientRequestBuilder(HttpMethod method, URI url) {
this.method = method;
this.url = url;
method(method);
url(url);
}
public DefaultClientRequestBuilder(ClientRequest other) {
this(other.method(), other.url());
Assert.notNull(other, "ClientRequest must not be null");
method(other.method());
url(other.url());
headers(headers -> headers.addAll(other.headers()));
cookies(cookies -> cookies.addAll(other.cookies()));
attributes(attributes -> attributes.putAll(other.attributes()));
body(other.body());
}
@Override
public ClientRequest.Builder method(HttpMethod method) {
Assert.notNull(method, "'method' must not be null");
@ -99,7 +102,6 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
@Override
public ClientRequest.Builder headers(Consumer<HttpHeaders> headersConsumer) {
Assert.notNull(headersConsumer, "'headersConsumer' must not be null");
headersConsumer.accept(this.headers);
return this;
}
@ -114,7 +116,6 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
@Override
public ClientRequest.Builder cookies(Consumer<MultiValueMap<String, String>> cookiesConsumer) {
Assert.notNull(cookiesConsumer, "'cookiesConsumer' must not be null");
cookiesConsumer.accept(this.cookies);
return this;
}
@ -129,8 +130,8 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
}
@Override
public <S, P extends Publisher<S>> ClientRequest.Builder body(P publisher,
ParameterizedTypeReference<S> typeReference) {
public <S, P extends Publisher<S>> ClientRequest.Builder body(
P publisher, ParameterizedTypeReference<S> typeReference) {
Assert.notNull(publisher, "'publisher' must not be null");
Assert.notNull(typeReference, "'typeReference' must not be null");
@ -147,7 +148,6 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
@Override
public ClientRequest.Builder attributes(Consumer<Map<String, Object>> attributesConsumer) {
Assert.notNull(attributesConsumer, "'attributesConsumer' must not be null");
attributesConsumer.accept(this.attributes);
return this;
}

View File

@ -40,7 +40,7 @@ import org.springframework.util.MultiValueMap;
* @author Arjen Poutsma
* @since 5.0.5
*/
class DefaultClientResponseBuilder implements ClientResponse.Builder {
final class DefaultClientResponseBuilder implements ClientResponse.Builder {
private final HttpHeaders headers = new HttpHeaders();
@ -59,7 +59,8 @@ class DefaultClientResponseBuilder implements ClientResponse.Builder {
}
public DefaultClientResponseBuilder(ClientResponse other) {
this(other.strategies());
Assert.notNull(other, "ClientResponse must not be null");
this.strategies = other.strategies();
statusCode(other.statusCode());
headers(headers -> headers.addAll(other.headers().asHttpHeaders()));
cookies(cookies -> cookies.addAll(other.cookies()));

View File

@ -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.
@ -24,7 +24,6 @@ import java.util.function.Consumer;
import org.springframework.http.codec.ClientCodecConfigurer;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.util.Assert;
/**
* Default implementation of {@link ExchangeStrategies.Builder}.
@ -32,7 +31,7 @@ import org.springframework.util.Assert;
* @author Arjen Poutsma
* @since 5.0
*/
class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Builder {
final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Builder {
private final ClientCodecConfigurer codecConfigurer = ClientCodecConfigurer.create();
@ -41,13 +40,13 @@ class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Builder {
this.codecConfigurer.registerDefaults(false);
}
public void defaultConfiguration() {
this.codecConfigurer.registerDefaults(true);
}
@Override
public ExchangeStrategies.Builder codecs(Consumer<ClientCodecConfigurer> consumer) {
Assert.notNull(consumer, "'consumer' must not be null");
consumer.accept(this.codecConfigurer);
return this;
}

View File

@ -215,7 +215,6 @@ class DefaultWebClient implements WebClient {
@Override
public DefaultRequestBodyUriSpec headers(Consumer<HttpHeaders> headersConsumer) {
Assert.notNull(headersConsumer, "'headersConsumer' must not be null");
headersConsumer.accept(getHeaders());
return this;
}
@ -228,7 +227,6 @@ class DefaultWebClient implements WebClient {
@Override
public RequestBodySpec attributes(Consumer<Map<String, Object>> attributesConsumer) {
Assert.notNull(attributesConsumer, "'attributesConsumer' must not be null");
attributesConsumer.accept(this.attributes);
return this;
}
@ -265,7 +263,6 @@ class DefaultWebClient implements WebClient {
@Override
public DefaultRequestBodyUriSpec cookies(Consumer<MultiValueMap<String, String>> cookiesConsumer) {
Assert.notNull(cookiesConsumer, "'cookiesConsumer' must not be null");
cookiesConsumer.accept(getCookies());
return this;
}
@ -378,7 +375,6 @@ class DefaultWebClient implements WebClient {
private List<StatusHandler> statusHandlers = new ArrayList<>(1);
DefaultResponseSpec(Mono<ClientResponse> responseMono) {
this.responseMono = responseMono;
this.statusHandlers.add(DEFAULT_STATUS_HANDLER);
@ -388,13 +384,9 @@ class DefaultWebClient implements WebClient {
public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
Assert.notNull(statusPredicate, "'statusPredicate' must not be null");
Assert.notNull(exceptionFunction, "'exceptionFunction' must not be null");
if (this.statusHandlers.size() == 1 && this.statusHandlers.get(0) == DEFAULT_STATUS_HANDLER) {
this.statusHandlers.clear();
}
this.statusHandlers.add(new StatusHandler(statusPredicate, exceptionFunction));
return this;
@ -476,6 +468,7 @@ class DefaultWebClient implements WebClient {
});
}
private static class StatusHandler {
private final Predicate<HttpStatus> predicate;
@ -484,6 +477,9 @@ class DefaultWebClient implements WebClient {
public StatusHandler(Predicate<HttpStatus> predicate,
Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
Assert.notNull(predicate, "Predicate must not be null");
Assert.notNull(exceptionFunction, "Function must not be null");
this.predicate = predicate;
this.exceptionFunction = exceptionFunction;
}
@ -496,6 +492,6 @@ class DefaultWebClient implements WebClient {
return this.exceptionFunction.apply(response);
}
}
}
}

View File

@ -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.
@ -40,7 +40,7 @@ import org.springframework.web.util.UriBuilderFactory;
* @author Rossen Stoyanchev
* @since 5.0
*/
class DefaultWebClientBuilder implements WebClient.Builder {
final class DefaultWebClientBuilder implements WebClient.Builder {
@Nullable
private String baseUrl;
@ -74,7 +74,7 @@ class DefaultWebClientBuilder implements WebClient.Builder {
}
public DefaultWebClientBuilder(DefaultWebClientBuilder other) {
Assert.notNull(other, "'other' must not be null");
Assert.notNull(other, "DefaultWebClientBuilder must not be null");
this.baseUrl = other.baseUrl;
this.defaultUriVariables = (other.defaultUriVariables != null ?
@ -125,7 +125,6 @@ class DefaultWebClientBuilder implements WebClient.Builder {
@Override
public WebClient.Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer) {
Assert.notNull(headersConsumer, "'headersConsumer' must not be null");
headersConsumer.accept(initHeaders());
return this;
}
@ -145,7 +144,6 @@ class DefaultWebClientBuilder implements WebClient.Builder {
@Override
public WebClient.Builder defaultCookies(Consumer<MultiValueMap<String, String>> cookiesConsumer) {
Assert.notNull(cookiesConsumer, "Cookies consumer must not be null");
cookiesConsumer.accept(initCookies());
return this;
}
@ -172,7 +170,6 @@ class DefaultWebClientBuilder implements WebClient.Builder {
@Override
public WebClient.Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer) {
Assert.notNull(filtersConsumer, "Filters consumer must not be null");
filtersConsumer.accept(initFilters());
return this;
}
@ -214,7 +211,8 @@ class DefaultWebClientBuilder implements WebClient.Builder {
HttpHeaders copy = new HttpHeaders();
copy.putAll(original);
return HttpHeaders.readOnlyHttpHeaders(copy);
} else {
}
else {
return null;
}
}
@ -259,8 +257,6 @@ class DefaultWebClientBuilder implements WebClient.Builder {
@Override
public WebClient.Builder apply(Consumer<WebClient.Builder> builderConsumer) {
Assert.notNull(builderConsumer, "'builderConsumer' must not be null");
builderConsumer.accept(this);
return this;
}

View File

@ -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.
@ -50,7 +50,7 @@ public interface ExchangeFilterFunction {
* {@code after} function
*/
default ExchangeFilterFunction andThen(ExchangeFilterFunction after) {
Assert.notNull(after, "'after' must not be null");
Assert.notNull(after, "ExchangeFilterFunction must not be null");
return (request, next) -> {
ExchangeFunction nextExchange = exchangeRequest -> after.filter(exchangeRequest, next);
return filter(request, nextExchange);
@ -63,7 +63,7 @@ public interface ExchangeFilterFunction {
* @return the filtered exchange function
*/
default ExchangeFunction apply(ExchangeFunction exchange) {
Assert.notNull(exchange, "'exchange' must not be null");
Assert.notNull(exchange, "ExchangeFunction must not be null");
return request -> this.filter(request, exchange);
}
@ -73,10 +73,8 @@ public interface ExchangeFilterFunction {
* @param requestProcessor the request processor
* @return the filter adaptation of the request processor
*/
static ExchangeFilterFunction ofRequestProcessor(Function<ClientRequest,
Mono<ClientRequest>> requestProcessor) {
Assert.notNull(requestProcessor, "'requestProcessor' must not be null");
static ExchangeFilterFunction ofRequestProcessor(Function<ClientRequest, Mono<ClientRequest>> requestProcessor) {
Assert.notNull(requestProcessor, "Function must not be null");
return (request, next) -> requestProcessor.apply(request).flatMap(next::exchange);
}
@ -86,10 +84,8 @@ public interface ExchangeFilterFunction {
* @param responseProcessor the response processor
* @return the filter adaptation of the request processor
*/
static ExchangeFilterFunction ofResponseProcessor(Function<ClientResponse,
Mono<ClientResponse>> responseProcessor) {
Assert.notNull(responseProcessor, "'responseProcessor' must not be null");
static ExchangeFilterFunction ofResponseProcessor(Function<ClientResponse, Mono<ClientResponse>> responseProcessor) {
Assert.notNull(responseProcessor, "Function must not be null");
return (request, next) -> next.exchange(request).flatMap(responseProcessor);
}

View File

@ -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.
@ -63,7 +63,6 @@ public abstract class ExchangeFilterFunctions {
public static ExchangeFilterFunction basicAuthentication(String username, String password) {
Assert.notNull(username, "'username' must not be null");
Assert.notNull(password, "'password' must not be null");
checkIllegalCharacters(username, password);
return basicAuthenticationInternal(r -> Optional.of(new Credentials(username, password)));
}
@ -134,8 +133,8 @@ public abstract class ExchangeFilterFunctions {
public static ExchangeFilterFunction statusError(Predicate<HttpStatus> statusPredicate,
Function<ClientResponse, ? extends Throwable> exceptionFunction) {
Assert.notNull(statusPredicate, "'statusPredicate' must not be null");
Assert.notNull(exceptionFunction, "'exceptionFunction' must not be null");
Assert.notNull(statusPredicate, "Predicate must not be null");
Assert.notNull(exceptionFunction, "Function must not be null");
return ExchangeFilterFunction.ofResponseProcessor(
clientResponse -> {
@ -168,7 +167,6 @@ public abstract class ExchangeFilterFunctions {
public Credentials(String username, String password) {
Assert.notNull(username, "'username' must not be null");
Assert.notNull(password, "'password' must not be null");
this.username = username;
this.password = password;
}

View File

@ -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.
@ -18,8 +18,6 @@ package org.springframework.web.reactive.function.client;
import reactor.core.publisher.Mono;
import org.springframework.util.Assert;
/**
* Represents a function that exchanges a {@linkplain ClientRequest request} for a (delayed)
* {@linkplain ClientResponse}. Can be used as an alternative to {@link WebClient}.
@ -55,7 +53,6 @@ public interface ExchangeFunction {
* @see ExchangeFilterFunction#apply(ExchangeFunction)
*/
default ExchangeFunction filter(ExchangeFilterFunction filter) {
Assert.notNull(filter, "'filter' must not be null");
return filter.apply(this);
}

View File

@ -38,9 +38,9 @@ import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.util.UriBuilder;
import org.springframework.web.util.UriBuilderFactory;
import org.springframework.web.reactive.function.BodyInserters;
/**
* A non-blocking, reactive client for performing HTTP requests with Reactive

View File

@ -55,7 +55,7 @@ public class ClientResponseWrapper implements ClientResponse {
* @param delegate the response to wrap
*/
public ClientResponseWrapper(ClientResponse delegate) {
Assert.notNull(delegate, "'delegate' must not be null");
Assert.notNull(delegate, "Delegate is required");
this.delegate = delegate;
}

View File

@ -64,35 +64,34 @@ class DefaultHandlerStrategiesBuilder implements HandlerStrategies.Builder {
@Override
public HandlerStrategies.Builder codecs(Consumer<ServerCodecConfigurer> consumer) {
Assert.notNull(consumer, "'consumer' must not be null");
consumer.accept(this.codecConfigurer);
return this;
}
@Override
public HandlerStrategies.Builder viewResolver(ViewResolver viewResolver) {
Assert.notNull(viewResolver, "'viewResolver' must not be null");
Assert.notNull(viewResolver, "ViewResolver must not be null");
this.viewResolvers.add(viewResolver);
return this;
}
@Override
public HandlerStrategies.Builder webFilter(WebFilter filter) {
Assert.notNull(filter, "'filter' must not be null");
Assert.notNull(filter, "WebFilter must not be null");
this.webFilters.add(filter);
return this;
}
@Override
public HandlerStrategies.Builder exceptionHandler(WebExceptionHandler exceptionHandler) {
Assert.notNull(exceptionHandler, "'exceptionHandler' must not be null");
Assert.notNull(exceptionHandler, "WebExceptionHandler must not be null");
this.exceptionHandlers.add(exceptionHandler);
return this;
}
@Override
public HandlerStrategies.Builder localeContextResolver(LocaleContextResolver localeContextResolver) {
Assert.notNull(localeContextResolver, "'localeContextResolver' must not be null");
Assert.notNull(localeContextResolver, "LocaleContextResolver must not be null");
this.localeContextResolver = localeContextResolver;
return this;
}

View File

@ -49,7 +49,7 @@ import org.springframework.web.server.ServerWebExchange;
* @author Juergen Hoeller
* @since 5.0
*/
class DefaultRenderingResponseBuilder implements RenderingResponse.Builder {
final class DefaultRenderingResponseBuilder implements RenderingResponse.Builder {
private final String name;
@ -63,6 +63,7 @@ class DefaultRenderingResponseBuilder implements RenderingResponse.Builder {
public DefaultRenderingResponseBuilder(RenderingResponse other) {
Assert.notNull(other, "RenderingResponse must not be null");
this.name = other.name();
this.status = (other instanceof DefaultRenderingResponse ?
((DefaultRenderingResponse) other).statusCode : other.statusCode().value());
@ -71,6 +72,7 @@ class DefaultRenderingResponseBuilder implements RenderingResponse.Builder {
}
public DefaultRenderingResponseBuilder(String name) {
Assert.notNull(name, "Name must not be null");
this.name = name;
}

View File

@ -43,7 +43,6 @@ import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
@ -128,7 +127,6 @@ class DefaultServerRequest implements ServerRequest {
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor, Map<String, Object> hints) {
Assert.notNull(extractor, "'extractor' must not be null");
return extractor.extract(request(),
new BodyExtractor.Context() {
@Override
@ -279,6 +277,7 @@ class DefaultServerRequest implements ServerRequest {
}
}
private final class ServerRequestAdapter implements HttpRequest {
@Override
@ -297,5 +296,4 @@ class DefaultServerRequest implements ServerRequest {
}
}
}

View File

@ -71,13 +71,15 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
public DefaultServerResponseBuilder(ServerResponse other) {
Assert.notNull(other, "ServerResponse must not be null");
this.statusCode = (other instanceof AbstractServerResponse ?
((AbstractServerResponse) other).statusCode : other.statusCode().value());
this.headers.addAll(other.headers());
}
public DefaultServerResponseBuilder(HttpStatus statusCode) {
this.statusCode = statusCode.value();
public DefaultServerResponseBuilder(HttpStatus status) {
Assert.notNull(status, "HttpStatus must not be null");
this.statusCode = status.value();
}
public DefaultServerResponseBuilder(int statusCode) {
@ -406,12 +408,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
public List<HttpMessageWriter<?>> messageWriters() {
return context.messageWriters();
}
@Override
public Optional<ServerHttpRequest> serverRequest() {
return Optional.of(exchange.getRequest());
}
@Override
public Map<String, Object> hints() {
return hints;

View File

@ -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.
@ -55,7 +55,7 @@ public interface HandlerFilterFunction<T extends ServerResponse, R extends Serve
* {@code after} function
*/
default HandlerFilterFunction<T, R> andThen(HandlerFilterFunction<T, T> after) {
Assert.notNull(after, "'after' must not be null");
Assert.notNull(after, "HandlerFilterFunction must not be null");
return (request, next) -> {
HandlerFunction<T> nextHandler = handlerRequest -> after.filter(handlerRequest, next);
return filter(request, nextHandler);
@ -68,35 +68,34 @@ public interface HandlerFilterFunction<T extends ServerResponse, R extends Serve
* @return the filtered handler function
*/
default HandlerFunction<R> apply(HandlerFunction<T> handler) {
Assert.notNull(handler, "'handler' must not be null");
Assert.notNull(handler, "HandlerFunction must not be null");
return request -> this.filter(request, handler);
}
/**
* Adapt the given request processor function to a filter function that only operates on the
* {@code ClientRequest}.
* Adapt the given request processor function to a filter function that only operates
* on the {@code ClientRequest}.
* @param requestProcessor the request processor
* @return the filter adaptation of the request processor
*/
static HandlerFilterFunction<?, ?> ofRequestProcessor(
Function<ServerRequest, Mono<ServerRequest>> requestProcessor) {
Assert.notNull(requestProcessor, "'requestProcessor' must not be null");
Assert.notNull(requestProcessor, "Function must not be null");
return (request, next) -> requestProcessor.apply(request).flatMap(next::handle);
}
/**
* Adapt the given response processor function to a filter function that only operates on the
* {@code ClientResponse}.
* Adapt the given response processor function to a filter function that only operates
* on the {@code ClientResponse}.
* @param responseProcessor the response processor
* @return the filter adaptation of the request processor
*/
static <T extends ServerResponse, R extends ServerResponse> HandlerFilterFunction<T, R> ofResponseProcessor(
Function<T, Mono<R>> responseProcessor) {
Assert.notNull(responseProcessor, "'responseProcessor' must not be null");
Assert.notNull(responseProcessor, "Function must not be null");
return (request, next) -> next.handle(request).flatMap(responseProcessor);
}
}

View File

@ -27,6 +27,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.server.PathContainer;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.util.pattern.PathPattern;
@ -48,6 +49,8 @@ class PathResourceLookupFunction implements Function<ServerRequest, Mono<Resourc
public PathResourceLookupFunction(String pattern, Resource location) {
Assert.hasLength(pattern, "'pattern' must not be empty");
Assert.notNull(location, "'location' must not be null");
this.pattern = PATTERN_PARSER.parse(pattern);
this.location = location;
}

View File

@ -26,7 +26,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
/**
@ -57,7 +56,6 @@ public interface RenderingResponse extends ServerResponse {
* @return the created builder
*/
static Builder from(RenderingResponse other) {
Assert.notNull(other, "Other RenderingResponse must not be null");
return new DefaultRenderingResponseBuilder(other);
}
@ -67,7 +65,6 @@ public interface RenderingResponse extends ServerResponse {
* @return the created builder
*/
static Builder create(String name) {
Assert.notNull(name, "'name' must not be null");
return new DefaultRenderingResponseBuilder(name);
}

View File

@ -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.
@ -18,8 +18,6 @@ package org.springframework.web.reactive.function.server;
import java.util.Optional;
import org.springframework.util.Assert;
/**
* Represents a function that evaluates on a given {@link ServerRequest}.
* Instances of this function that evaluate on common request properties
@ -49,7 +47,6 @@ public interface RequestPredicate {
* @return a predicate composed of this predicate AND the {@code other} predicate
*/
default RequestPredicate and(RequestPredicate other) {
Assert.notNull(other, "'other' must not be null");
return new RequestPredicates.AndRequestPredicate(this, other);
}
@ -69,7 +66,6 @@ public interface RequestPredicate {
* @return a predicate composed of this predicate OR the {@code other} predicate
*/
default RequestPredicate or(RequestPredicate other) {
Assert.notNull(other, "'other' must not be null");
return new RequestPredicates.OrRequestPredicate(this, other);
}

View File

@ -316,7 +316,7 @@ public abstract class RequestPredicates {
private final HttpMethod httpMethod;
public HttpMethodPredicate(HttpMethod httpMethod) {
Assert.notNull(httpMethod, "'httpMethod' must not be null");
Assert.notNull(httpMethod, "HttpMethod must not be null");
this.httpMethod = httpMethod;
}
@ -388,7 +388,7 @@ public abstract class RequestPredicates {
private final Predicate<ServerRequest.Headers> headersPredicate;
public HeadersPredicate(Predicate<ServerRequest.Headers> headersPredicate) {
Assert.notNull(headersPredicate, "'headersPredicate' must not be null");
Assert.notNull(headersPredicate, "Predicate must not be null");
this.headersPredicate = headersPredicate;
}
@ -410,13 +410,15 @@ public abstract class RequestPredicates {
private final RequestPredicate right;
public AndRequestPredicate(RequestPredicate left, RequestPredicate right) {
Assert.notNull(left, "Left RequestPredicate must not be null");
Assert.notNull(right, "Right RequestPredicate must not be null");
this.left = left;
this.right = right;
}
@Override
public boolean test(ServerRequest t) {
return this.left.test(t) && this.right.test(t);
return (this.left.test(t) && this.right.test(t));
}
@Override
@ -437,12 +439,15 @@ public abstract class RequestPredicates {
private final RequestPredicate right;
public OrRequestPredicate(RequestPredicate left, RequestPredicate right) {
Assert.notNull(left, "Left RequestPredicate must not be null");
Assert.notNull(right, "Right RequestPredicate must not be null");
this.left = left;
this.right = right;
}
@Override
public boolean test(ServerRequest t) {
return this.left.test(t) || this.right.test(t);
return (this.left.test(t) || this.right.test(t));
}
@Override

View File

@ -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.
@ -83,11 +83,8 @@ public abstract class RouterFunctions {
* {@code predicate} evaluates to {@code true}
* @see RequestPredicates
*/
public static <T extends ServerResponse> RouterFunction<T> route(RequestPredicate predicate,
HandlerFunction<T> handlerFunction) {
Assert.notNull(predicate, "'predicate' must not be null");
Assert.notNull(handlerFunction, "'handlerFunction' must not be null");
public static <T extends ServerResponse> RouterFunction<T> route(
RequestPredicate predicate, HandlerFunction<T> handlerFunction) {
return new DefaultRouterFunction<>(predicate, handlerFunction);
}
@ -115,11 +112,8 @@ public abstract class RouterFunctions {
* {@code predicate} evaluates to {@code true}
* @see RequestPredicates
*/
public static <T extends ServerResponse> RouterFunction<T> nest(RequestPredicate predicate,
RouterFunction<T> routerFunction) {
Assert.notNull(predicate, "'predicate' must not be null");
Assert.notNull(routerFunction, "'routerFunction' must not be null");
public static <T extends ServerResponse> RouterFunction<T> nest(
RequestPredicate predicate, RouterFunction<T> routerFunction) {
return new DefaultNestedRouterFunction<>(predicate, routerFunction);
}
@ -136,8 +130,6 @@ public abstract class RouterFunctions {
* @return a router function that routes to resources
*/
public static RouterFunction<ServerResponse> resources(String pattern, Resource location) {
Assert.hasLength(pattern, "'pattern' must not be empty");
Assert.notNull(location, "'location' must not be null");
return resources(new PathResourceLookupFunction(pattern, location));
}
@ -149,7 +141,6 @@ public abstract class RouterFunctions {
* @return a router function that routes to resources
*/
public static RouterFunction<ServerResponse> resources(Function<ServerRequest, Mono<Resource>> lookupFunction) {
Assert.notNull(lookupFunction, "'lookupFunction' must not be null");
return new ResourcesRouterFunction(lookupFunction);
}
@ -192,9 +183,6 @@ public abstract class RouterFunctions {
* @return an http handler that handles HTTP request using the given router function
*/
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, HandlerStrategies strategies) {
Assert.notNull(routerFunction, "RouterFunction must not be null");
Assert.notNull(strategies, "HandlerStrategies must not be null");
WebHandler webHandler = toWebHandler(routerFunction, strategies);
return WebHttpHandlerBuilder.webHandler(webHandler)
.filters(filters -> filters.addAll(strategies.webFilters()))
@ -396,8 +384,9 @@ public abstract class RouterFunctions {
private final HandlerFunction<T> handlerFunction;
public DefaultRouterFunction(RequestPredicate predicate,
HandlerFunction<T> handlerFunction) {
public DefaultRouterFunction(RequestPredicate predicate, HandlerFunction<T> handlerFunction) {
Assert.notNull(predicate, "Predicate must not be null");
Assert.notNull(handlerFunction, "HandlerFunction must not be null");
this.predicate = predicate;
this.handlerFunction = handlerFunction;
}
@ -406,8 +395,7 @@ public abstract class RouterFunctions {
public Mono<HandlerFunction<T>> route(ServerRequest request) {
if (this.predicate.test(request)) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Predicate \"%s\" matches against \"%s\"",
this.predicate, request));
logger.debug(String.format("Predicate \"%s\" matches against \"%s\"", this.predicate, request));
}
return Mono.just(this.handlerFunction);
}
@ -430,8 +418,9 @@ public abstract class RouterFunctions {
private final RouterFunction<T> routerFunction;
public DefaultNestedRouterFunction(RequestPredicate predicate,
RouterFunction<T> routerFunction) {
public DefaultNestedRouterFunction(RequestPredicate predicate, RouterFunction<T> routerFunction) {
Assert.notNull(predicate, "Predicate must not be null");
Assert.notNull(routerFunction, "RouterFunction must not be null");
this.predicate = predicate;
this.routerFunction = routerFunction;
}
@ -466,6 +455,7 @@ public abstract class RouterFunctions {
private final Function<ServerRequest, Mono<Resource>> lookupFunction;
public ResourcesRouterFunction(Function<ServerRequest, Mono<Resource>> lookupFunction) {
Assert.notNull(lookupFunction, "Function must not be null");
this.lookupFunction = lookupFunction;
}

View File

@ -38,7 +38,6 @@ import org.springframework.http.ResponseCookie;
import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.codec.json.Jackson2CodecSupport;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.BodyInserters;
@ -91,7 +90,6 @@ public interface ServerResponse {
* @return the created builder
*/
static BodyBuilder from(ServerResponse other) {
Assert.notNull(other, "Other ServerResponse must not be null");
return new DefaultServerResponseBuilder(other);
}
@ -101,7 +99,6 @@ public interface ServerResponse {
* @return the created builder
*/
static BodyBuilder status(HttpStatus status) {
Assert.notNull(status, "HttpStatus must not be null");
return new DefaultServerResponseBuilder(status);
}

View File

@ -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.
@ -26,7 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
@ -87,7 +86,6 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
* <p>By default this is set to the {@link ServerCodecConfigurer}'s defaults.
*/
public void setMessageReaders(List<HttpMessageReader<?>> messageReaders) {
Assert.notNull(messageReaders, "'messageReaders' must not be null");
this.messageReaders = messageReaders;
}

View File

@ -201,6 +201,7 @@ public class ServerRequestWrapper implements ServerRequest {
return this.delegate.multipartData();
}
/**
* Implementation of the {@code Headers} interface that can be subclassed
* to adapt the headers in a
@ -211,17 +212,15 @@ public class ServerRequestWrapper implements ServerRequest {
private final Headers headers;
/**
* Create a new {@code HeadersWrapper} that wraps the given request.
* @param headers the headers to wrap
*/
public HeadersWrapper(Headers headers) {
Assert.notNull(headers, "'headers' must not be null");
Assert.notNull(headers, "Headers must not be null");
this.headers = headers;
}
@Override
public List<MediaType> accept() {
return this.headers.accept();

View File

@ -53,7 +53,6 @@ public class ServerResponseResultHandler implements HandlerResultHandler, Initia
* <p>By default this is set to {@link ServerCodecConfigurer}'s default writers.
*/
public void setMessageWriters(List<HttpMessageWriter<?>> configurer) {
Assert.notNull(messageWriters, "'messageWriters' must not be null");
this.messageWriters = configurer;
}
@ -104,4 +103,5 @@ public class ServerResponseResultHandler implements HandlerResultHandler, Initia
}
});
}
}