Browse Source

Remove deprecated WebFlux APIs

See gh-33809
pull/34281/head
rstoyanchev 11 months ago
parent
commit
2ed281f6a8
  1. 8
      spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java
  2. 23
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java
  3. 14
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java
  4. 17
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java
  5. 24
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java
  6. 12
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java
  7. 89
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java
  8. 71
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java
  9. 11
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientResponseException.java
  10. 8
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java
  11. 8
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java
  12. 20
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java
  13. 20
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java
  14. 10
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java
  15. 15
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java
  16. 38
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java
  17. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolver.java
  18. 10
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java
  19. 24
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java
  20. 63
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java
  21. 60
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNettyRequestUpgradeStrategy.java
  22. 18
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt
  23. 14
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensions.kt
  24. 91
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/server/ServerWebExchangeExtensions.kt
  25. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java
  26. 31
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java
  27. 40
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctionsTests.java
  28. 2
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java
  29. 12
      spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt

8
spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -127,12 +127,6 @@ public final class MockServerRequest implements ServerRequest {
return this.method; return this.method;
} }
@Override
@Deprecated
public String methodName() {
return this.method.name();
}
@Override @Override
public URI uri() { public URI uri() {
return this.uri; return this.uri;

23
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -129,27 +129,6 @@ public abstract class BodyInserters {
writeWithMessageWriters(message, context, Mono.just(body), ResolvableType.forType(bodyType), null); writeWithMessageWriters(message, context, Mono.just(body), ResolvableType.forType(bodyType), null);
} }
/**
* Inserter to write the given object.
* <p>Alternatively, consider using the {@code bodyValue(Object)} shortcuts on
* {@link org.springframework.web.reactive.function.client.WebClient WebClient} and
* {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}.
* @param body the body to write to the response
* @param <T> the type of the body
* @return the inserter to write a single object
* @throws IllegalArgumentException if {@code body} is a {@link Publisher} or an
* instance of a type supported by {@link ReactiveAdapterRegistry#getSharedInstance()},
* for which {@link #fromPublisher(Publisher, Class)} or
* {@link #fromProducer(Object, Class)} should be used.
* @see #fromPublisher(Publisher, Class)
* @see #fromProducer(Object, Class)
* @deprecated As of Spring Framework 5.2, in favor of {@link #fromValue(Object)}
*/
@Deprecated
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromObject(T body) {
return fromValue(body);
}
/** /**
* Inserter to write the given producer of value(s) which must be a {@link Publisher} * Inserter to write the given producer of value(s) which must be a {@link Publisher}
* or another producer adaptable to a {@code Publisher} via * or another producer adaptable to a {@code Publisher} via

14
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -133,18 +133,6 @@ public interface ClientRequest {
return new DefaultClientRequestBuilder(other); return new DefaultClientRequestBuilder(other);
} }
/**
* Create a builder with the given HTTP method and url.
* @param method the HTTP method (GET, POST, etc)
* @param url the url (as a URI instance)
* @return the created builder
* @deprecated in favor of {@link #create(HttpMethod, URI)}
*/
@Deprecated
static Builder method(HttpMethod method, URI url) {
return new DefaultClientRequestBuilder(method, url);
}
/** /**
* Create a request builder with the given HTTP method and url. * Create a request builder with the given HTTP method and url.
* @param method the HTTP method (GET, POST, etc) * @param method the HTTP method (GET, POST, etc)

17
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -211,21 +211,6 @@ public interface ClientResponse {
// Static builder methods // Static builder methods
/**
* Create a builder with the status, headers, and cookies of the given response.
* <p><strong>Note:</strong> Note that the body in the returned builder is
* {@link Flux#empty()} by default. To carry over the one from the original
* response, use {@code otherResponse.bodyToFlux(DataBuffer.class)} or
* simply use the instance based {@link #mutate()} method.
* @param other the response to copy the status, headers, and cookies from
* @return the created builder
* @deprecated as of 5.3 in favor of the instance based {@link #mutate()}.
*/
@Deprecated
static Builder from(ClientResponse other) {
return new DefaultClientResponseBuilder(other, false);
}
/** /**
* Create a response builder with the given status code and using default strategies for * Create a response builder with the given status code and using default strategies for
* reading the body. * reading the body.

24
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java

@ -39,7 +39,6 @@ import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.core.publisher.SignalType; import reactor.core.publisher.SignalType;
import reactor.util.context.Context;
import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -207,8 +206,6 @@ final class DefaultWebClient implements WebClient {
private final Map<String, Object> attributes = new LinkedHashMap<>(4); private final Map<String, Object> attributes = new LinkedHashMap<>(4);
private @Nullable Function<Context, Context> contextModifier;
private @Nullable Consumer<ClientHttpRequest> httpRequestConsumer; private @Nullable Consumer<ClientHttpRequest> httpRequestConsumer;
DefaultRequestBodyUriSpec(HttpMethod httpMethod) { DefaultRequestBodyUriSpec(HttpMethod httpMethod) {
@ -335,14 +332,6 @@ final class DefaultWebClient implements WebClient {
return this; return this;
} }
@SuppressWarnings("deprecation")
@Override
public RequestBodySpec context(Function<Context, Context> contextModifier) {
this.contextModifier = (this.contextModifier != null ?
this.contextModifier.andThen(contextModifier) : contextModifier);
return this;
}
@Override @Override
public RequestBodySpec httpRequest(Consumer<ClientHttpRequest> requestConsumer) { public RequestBodySpec httpRequest(Consumer<ClientHttpRequest> requestConsumer) {
this.httpRequestConsumer = (this.httpRequestConsumer != null ? this.httpRequestConsumer = (this.httpRequestConsumer != null ?
@ -393,12 +382,6 @@ final class DefaultWebClient implements WebClient {
return this; return this;
} }
@Override
@Deprecated
public RequestHeadersSpec<?> syncBody(Object body) {
return bodyValue(body);
}
@Override @Override
public ResponseSpec retrieve() { public ResponseSpec retrieve() {
return new DefaultResponseSpec( return new DefaultResponseSpec(
@ -434,9 +417,7 @@ final class DefaultWebClient implements WebClient {
}); });
} }
@SuppressWarnings("deprecation") private Mono<ClientResponse> exchange() {
@Override
public Mono<ClientResponse> exchange() {
ClientRequest.Builder requestBuilder = initRequestBuilder(); ClientRequest.Builder requestBuilder = initRequestBuilder();
ClientRequestObservationContext observationContext = new ClientRequestObservationContext(requestBuilder); ClientRequestObservationContext observationContext = new ClientRequestObservationContext(requestBuilder);
return Mono.deferContextual(contextView -> { return Mono.deferContextual(contextView -> {
@ -459,9 +440,6 @@ final class DefaultWebClient implements WebClient {
WebClientUtils.getRequestDescription(request.method(), request.url()) + WebClientUtils.getRequestDescription(request.method(), request.url()) +
" [DefaultWebClient]") " [DefaultWebClient]")
.switchIfEmpty(NO_HTTP_CLIENT_RESPONSE_ERROR); .switchIfEmpty(NO_HTTP_CLIENT_RESPONSE_ERROR);
if (this.contextModifier != null) {
responseMono = responseMono.contextWrite(this.contextModifier);
}
final AtomicBoolean responseReceived = new AtomicBoolean(); final AtomicBoolean responseReceived = new AtomicBoolean();
return responseMono return responseMono
.doOnNext(response -> responseReceived.set(true)) .doOnNext(response -> responseReceived.set(true))

12
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -251,16 +251,6 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
return this; return this;
} }
@Override
@Deprecated
public WebClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer) {
if (this.strategiesConfigurers == null) {
this.strategiesConfigurers = new ArrayList<>(4);
}
this.strategiesConfigurers.add(configurer);
return this;
}
@Override @Override
public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) { public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) {
this.exchangeFunction = exchangeFunction; this.exchangeFunction = exchangeFunction;

89
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,12 +17,9 @@
package org.springframework.web.reactive.function.client; package org.springframework.web.reactive.function.client;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.DataBufferUtils;
@ -41,13 +38,6 @@ import org.springframework.util.Assert;
*/ */
public abstract class ExchangeFilterFunctions { public abstract class ExchangeFilterFunctions {
/**
* Name of the request attribute with {@link Credentials} for {@link #basicAuthentication()}.
*/
private static final String BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE =
ExchangeFilterFunctions.class.getName() + ".basicAuthenticationCredentials";
/** /**
* Consume up to the specified number of bytes from the response body and * Consume up to the specified number of bytes from the response body and
* cancel if any more data arrives. * cancel if any more data arrives.
@ -100,81 +90,4 @@ public abstract class ExchangeFilterFunctions {
.build()); .build());
} }
/**
* Variant of {@link #basicAuthentication(String, String)} that looks up
* the {@link Credentials Credentials} in a
* {@link #BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE request attribute}.
* @return the filter to use
* @see Credentials
* @deprecated as of Spring 5.1 in favor of using
* {@link HttpHeaders#setBasicAuth(String, String)} while building the request.
*/
@Deprecated
public static ExchangeFilterFunction basicAuthentication() {
return (request, next) -> {
Object attr = request.attributes().get(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE);
if (attr instanceof Credentials cred) {
return next.exchange(ClientRequest.from(request)
.headers(headers -> headers.setBasicAuth(cred.username, cred.password))
.build());
}
else {
return next.exchange(request);
}
};
}
/**
* Stores username and password for HTTP basic authentication.
* @deprecated as of Spring 5.1 in favor of using
* {@link HttpHeaders#setBasicAuth(String, String)} while building the request.
*/
@Deprecated
public static final class Credentials {
private final String username;
private final String password;
/**
* Create a new {@code Credentials} instance with the given username and password.
* @param username the username
* @param password the password
*/
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;
}
/**
* Return a {@literal Consumer} that stores the given username and password
* as a request attribute of type {@code Credentials} that is in turn
* used by {@link ExchangeFilterFunctions#basicAuthentication()}.
* @param username the username
* @param password the password
* @return a consumer that can be passed into
* {@linkplain ClientRequest.Builder#attributes(java.util.function.Consumer)}
* @see ClientRequest.Builder#attributes(java.util.function.Consumer)
* @see #BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE
*/
public static Consumer<Map<String, Object>> basicAuthenticationCredentials(String username, String password) {
Credentials credentials = new Credentials(username, password);
return (map -> map.put(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE, credentials));
}
@Override
public boolean equals(@Nullable Object other) {
return (this == other ||(other instanceof Credentials that &&
this.username.equals(that.username) && this.password.equals(that.password)));
}
@Override
public int hashCode() {
return this.username.hashCode() * 31 + this.password.hashCode();
}
}
} }

