Upgrade to Spring Framework 6 and Jakarta EE 9
Closes gh-750 Closes gh-748
This commit is contained in:
@@ -34,10 +34,10 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ReactiveHttpInputMessage;
|
||||
import org.springframework.http.codec.FormHttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.multipart.DefaultPartHttpMessageReader;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
import org.springframework.http.codec.multipart.MultipartHttpMessageReader;
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader;
|
||||
import org.springframework.restdocs.operation.OperationRequest;
|
||||
import org.springframework.restdocs.operation.OperationRequestFactory;
|
||||
import org.springframework.restdocs.operation.OperationRequestPart;
|
||||
@@ -48,7 +48,6 @@ import org.springframework.restdocs.operation.RequestConverter;
|
||||
import org.springframework.restdocs.operation.RequestCookie;
|
||||
import org.springframework.test.web.reactive.server.ExchangeResult;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@@ -60,8 +59,6 @@ import org.springframework.util.MultiValueMap;
|
||||
*/
|
||||
class WebTestClientRequestConverter implements RequestConverter<ExchangeResult> {
|
||||
|
||||
private static final String DEFAULT_PART_HTTP_MESSAGE_READER = "org.springframework.http.codec.multipart.DefaultPartHttpMessageReader";
|
||||
|
||||
private static final ResolvableType FORM_DATA_TYPE = ResolvableType.forClassWithGenerics(MultiValueMap.class,
|
||||
String.class, String.class);
|
||||
|
||||
@@ -94,10 +91,7 @@ class WebTestClientRequestConverter implements RequestConverter<ExchangeResult>
|
||||
}
|
||||
|
||||
private List<OperationRequestPart> extractRequestParts(ExchangeResult result) {
|
||||
HttpMessageReader<Part> partHttpMessageReader = findPartHttpMessageReader();
|
||||
if (partHttpMessageReader == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
HttpMessageReader<Part> partHttpMessageReader = new DefaultPartHttpMessageReader();
|
||||
return new MultipartHttpMessageReader(partHttpMessageReader)
|
||||
.readMono(ResolvableType.forClass(Part.class), new ExchangeResultReactiveHttpInputMessage(result),
|
||||
Collections.emptyMap())
|
||||
@@ -105,25 +99,6 @@ class WebTestClientRequestConverter implements RequestConverter<ExchangeResult>
|
||||
.flatMap((parts) -> parts.stream().map(this::createOperationRequestPart)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private HttpMessageReader<Part> findPartHttpMessageReader() {
|
||||
if (ClassUtils.isPresent(DEFAULT_PART_HTTP_MESSAGE_READER, getClass().getClassLoader())) {
|
||||
try {
|
||||
return (HttpMessageReader<Part>) Class
|
||||
.forName(DEFAULT_PART_HTTP_MESSAGE_READER, true, getClass().getClassLoader())
|
||||
.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
if (ClassUtils.isPresent("org.synchronoss.cloud.nio.multipart.NioMultipartParserListener",
|
||||
getClass().getClassLoader())) {
|
||||
return new SynchronossPartHttpMessageReader();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private OperationRequestPart createOperationRequestPart(Part part) {
|
||||
ByteArrayOutputStream content = readPartBodyContent(part);
|
||||
return new OperationRequestPartFactory().create(part.name(),
|
||||
|
||||
@@ -94,7 +94,7 @@ public class WebTestClientRestDocumentationConfigurer extends
|
||||
|
||||
private ClientRequest applyUriDefaults(ClientRequest request) {
|
||||
URI requestUri = request.url();
|
||||
if (!StringUtils.isEmpty(requestUri.getHost())) {
|
||||
if (StringUtils.hasLength(requestUri.getHost())) {
|
||||
return request;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class WebTestClientResponseConverterTests {
|
||||
public void basicResponse() {
|
||||
ExchangeResult result = WebTestClient
|
||||
.bindToRouterFunction(
|
||||
RouterFunctions.route(GET("/foo"), (req) -> ServerResponse.ok().syncBody("Hello, World!")))
|
||||
RouterFunctions.route(GET("/foo"), (req) -> ServerResponse.ok().bodyValue("Hello, World!")))
|
||||
.configureClient().baseUrl("http://localhost").build().get().uri("/foo").exchange().expectBody()
|
||||
.returnResult();
|
||||
OperationResponse response = this.converter.convert(result);
|
||||
|
||||
@@ -68,7 +68,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.requestP
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParts;
|
||||
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
|
||||
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
||||
|
||||
/**
|
||||
* Integration tests for using Spring REST Docs with Spring Framework's WebTestClient.
|
||||
@@ -86,9 +86,9 @@ public class WebTestClientRestDocumentationIntegrationTests {
|
||||
public void setUp() {
|
||||
RouterFunction<ServerResponse> route = RouterFunctions
|
||||
.route(RequestPredicates.GET("/"),
|
||||
(request) -> ServerResponse.status(HttpStatus.OK).body(fromObject(new Person("Jane", "Doe"))))
|
||||
(request) -> ServerResponse.status(HttpStatus.OK).body(fromValue(new Person("Jane", "Doe"))))
|
||||
.andRoute(RequestPredicates.GET("/{foo}/{bar}"),
|
||||
(request) -> ServerResponse.status(HttpStatus.OK).body(fromObject(new Person("Jane", "Doe"))))
|
||||
(request) -> ServerResponse.status(HttpStatus.OK).body(fromValue(new Person("Jane", "Doe"))))
|
||||
.andRoute(RequestPredicates.POST("/upload"),
|
||||
(request) -> request.body(BodyExtractors.toMultipartData())
|
||||
.map((parts) -> ServerResponse.status(HttpStatus.OK).build().block()))
|
||||
|
||||
Reference in New Issue
Block a user