Skip to content

Commit 2ed281f

Browse files
committed
Remove deprecated WebFlux APIs
See gh-33809
1 parent eb15b26 commit 2ed281f

29 files changed

+31
-730
lines changed

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -127,12 +127,6 @@ public HttpMethod method() {
127127
return this.method;
128128
}
129129

130-
@Override
131-
@Deprecated
132-
public String methodName() {
133-
return this.method.name();
134-
}
135-
136130
@Override
137131
public URI uri() {
138132
return this.uri;

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

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -129,27 +129,6 @@ public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromValue(T body, P
129129
writeWithMessageWriters(message, context, Mono.just(body), ResolvableType.forType(bodyType), null);
130130
}
131131

132-
/**
133-
* Inserter to write the given object.
134-
* <p>Alternatively, consider using the {@code bodyValue(Object)} shortcuts on
135-
* {@link org.springframework.web.reactive.function.client.WebClient WebClient} and
136-
* {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}.
137-
* @param body the body to write to the response
138-
* @param <T> the type of the body
139-
* @return the inserter to write a single object
140-
* @throws IllegalArgumentException if {@code body} is a {@link Publisher} or an
141-
* instance of a type supported by {@link ReactiveAdapterRegistry#getSharedInstance()},
142-
* for which {@link #fromPublisher(Publisher, Class)} or
143-
* {@link #fromProducer(Object, Class)} should be used.
144-
* @see #fromPublisher(Publisher, Class)
145-
* @see #fromProducer(Object, Class)
146-
* @deprecated As of Spring Framework 5.2, in favor of {@link #fromValue(Object)}
147-
*/
148-
@Deprecated
149-
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromObject(T body) {
150-
return fromValue(body);
151-
}
152-
153132
/**
154133
* Inserter to write the given producer of value(s) which must be a {@link Publisher}
155134
* or another producer adaptable to a {@code Publisher} via

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

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -133,18 +133,6 @@ static Builder from(ClientRequest other) {
133133
return new DefaultClientRequestBuilder(other);
134134
}
135135

136-
/**
137-
* Create a builder with the given HTTP method and url.
138-
* @param method the HTTP method (GET, POST, etc)
139-
* @param url the url (as a URI instance)
140-
* @return the created builder
141-
* @deprecated in favor of {@link #create(HttpMethod, URI)}
142-
*/
143-
@Deprecated
144-
static Builder method(HttpMethod method, URI url) {
145-
return new DefaultClientRequestBuilder(method, url);
146-
}
147-
148136
/**
149137
* Create a request builder with the given HTTP method and url.
150138
* @param method the HTTP method (GET, POST, etc)

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

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -211,21 +211,6 @@ default Builder mutate() {
211211

212212
// Static builder methods
213213

214-
/**
215-
* Create a builder with the status, headers, and cookies of the given response.
216-
* <p><strong>Note:</strong> Note that the body in the returned builder is
217-
* {@link Flux#empty()} by default. To carry over the one from the original
218-
* response, use {@code otherResponse.bodyToFlux(DataBuffer.class)} or
219-
* simply use the instance based {@link #mutate()} method.
220-
* @param other the response to copy the status, headers, and cookies from
221-
* @return the created builder
222-
* @deprecated as of 5.3 in favor of the instance based {@link #mutate()}.
223-
*/
224-
@Deprecated
225-
static Builder from(ClientResponse other) {
226-
return new DefaultClientResponseBuilder(other, false);
227-
}
228-
229214
/**
230215
* Create a response builder with the given status code and using default strategies for
231216
* reading the body.

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

+1-23
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import reactor.core.publisher.Flux;
4040
import reactor.core.publisher.Mono;
4141
import reactor.core.publisher.SignalType;
42-
import reactor.util.context.Context;
4342

4443
import org.springframework.core.ParameterizedTypeReference;
4544
import org.springframework.http.HttpHeaders;
@@ -207,8 +206,6 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec {
207206

208207
private final Map<String, Object> attributes = new LinkedHashMap<>(4);
209208

210-
private @Nullable Function<Context, Context> contextModifier;
211-
212209
private @Nullable Consumer<ClientHttpRequest> httpRequestConsumer;
213210

214211
DefaultRequestBodyUriSpec(HttpMethod httpMethod) {
@@ -335,14 +332,6 @@ public RequestBodySpec attributes(Consumer<Map<String, Object>> attributesConsum
335332
return this;
336333
}
337334

338-
@SuppressWarnings("deprecation")
339-
@Override
340-
public RequestBodySpec context(Function<Context, Context> contextModifier) {
341-
this.contextModifier = (this.contextModifier != null ?
342-
this.contextModifier.andThen(contextModifier) : contextModifier);
343-
return this;
344-
}
345-
346335
@Override
347336
public RequestBodySpec httpRequest(Consumer<ClientHttpRequest> requestConsumer) {
348337
this.httpRequestConsumer = (this.httpRequestConsumer != null ?
@@ -393,12 +382,6 @@ public RequestHeadersSpec<?> body(BodyInserter<?, ? super ClientHttpRequest> ins
393382
return this;
394383
}
395384

396-
@Override
397-
@Deprecated
398-
public RequestHeadersSpec<?> syncBody(Object body) {
399-
return bodyValue(body);
400-
}
401-
402385
@Override
403386
public ResponseSpec retrieve() {
404387
return new DefaultResponseSpec(
@@ -434,9 +417,7 @@ public <V> Flux<V> exchangeToFlux(Function<ClientResponse, ? extends Flux<V>> re
434417
});
435418
}
436419

437-
@SuppressWarnings("deprecation")
438-
@Override
439-
public Mono<ClientResponse> exchange() {
420+
private Mono<ClientResponse> exchange() {
440421
ClientRequest.Builder requestBuilder = initRequestBuilder();
441422
ClientRequestObservationContext observationContext = new ClientRequestObservationContext(requestBuilder);
442423
return Mono.deferContextual(contextView -> {
@@ -459,9 +440,6 @@ public Mono<ClientResponse> exchange() {
459440
WebClientUtils.getRequestDescription(request.method(), request.url()) +
460441
" [DefaultWebClient]")
461442
.switchIfEmpty(NO_HTTP_CLIENT_RESPONSE_ERROR);
462-
if (this.contextModifier != null) {
463-
responseMono = responseMono.contextWrite(this.contextModifier);
464-
}
465443
final AtomicBoolean responseReceived = new AtomicBoolean();
466444
return responseMono
467445
.doOnNext(response -> responseReceived.set(true))

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -251,16 +251,6 @@ public WebClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
251251
return this;
252252
}
253253

254-
@Override
255-
@Deprecated
256-
public WebClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer) {
257-
if (this.strategiesConfigurers == null) {
258-
this.strategiesConfigurers = new ArrayList<>(4);
259-
}
260-
this.strategiesConfigurers.add(configurer);
261-
return this;
262-
}
263-
264254
@Override
265255
public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) {
266256
this.exchangeFunction = exchangeFunction;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,12 +17,9 @@
1717
package org.springframework.web.reactive.function.client;
1818

1919
import java.nio.charset.Charset;
20-
import java.util.Map;
21-
import java.util.function.Consumer;
2220
import java.util.function.Function;
2321
import java.util.function.Predicate;
2422

25-
import org.jspecify.annotations.Nullable;
2623
import reactor.core.publisher.Mono;
2724

2825
import org.springframework.core.io.buffer.DataBufferUtils;
@@ -41,13 +38,6 @@
4138
*/
4239
public abstract class ExchangeFilterFunctions {
4340

44-
/**
45-
* Name of the request attribute with {@link Credentials} for {@link #basicAuthentication()}.
46-
*/
47-
private static final String BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE =
48-
ExchangeFilterFunctions.class.getName() + ".basicAuthenticationCredentials";
49-
50-
5141
/**
5242
* Consume up to the specified number of bytes from the response body and
5343
* cancel if any more data arrives.
@@ -100,81 +90,4 @@ public static ExchangeFilterFunction basicAuthentication(String username, String
10090
.build());
10191
}
10292

103-
/**
104-
* Variant of {@link #basicAuthentication(String, String)} that looks up
105-
* the {@link Credentials Credentials} in a
106-
* {@link #BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE request attribute}.
107-
* @return the filter to use
108-
* @see Credentials
109-
* @deprecated as of Spring 5.1 in favor of using
110-
* {@link HttpHeaders#setBasicAuth(String, String)} while building the request.
111-
*/
112-
@Deprecated
113-
public static ExchangeFilterFunction basicAuthentication() {
114-
return (request, next) -> {
115-
Object attr = request.attributes().get(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE);
116-
if (attr instanceof Credentials cred) {
117-
return next.exchange(ClientRequest.from(request)
118-
.headers(headers -> headers.setBasicAuth(cred.username, cred.password))
119-
.build());
120-
}
121-
else {
122-
return next.exchange(request);
123-
}
124-
};
125-
}
126-
127-
128-
/**
129-
* Stores username and password for HTTP basic authentication.
130-
* @deprecated as of Spring 5.1 in favor of using
131-
* {@link HttpHeaders#setBasicAuth(String, String)} while building the request.
132-
*/
133-
@Deprecated
134-
public static final class Credentials {
135-
136-
private final String username;
137-
138-
private final String password;
139-
140-
/**
141-
* Create a new {@code Credentials} instance with the given username and password.
142-
* @param username the username
143-
* @param password the password
144-
*/
145-
public Credentials(String username, String password) {
146-
Assert.notNull(username, "'username' must not be null");
147-
Assert.notNull(password, "'password' must not be null");
148-
this.username = username;
149-
this.password = password;
150-
}
151-
152-
/**
153-
* Return a {@literal Consumer} that stores the given username and password
154-
* as a request attribute of type {@code Credentials} that is in turn
155-
* used by {@link ExchangeFilterFunctions#basicAuthentication()}.
156-
* @param username the username
157-
* @param password the password
158-
* @return a consumer that can be passed into
159-
* {@linkplain ClientRequest.Builder#attributes(java.util.function.Consumer)}
160-
* @see ClientRequest.Builder#attributes(java.util.function.Consumer)
161-
* @see #BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE
162-
*/
163-
public static Consumer<Map<String, Object>> basicAuthenticationCredentials(String username, String password) {
164-
Credentials credentials = new Credentials(username, password);
165-
return (map -> map.put(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE, credentials));
166-
}
167-
168-
@Override
169-
public boolean equals(@Nullable Object other) {
170-
return (this == other ||(other instanceof Credentials that &&
171-
this.username.equals(that.username) && this.password.equals(that.password)));
172-
}
173-
174-
@Override
175-
public int hashCode() {
176-
return this.username.hashCode() * 31 + this.password.hashCode();
177-
}
178-
}
179-
18093
}

0 commit comments

Comments
 (0)