71
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,7 +32,6 @@ import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.util.context.Context;
import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.ReactiveAdapterRegistry;
@ -320,16 +319,6 @@ public interface WebClient {
*/ */
Builder exchangeStrategies(ExchangeStrategies strategies); Builder exchangeStrategies(ExchangeStrategies strategies);
/**
* Customize the strategies configured via
* {@link #exchangeStrategies(ExchangeStrategies)}. This method is
* designed for use in scenarios where multiple parties wish to update
* the {@code ExchangeStrategies}.
* @deprecated as of 5.1.13 in favor of {@link #codecs(Consumer)}
*/
@Deprecated
Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer);
/** /**
* Provide an {@link ExchangeFunction} pre-configured with * Provide an {@link ExchangeFunction} pre-configured with
* {@link ClientHttpConnector} and {@link ExchangeStrategies}. * {@link ClientHttpConnector} and {@link ExchangeStrategies}.
@ -502,17 +491,6 @@ public interface WebClient {
*/ */
S attributes(Consumer<Map<String, Object>> attributesConsumer); S attributes(Consumer<Map<String, Object>> attributesConsumer);
/**
* Provide a function to populate the Reactor {@code Context}.
* @param contextModifier the function to modify the context with
* @since 5.3.1
* @deprecated in 5.3.2 to be removed soon after; this method cannot
* provide context to downstream (nested or subsequent) requests and is
* of limited value.
*/
@Deprecated
S context(Function<Context, Context> contextModifier);
/** /**
* Callback for access to the {@link ClientHttpRequest} that in turn * Callback for access to the {@link ClientHttpRequest} that in turn
* provides access to the native request of the underlying HTTP library. * provides access to the native request of the underlying HTTP library.
@ -606,44 +584,6 @@ public interface WebClient {
* @since 5.3 * @since 5.3
*/ */
<V> Flux<V> exchangeToFlux(Function<ClientResponse, ? extends Flux<V>> responseHandler); <V> Flux<V> exchangeToFlux(Function<ClientResponse, ? extends Flux<V>> responseHandler);
/**
* Perform the HTTP request and return a {@link ClientResponse} with the
* response status and headers. You can then use methods of the response
* to consume the body:
* <p><pre>
* Mono&lt;Person&gt; mono = client.get()
* .uri("/persons/1")
* .accept(MediaType.APPLICATION_JSON)
* .exchange()
* .flatMap(response -&gt; response.bodyToMono(Person.class));
*
* Flux&lt;Person&gt; flux = client.get()
* .uri("/persons")
* .accept(MediaType.APPLICATION_STREAM_JSON)
* .exchange()
* .flatMapMany(response -&gt; response.bodyToFlux(Person.class));
* </pre>
* <p><strong>NOTE:</strong> Unlike {@link #retrieve()}, when using
* {@code exchange()}, it is the responsibility of the application to
* consume any response content regardless of the scenario (success,
* error, unexpected data, etc). Not doing so can cause a memory leak.
* See {@link ClientResponse} for a list of all the available options
* for consuming the body. Generally prefer using {@link #retrieve()}
* unless you have a good reason to use {@code exchange()} which does
* allow to check the response status and headers before deciding how or
* if to consume the response.
* @return a {@code Mono} for the response
* @see #retrieve()
* @deprecated since 5.3 due to the possibility to leak memory and/or
* connections; please, use {@link #exchangeToMono(Function)},
* {@link #exchangeToFlux(Function)}; consider also using
* {@link #retrieve()} which provides access to the response status
* and headers via {@link ResponseEntity} along with error status
* handling.
*/
@Deprecated
Mono<ClientResponse> exchange();
} }
@ -789,15 +729,6 @@ public interface WebClient {
* @see org.springframework.web.reactive.function.BodyInserters * @see org.springframework.web.reactive.function.BodyInserters
*/ */
RequestHeadersSpec<?> body(BodyInserter<?, ? super ClientHttpRequest> inserter); RequestHeadersSpec<?> body(BodyInserter<?, ? super ClientHttpRequest> inserter);
/**
* Shortcut for {@link #body(BodyInserter)} with a
* {@linkplain BodyInserters#fromValue value inserter}.
* As of 5.2 this method delegates to {@link #bodyValue(Object)}.
* @deprecated as of Spring Framework 5.2 in favor of {@link #bodyValue(Object)}
*/
@Deprecated
RequestHeadersSpec<?> syncBody(Object body);
} }

