Merge branch '5.2.x'

# Conflicts:
#	build.gradle
#	spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java
#	spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java
#	spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java
This commit is contained in:
Juergen Hoeller
2020-06-06 18:52:51 +02:00
8 changed files with 43 additions and 43 deletions

View File

@@ -64,6 +64,8 @@ import org.springframework.web.util.UriTemplateHandler;
* @param <T> the body type
* @see #getMethod()
* @see #getUrl()
* @see org.springframework.web.client.RestOperations#exchange(RequestEntity, Class)
* @see ResponseEntity
*/
public class RequestEntity<T> extends HttpEntity<T> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@@ -70,6 +70,10 @@ import org.springframework.util.ObjectUtils;
* @since 3.0.2
* @param <T> the body type
* @see #getStatusCode()
* @see org.springframework.web.client.RestOperations#getForEntity(String, Class, Object...)
* @see org.springframework.web.client.RestOperations#getForEntity(String, Class, java.util.Map)
* @see org.springframework.web.client.RestOperations#getForEntity(URI, Class)
* @see RequestEntity
*/
public class ResponseEntity<T> extends HttpEntity<T> {
@@ -217,19 +221,6 @@ public class ResponseEntity<T> extends HttpEntity<T> {
return new DefaultBuilder(status);
}
/**
* A shortcut for creating a {@code ResponseEntity} with the given body
* and the {@linkplain HttpStatus#OK OK} status, or an empty body and a
* {@linkplain HttpStatus#NOT_FOUND NOT FOUND} status in case of an
* {@linkplain Optional#empty()} parameter.
* @return the created {@code ResponseEntity}
* @since 5.1
*/
public static <T> ResponseEntity<T> of(Optional<T> body) {
Assert.notNull(body, "Body must not be null");
return body.map(ResponseEntity::ok).orElse(notFound().build());
}
/**
* Create a builder with the status set to {@linkplain HttpStatus#OK OK}.
* @return the created builder
@@ -246,8 +237,20 @@ public class ResponseEntity<T> extends HttpEntity<T> {
* @since 4.1
*/
public static <T> ResponseEntity<T> ok(T body) {
BodyBuilder builder = ok();
return builder.body(body);
return ok().body(body);
}
/**
* A shortcut for creating a {@code ResponseEntity} with the given body
* and the {@linkplain HttpStatus#OK OK} status, or an empty body and a
* {@linkplain HttpStatus#NOT_FOUND NOT FOUND} status in case of an
* {@linkplain Optional#empty()} parameter.
* @return the created {@code ResponseEntity}
* @since 5.1
*/
public static <T> ResponseEntity<T> of(Optional<T> body) {
Assert.notNull(body, "Body must not be null");
return body.map(ResponseEntity::ok).orElseGet(() -> notFound().build());
}
/**
@@ -258,8 +261,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
* @since 4.1
*/
public static BodyBuilder created(URI location) {
BodyBuilder builder = status(HttpStatus.CREATED);
return builder.location(location);
return status(HttpStatus.CREATED).location(location);
}
/**

View File

@@ -76,15 +76,15 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
private MockServerHttpRequest(String httpMethod,
URI uri, @Nullable String contextPath, HttpHeaders headers, MultiValueMap<String, HttpCookie> cookies,
@Nullable InetSocketAddress remoteAddress, @Nullable InetSocketAddress localAddress,
@Nullable InetSocketAddress localAddress, @Nullable InetSocketAddress remoteAddress,
@Nullable SslInfo sslInfo, Publisher<? extends DataBuffer> body) {
super(uri, contextPath, headers);
Assert.isTrue(StringUtils.hasText(httpMethod), "HTTP method is required.");
this.httpMethod = httpMethod;
this.cookies = cookies;
this.remoteAddress = remoteAddress;
this.localAddress = localAddress;
this.remoteAddress = remoteAddress;
this.sslInfo = sslInfo;
this.body = Flux.from(body);
}
@@ -382,9 +382,9 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
* @see BodyBuilder#body(String)
*/
MockServerHttpRequest build();
}
/**
* A builder that adds a body to the request.
*/
@@ -423,7 +423,6 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
* @return the built request entity
*/
MockServerHttpRequest body(String body);
}
@@ -597,7 +596,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
public MockServerHttpRequest body(Publisher<? extends DataBuffer> body) {
applyCookiesIfNecessary();
return new MockServerHttpRequest(this.methodValue, getUrlToUse(), this.contextPath,
this.headers, this.cookies, this.remoteAddress, this.localAddress, this.sslInfo, body);
this.headers, this.cookies, this.localAddress, this.remoteAddress, this.sslInfo, body);
}
private void applyCookiesIfNecessary() {
@@ -610,11 +609,9 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
private URI getUrlToUse() {
MultiValueMap<String, String> params =
this.queryParamsBuilder.buildAndExpand().encode().getQueryParams();
if (!params.isEmpty()) {
return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri();
}
return this.url;
}
}