Move ServerWebExchange Kotlin extensions

This commit moves ServerWebExchange Kotlin extensions
where they belong: in the spring-web module with the
org.springframework.web.server package, like
ServerWebExchange itself.

The extensions in the wrong location are deprecated
and semi-automated migration to the new variants is
made possible via @Deprecated + ReplaceWith(...).

Some tests have been added as well.

Closes gh-31046
This commit is contained in:
Sébastien Deleuze
2023-08-15 18:01:32 +02:00
parent 57f675c537
commit 02d003127f
3 changed files with 179 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
@@ -31,6 +31,10 @@ import java.security.Principal
* @author Sebastien Deleuze
* @since 5.2
*/
@Deprecated(
message = "Use the variant with the org.springframework.web.server package instead.",
ReplaceWith("awaitFormData()", "org.springframework.web.server.awaitFormData"),
)
suspend fun ServerWebExchange.awaitFormData(): MultiValueMap<String, String> =
this.formData.awaitSingle()
@@ -40,6 +44,10 @@ suspend fun ServerWebExchange.awaitFormData(): MultiValueMap<String, String> =
* @author Sebastien Deleuze
* @since 5.2
*/
@Deprecated(
message = "Use the variant with the org.springframework.web.server package instead.",
ReplaceWith("awaitMultipartData()", "org.springframework.web.server.awaitMultipartData"),
)
suspend fun ServerWebExchange.awaitMultipartData(): MultiValueMap<String, Part> =
this.multipartData.awaitSingle()
@@ -49,6 +57,10 @@ suspend fun ServerWebExchange.awaitMultipartData(): MultiValueMap<String, Part>
* @author Sebastien Deleuze
* @since 5.2
*/
@Deprecated(
message = "Use the variant with the org.springframework.web.server package instead.",
ReplaceWith("awaitPrincipal<T>()", "org.springframework.web.server.awaitPrincipal"),
)
suspend fun <T : Principal> ServerWebExchange.awaitPrincipal(): T =
this.getPrincipal<T>().awaitSingle()
@@ -58,6 +70,10 @@ suspend fun <T : Principal> ServerWebExchange.awaitPrincipal(): T =
* @author Sebastien Deleuze
* @since 5.2
*/
@Deprecated(
message = "Use the variant with the org.springframework.web.server package instead.",
ReplaceWith("awaitSession()", "org.springframework.web.server.awaitSession"),
)
suspend fun ServerWebExchange.awaitSession(): WebSession =
this.session.awaitSingle()
@@ -67,5 +83,9 @@ suspend fun ServerWebExchange.awaitSession(): WebSession =
* @author Sebastien Deleuze
* @since 5.2
*/
@Deprecated(
message = "Use the variant with the org.springframework.web.server package instead.",
ReplaceWith("principal(supplier)", "org.springframework.web.server.principal"),
)
fun ServerWebExchange.Builder.principal(supplier: suspend () -> Principal): ServerWebExchange.Builder
= principal(mono(Dispatchers.Unconfined) { supplier.invoke() })