11
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientResponseException.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -168,15 +168,6 @@ public class WebClientResponseException extends WebClientException {
return this.statusCode; return this.statusCode;
} }
/**
* Return the raw HTTP status code value.
* @deprecated in favor of {@link #getStatusCode()}, for removal in 7.0
*/
@Deprecated(since = "6.0")
public int getRawStatusCode() {
return this.statusCode.value();
}
/** /**
* Return the HTTP status text. * Return the HTTP status text.
*/ */

8
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -122,12 +122,6 @@ class DefaultServerRequest implements ServerRequest {
return request().getMethod(); return request().getMethod();
} }
@Override
@Deprecated
public String methodName() {
return request().getMethod().name();
}
@Override @Override
public URI uri() { public URI uri() {
return request().getURI(); return request().getURI();

8
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -260,12 +260,6 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
this.statusCode, this.headers, this.cookies, inserter, this.hints)); this.statusCode, this.headers, this.cookies, inserter, this.hints));
} }
@Override
@Deprecated
public Mono<ServerResponse> syncBody(Object body) {
return bodyValue(body);
}
@Override @Override
public Mono<ServerResponse> render(String name, Object... modelAttributes) { public Mono<ServerResponse> render(String name, Object... modelAttributes) {
return new DefaultRenderingResponseBuilder(name) return new DefaultRenderingResponseBuilder(name)

20
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -1144,12 +1144,6 @@ public abstract class RequestPredicates {
return this.delegate.method(); return this.delegate.method();
} }
@Override
@Deprecated
public String methodName() {
return this.delegate.methodName();
}
@Override @Override
public URI uri() { public URI uri() {
return this.delegate.uri(); return this.delegate.uri();
@ -1165,12 +1159,6 @@ public abstract class RequestPredicates {
return this.delegate.path(); return this.delegate.path();
} }
@Override
@Deprecated
public PathContainer pathContainer() {
return this.delegate.pathContainer();
}
@Override @Override
public RequestPath requestPath() { public RequestPath requestPath() {
return this.delegate.requestPath(); return this.delegate.requestPath();
@ -1415,11 +1403,5 @@ public abstract class RequestPredicates {
public String path() { public String path() {
return this.requestPath.pathWithinApplication().value(); return this.requestPath.pathWithinApplication().value();
} }
@Override
@Deprecated
public PathContainer pathContainer() {
return this.requestPath;
}
} }
} }

20
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,7 +42,6 @@ import org.springframework.http.MediaType;
import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.json.Jackson2CodecSupport; import org.springframework.http.codec.json.Jackson2CodecSupport;
import org.springframework.http.codec.multipart.Part; import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.RequestPath; import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -72,14 +71,6 @@ public interface ServerRequest {
*/ */
HttpMethod method(); HttpMethod method();
/**
* Get the name of the HTTP method.
* @return the HTTP method as a String
* @deprecated as of 6.0, in favor of {@link #method()}
*/
@Deprecated(since = "6.0")
String methodName();
/** /**
* Get the request URI. * Get the request URI.
*/ */
@ -103,15 +94,6 @@ public interface ServerRequest {
return requestPath().pathWithinApplication().value(); return requestPath().pathWithinApplication().value();
} }
/**
* Get the request path as a {@code PathContainer}.
* @deprecated as of 5.3, in favor on {@link #requestPath()}
*/
@Deprecated
default PathContainer pathContainer() {
return requestPath();
}
/** /**
* Get the request path as a {@code PathContainer}. * Get the request path as a {@code PathContainer}.
* @since 5.3 * @since 5.3

10
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -480,14 +480,6 @@ public interface ServerResponse {
*/ */
Mono<ServerResponse> body(BodyInserter<?, ? super ServerHttpResponse> inserter); Mono<ServerResponse> body(BodyInserter<?, ? super ServerHttpResponse> inserter);
/**
* Set the response body to the given {@code Object} and return it.
* As of 5.2 this method delegates to {@link #bodyValue(Object)}.
* @deprecated as of Spring Framework 5.2 in favor of {@link #bodyValue(Object)}
*/
@Deprecated
Mono<ServerResponse> syncBody(Object body);
/** /**
* Render the template with the given {@code name} using the given {@code modelAttributes}. * Render the template with the given {@code name} using the given {@code modelAttributes}.
* The model attributes are mapped under a * The model attributes are mapped under a

15
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,6 @@ import org.springframework.http.HttpRange;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.multipart.Part; import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.RequestPath; import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -87,12 +86,6 @@ public class ServerRequestWrapper implements ServerRequest {
return this.delegate.method(); return this.delegate.method();
} }
@Override
@Deprecated
public String methodName() {
return this.delegate.methodName();
}
@Override @Override
public URI uri() { public URI uri() {
return this.delegate.uri(); return this.delegate.uri();
@ -108,12 +101,6 @@ public class ServerRequestWrapper implements ServerRequest {
return this.delegate.path(); return this.delegate.path();
} }
@Override
@Deprecated
public PathContainer pathContainer() {
return this.delegate.pathContainer();
}
@Override @Override
public RequestPath requestPath() { public RequestPath requestPath() {
return this.delegate.requestPath(); return this.delegate.requestPath();

38
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -92,42 +92,6 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
private final BuilderConfiguration options; private final BuilderConfiguration options;
/**
* Full constructor with a mapping name.
* @deprecated as of 5.3.4 in favor using {@link RequestMappingInfo.Builder} via {@link #paths(String...)}.
*/
@Deprecated
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
@Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes,
@Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) {
this(name, patterns, methods, params, headers, consumes, produces, custom, new BuilderConfiguration());
}
/**
* Create an instance with the given conditions.
* @deprecated as of 5.3.4 in favor using {@link RequestMappingInfo.Builder} via {@link #paths(String...)}.
*/
@Deprecated
public RequestMappingInfo(@Nullable PatternsRequestCondition patterns,
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
@Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes,
@Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) {
this(null, patterns, methods, params, headers, consumes, produces, custom);
}
/**
* Re-create a RequestMappingInfo with the given custom request condition.
* @deprecated since 5.3.4 in favor of using a {@link Builder} via {@link #mutate()}.
*/
@Deprecated
public RequestMappingInfo(RequestMappingInfo info, @Nullable RequestCondition<?> customRequestCondition) {
this(info.name, info.patternsCondition, info.methodsCondition, info.paramsCondition, info.headersCondition,
info.consumesCondition, info.producesCondition, customRequestCondition);
}
private RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns, private RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params, @Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
@Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes, @Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes,

4
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolver.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -59,7 +59,7 @@ public class RequestHeaderMapMethodArgumentResolver extends HandlerMethodArgumen
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
@Override @Override
public Object resolveArgumentValue( public Object resolveArgumentValue(
MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) { MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) {

10
spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -186,14 +186,6 @@ public final class CloseStatus {
return new CloseStatus(this.code, reason); return new CloseStatus(this.code, reason);
} }
/**
* @deprecated as of 5.3 in favor of comparing codes directly
*/
@Deprecated
public boolean equalsCode(CloseStatus other) {
return (this.code == other.code);
}
/** /**
* Return a constant for the given code, or create a new instance if the * Return a constant for the given code, or create a new instance if the

24
spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -73,28 +73,6 @@ public class HandshakeInfo {
this(uri, headers, EMPTY_COOKIES, principal, protocol, null, Collections.emptyMap(), null); this(uri, headers, EMPTY_COOKIES, principal, protocol, null, Collections.emptyMap(), null);
} }
/**
* Constructor targeting server-side use with extra information such as
* the remote address, attributes, and a log prefix.
* @param uri the endpoint URL
* @param headers server request headers
* @param principal the principal for the session
* @param protocol the negotiated sub-protocol (may be {@code null})
* @param remoteAddress the remote address of the client
* @param attributes initial attributes for the WebSocket session
* @param logPrefix the log prefix for the handshake request.
* @since 5.1
* @deprecated as of 5.3.5 in favor of
* {@link #HandshakeInfo(URI, HttpHeaders, MultiValueMap, Mono, String, InetSocketAddress, Map, String)}
*/
@Deprecated
public HandshakeInfo(URI uri, HttpHeaders headers, Mono<Principal> principal,
@Nullable String protocol, @Nullable InetSocketAddress remoteAddress,
Map<String, Object> attributes, @Nullable String logPrefix) {
this(uri, headers, EMPTY_COOKIES, principal, protocol, remoteAddress, attributes, logPrefix);
}
/** /**
* Constructor targeting server-side use with extra information such as the * Constructor targeting server-side use with extra information such as the
* cookies, remote address, attributes, and a log prefix. * cookies, remote address, attributes, and a log prefix.

63
spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -119,64 +119,6 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
return builder.build(); return builder.build();
} }
/**
* Configure the maximum allowable frame payload length. Setting this value
* to your application's requirement may reduce denial of service attacks
* using long data frames.
* <p>Corresponds to the argument with the same name in the constructor of
* {@link io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory
* WebSocketServerHandshakerFactory} in Netty.
* <p>By default set to 65536 (64K).
* @param maxFramePayloadLength the max length for frames.
* @since 5.2
* @deprecated as of 5.3 in favor of providing a supplier of
* {@link reactor.netty.http.client.WebsocketClientSpec.Builder} with a
* constructor argument
*/
@Deprecated
public void setMaxFramePayloadLength(int maxFramePayloadLength) {
this.maxFramePayloadLength = maxFramePayloadLength;
}
/**
* Return the configured {@link #setMaxFramePayloadLength(int) maxFramePayloadLength}.
* @since 5.2
* @deprecated as of 5.3 in favor of {@link #getWebsocketClientSpec()}
*/
@Deprecated
public int getMaxFramePayloadLength() {
return getWebsocketClientSpec().maxFramePayloadLength();
}
/**
* Configure whether to let ping frames through to be handled by the
* {@link WebSocketHandler} given to the execute method. By default, Reactor
* Netty automatically replies with pong frames in response to pings. This is
* useful in a proxy for allowing ping and pong frames through.
* <p>By default this is set to {@code false} in which case ping frames are
* handled automatically by Reactor Netty. If set to {@code true}, ping
* frames will be passed through to the {@link WebSocketHandler}.
* @param handlePing whether to let Ping frames through for handling
* @since 5.2.4
* @deprecated as of 5.3 in favor of providing a supplier of
* {@link reactor.netty.http.client.WebsocketClientSpec.Builder} with a
* constructor argument
*/
@Deprecated
public void setHandlePing(boolean handlePing) {
this.handlePing = handlePing;
}
/**
* Return the configured {@link #setHandlePing(boolean)}.
* @since 5.2.4
* @deprecated as of 5.3 in favor of {@link #getWebsocketClientSpec()}
*/
@Deprecated
public boolean getHandlePing() {
return getWebsocketClientSpec().handlePing();
}
@Override @Override
public Mono<Void> execute(URI url, WebSocketHandler handler) { public Mono<Void> execute(URI url, WebSocketHandler handler) {
return execute(url, new HttpHeaders(), handler); return execute(url, new HttpHeaders(), handler);
@ -194,8 +136,7 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol"); String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol");
HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol);
NettyDataBufferFactory factory = new NettyDataBufferFactory(outbound.alloc()); NettyDataBufferFactory factory = new NettyDataBufferFactory(outbound.alloc());
WebSocketSession session = new ReactorNettyWebSocketSession( WebSocketSession session = new ReactorNettyWebSocketSession(inbound, outbound, info, factory);
inbound, outbound, info, factory, getMaxFramePayloadLength());
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Started session '" + session.getId() + "' for " + url); logger.debug("Started session '" + session.getId() + "' for " + url);
} }

60
spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNettyRequestUpgradeStrategy.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -94,64 +94,6 @@ public class ReactorNettyRequestUpgradeStrategy implements RequestUpgradeStrateg
return builder.build(); return builder.build();
} }
/**
* Configure the maximum allowable frame payload length. Setting this value
* to your application's requirement may reduce denial of service attacks
* using long data frames.
* <p>Corresponds to the argument with the same name in the constructor of
* {@link io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory
* WebSocketServerHandshakerFactory} in Netty.
* <p>By default set to 65536 (64K).
* @param maxFramePayloadLength the max length for frames.
* @since 5.1
* @deprecated as of 5.2.6 in favor of providing a supplier of
* {@link reactor.netty.http.server.WebsocketServerSpec.Builder} with a
* constructor argument
*/
@Deprecated
public void setMaxFramePayloadLength(Integer maxFramePayloadLength) {
this.maxFramePayloadLength = maxFramePayloadLength;
}
/**
* Return the configured max length for frames.
* @since 5.1
* @deprecated as of 5.2.6 in favor of {@link #getWebsocketServerSpec()}
*/
@Deprecated
public int getMaxFramePayloadLength() {
return getWebsocketServerSpec().maxFramePayloadLength();
}
/**
* Configure whether to let ping frames through to be handled by the
* {@link WebSocketHandler} given to the upgrade method. By default, Reactor
* Netty automatically replies with pong frames in response to pings. This is
* useful in a proxy for allowing ping and pong frames through.
* <p>By default this is set to {@code false} in which case ping frames are
* handled automatically by Reactor Netty. If set to {@code true}, ping
* frames will be passed through to the {@link WebSocketHandler}.
* @param handlePing whether to let Ping frames through for handling
* @since 5.2.4
* @deprecated as of 5.2.6 in favor of providing a supplier of
* {@link reactor.netty.http.server.WebsocketServerSpec.Builder} with a
* constructor argument
*/
@Deprecated
public void setHandlePing(boolean handlePing) {
this.handlePing = handlePing;
}
/**
* Return the configured {@link #setHandlePing(boolean)}.
* @since 5.2.4
* @deprecated as of 5.2.6 in favor of {@link #getWebsocketServerSpec()}
*/
@Deprecated
public boolean getHandlePing() {
return getWebsocketServerSpec().handlePing();
}
@Override @Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,

18
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,12 +18,11 @@ package org.springframework.web.reactive.function.client
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.reactive.asFlow import kotlinx.coroutines.reactive.asFlow
import kotlinx.coroutines.reactor.asFlux
import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.reactor.awaitSingleOrNull
import kotlinx.coroutines.reactor.asFlux
import kotlinx.coroutines.reactor.mono import kotlinx.coroutines.reactor.mono
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
@ -82,19 +81,6 @@ inline fun <reified T : Any> RequestBodySpec.body(producer: Any): RequestHeaders
inline fun <reified T : Any> RequestBodySpec.bodyValueWithType(body: T): RequestHeadersSpec<*> = inline fun <reified T : Any> RequestBodySpec.bodyValueWithType(body: T): RequestHeadersSpec<*> =
bodyValue(body, object : ParameterizedTypeReference<T>() {}) bodyValue(body, object : ParameterizedTypeReference<T>() {})
/**
* Coroutines variant of [WebClient.RequestHeadersSpec.exchange].
*
* @author Sebastien Deleuze
* @since 5.2
*/
@Suppress("DEPRECATION")
@Deprecated("Deprecated since 5.3 due to the possibility to leak memory and/or connections; please," +
"use awaitExchange { } or exchangeToFlow { } instead; consider also using retrieve()" +
"which provides access to the response status and headers via ResponseEntity along with error status handling.")
suspend fun RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchange(): ClientResponse =
exchange().awaitSingle()
/** /**
* Coroutines variant of [WebClient.RequestHeadersSpec.exchangeToMono]. * Coroutines variant of [WebClient.RequestHeadersSpec.exchangeToMono].
* *

14
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensions.kt

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -85,18 +85,6 @@ suspend inline fun <reified T: Any> ServerResponse.BodyBuilder.bodyValueWithType
suspend inline fun <reified T : Any> ServerResponse.BodyBuilder.bodyAndAwait(flow: Flow<T>): ServerResponse = suspend inline fun <reified T : Any> ServerResponse.BodyBuilder.bodyAndAwait(flow: Flow<T>): ServerResponse =
body(flow, object : ParameterizedTypeReference<T>() {}).awaitSingle() body(flow, object : ParameterizedTypeReference<T>() {}).awaitSingle()
/**
* Extension for [ServerResponse.BodyBuilder.body] providing a
* `bodyToServerSentEvents(Publisher<T>)` variant. This extension is not subject to type
* erasure and retains actual generic type arguments.
*
* @author Sebastien Deleuze
* @since 5.0
*/
@Deprecated("Use 'sse().body(publisher)' instead.", replaceWith = ReplaceWith("sse().body(publisher)"))
inline fun <reified T : Any> ServerResponse.BodyBuilder.bodyToServerSentEvents(publisher: Publisher<T>): Mono<ServerResponse> =
contentType(MediaType.TEXT_EVENT_STREAM).body(publisher, object : ParameterizedTypeReference<T>() {})
/** /**
* Shortcut for setting [MediaType.APPLICATION_JSON] `Content-Type` header. * Shortcut for setting [MediaType.APPLICATION_JSON] `Content-Type` header.
* @author Sebastien Deleuze * @author Sebastien Deleuze

91
spring-webflux/src/main/kotlin/org/springframework/web/reactive/server/ServerWebExchangeExtensions.kt

@ -1,91 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.server
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.reactor.mono
import org.springframework.http.codec.multipart.Part
import org.springframework.util.MultiValueMap
import org.springframework.web.server.ServerWebExchange
import org.springframework.web.server.WebSession
import java.security.Principal
/**
* Coroutines variant of [ServerWebExchange.getFormData].
*
* @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()
/**
* Coroutines variant of [ServerWebExchange.getMultipartData].
*
* @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()
/**
* Coroutines variant of [ServerWebExchange.getPrincipal].
*
* @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()
/**
* Coroutines variant of [ServerWebExchange.getSession].
*
* @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()
/**
* Coroutines variant of [ServerWebExchange.Builder.principal].
*
* @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() })

4
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java

@ -327,7 +327,7 @@ class DefaultClientResponseTests {
WebClientResponseException exception = resultMono.block(); WebClientResponseException exception = resultMono.block();
assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getMessage()).isEqualTo("404 Not Found from UNKNOWN https://example.org:9999/app/path"); assertThat(exception.getMessage()).isEqualTo("404 Not Found from UNKNOWN https://example.org:9999/app/path");
assertThat(exception.getHeaders().asMultiValueMap()).containsExactly(entry("Content-Type", List.of("text/plain"))); assertThat(exception.getHeaders().containsHeaderValue("Content-Type", "text/plain")).isTrue();
assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes); assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes);
} }
@ -387,7 +387,7 @@ class DefaultClientResponseTests {
WebClientResponseException exception = (WebClientResponseException) t; WebClientResponseException exception = (WebClientResponseException) t;
assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getMessage()).isEqualTo("404 Not Found"); assertThat(exception.getMessage()).isEqualTo("404 Not Found");
assertThat(exception.getHeaders().asMultiValueMap()).containsExactly(entry("Content-Type",List.of("text/plain"))); assertThat(exception.getHeaders().containsHeaderValue("Content-Type", "text/plain"));
assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes); assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes);
}) })
.verify(); .verify();

31
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -135,35 +135,6 @@ public class DefaultWebClientTests {
assertThat(request.cookies().getFirst("id")).isEqualTo("123"); assertThat(request.cookies().getFirst("id")).isEqualTo("123");
} }
@Test
@SuppressWarnings("deprecation")
public void contextFromThreadLocal() {
WebClient client = this.builder
.filter((request, next) ->
// Async, continue on different thread
Mono.delay(Duration.ofMillis(10)).then(next.exchange(request)))
.filter((request, next) ->
Mono.deferContextual(contextView -> {
String fooValue = contextView.get("foo");
return next.exchange(ClientRequest.from(request).header("foo", fooValue).build());
}))
.build();
ThreadLocal<String> fooHolder = new ThreadLocal<>();
fooHolder.set("bar");
try {
client.get().uri("/path")
.context(context -> context.put("foo", fooHolder.get()))
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
}
finally {
fooHolder.remove();
}
ClientRequest request = verifyAndGetRequest();
assertThat(request.headers().getFirst("foo")).isEqualTo("bar");
}
@Test @Test
void httpRequest() { void httpRequest() {
this.builder.build().get().uri("/path") this.builder.build().get().uri("/path")

40
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctionsTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -123,44 +123,6 @@ class ExchangeFilterFunctionsTests {
ExchangeFilterFunctions.basicAuthentication("foo", "\ud83d\udca9").filter(request, exchange)); ExchangeFilterFunctions.basicAuthentication("foo", "\ud83d\udca9").filter(request, exchange));
} }
@Test
@SuppressWarnings("deprecation")
public void basicAuthenticationAttributes() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL)
.attributes(org.springframework.web.reactive.function.client.ExchangeFilterFunctions
.Credentials.basicAuthenticationCredentials("foo", "bar"))
.build();
ClientResponse response = mock();
ExchangeFunction exchange = r -> {
assertThat(r.headers().containsHeader(HttpHeaders.AUTHORIZATION)).isTrue();
assertThat(r.headers().getFirst(HttpHeaders.AUTHORIZATION)).startsWith("Basic ");
return Mono.just(response);
};
ExchangeFilterFunction auth = ExchangeFilterFunctions.basicAuthentication();
assertThat(request.headers().containsHeader(HttpHeaders.AUTHORIZATION)).isFalse();
ClientResponse result = auth.filter(request, exchange).block();
assertThat(result).isEqualTo(response);
}
@Test
@SuppressWarnings("deprecation")
public void basicAuthenticationAbsentAttributes() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
ClientResponse response = mock();
ExchangeFunction exchange = r -> {
assertThat(r.headers().containsHeader(HttpHeaders.AUTHORIZATION)).isFalse();
return Mono.just(response);
};
ExchangeFilterFunction auth = ExchangeFilterFunctions.basicAuthentication();
assertThat(request.headers().containsHeader(HttpHeaders.AUTHORIZATION)).isFalse();
ClientResponse result = auth.filter(request, exchange).block();
assertThat(result).isEqualTo(response);
}
@Test @Test
void statusHandlerMatch() { void statusHandlerMatch() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build(); ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();

2
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java

@ -601,7 +601,6 @@ class WebClientIntegrationTests {
assertThat(throwable).isInstanceOf(WebClientResponseException.class); assertThat(throwable).isInstanceOf(WebClientResponseException.class);
WebClientResponseException ex = (WebClientResponseException) throwable; WebClientResponseException ex = (WebClientResponseException) throwable;
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(ex.getRawStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.value());
assertThat(ex.getStatusText()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()); assertThat(ex.getStatusText()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
assertThat(ex.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN); assertThat(ex.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage); assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage);
@ -710,7 +709,6 @@ class WebClientIntegrationTests {
assertThat(throwable).isInstanceOf(UnknownHttpStatusCodeException.class); assertThat(throwable).isInstanceOf(UnknownHttpStatusCodeException.class);
UnknownHttpStatusCodeException ex = (UnknownHttpStatusCodeException) throwable; UnknownHttpStatusCodeException ex = (UnknownHttpStatusCodeException) throwable;
assertThat(ex.getMessage()).isEqualTo(("Unknown status code ["+errorStatus+"]")); assertThat(ex.getMessage()).isEqualTo(("Unknown status code ["+errorStatus+"]"));
assertThat(ex.getRawStatusCode()).isEqualTo(errorStatus);
assertThat(ex.getStatusText()).isEmpty(); assertThat(ex.getStatusText()).isEmpty();
assertThat(ex.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN); assertThat(ex.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage); assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage);

12
spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -95,16 +95,6 @@ class WebClientExtensionsTests {
verify { responseSpec.bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {}) } verify { responseSpec.bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {}) }
} }
@Test
@Suppress("DEPRECATION")
fun awaitExchange() {
val response = mockk<ClientResponse>()
every { requestBodySpec.exchange() } returns Mono.just(response)
runBlocking {
assertThat(requestBodySpec.awaitExchange()).isEqualTo(response)
}
}
@Test @Test
fun `awaitExchange with function parameter`() { fun `awaitExchange with function parameter`() {
val foo = mockk<Foo>() val foo = mockk<Foo>()

Loading…
Cancel
Save