Skip to content

Commit

Permalink
Remove deprecated WebFlux APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jan 16, 2025
1 parent eb15b26 commit 2ed281f
Show file tree
Hide file tree
Showing 29 changed files with 31 additions and 730 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -127,12 +127,6 @@ public HttpMethod method() {
return this.method;
}

@Override
@Deprecated
public String methodName() {
return this.method.name();
}

@Override
public URI uri() {
return this.uri;
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -129,27 +129,6 @@ public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromValue(T body, P
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}
* or another producer adaptable to a {@code Publisher} via
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -133,18 +133,6 @@ static Builder from(ClientRequest 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.
* @param method the HTTP method (GET, POST, etc)
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -211,21 +211,6 @@ default Builder mutate() {

// 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
* reading the body.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.SignalType;
import reactor.util.context.Context;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -207,8 +206,6 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec {

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

private @Nullable Function<Context, Context> contextModifier;

private @Nullable Consumer<ClientHttpRequest> httpRequestConsumer;

DefaultRequestBodyUriSpec(HttpMethod httpMethod) {
Expand Down Expand Up @@ -335,14 +332,6 @@ public RequestBodySpec attributes(Consumer<Map<String, Object>> attributesConsum
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
public RequestBodySpec httpRequest(Consumer<ClientHttpRequest> requestConsumer) {
this.httpRequestConsumer = (this.httpRequestConsumer != null ?
Expand Down Expand Up @@ -393,12 +382,6 @@ public RequestHeadersSpec<?> body(BodyInserter<?, ? super ClientHttpRequest> ins
return this;
}

@Override
@Deprecated
public RequestHeadersSpec<?> syncBody(Object body) {
return bodyValue(body);
}

@Override
public ResponseSpec retrieve() {
return new DefaultResponseSpec(
Expand Down Expand Up @@ -434,9 +417,7 @@ public <V> Flux<V> exchangeToFlux(Function<ClientResponse, ? extends Flux<V>> re
});
}

@SuppressWarnings("deprecation")
@Override
public Mono<ClientResponse> exchange() {
private Mono<ClientResponse> exchange() {
ClientRequest.Builder requestBuilder = initRequestBuilder();
ClientRequestObservationContext observationContext = new ClientRequestObservationContext(requestBuilder);
return Mono.deferContextual(contextView -> {
Expand All @@ -459,9 +440,6 @@ public Mono<ClientResponse> exchange() {
WebClientUtils.getRequestDescription(request.method(), request.url()) +
" [DefaultWebClient]")
.switchIfEmpty(NO_HTTP_CLIENT_RESPONSE_ERROR);
if (this.contextModifier != null) {
responseMono = responseMono.contextWrite(this.contextModifier);
}
final AtomicBoolean responseReceived = new AtomicBoolean();
return responseMono
.doOnNext(response -> responseReceived.set(true))
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -251,16 +251,6 @@ public WebClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
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
public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) {
this.exchangeFunction = exchangeFunction;
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand All @@ -17,12 +17,9 @@
package org.springframework.web.reactive.function.client;

import java.nio.charset.Charset;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;

import org.springframework.core.io.buffer.DataBufferUtils;
Expand All @@ -41,13 +38,6 @@
*/
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
* cancel if any more data arrives.
Expand Down Expand Up @@ -100,81 +90,4 @@ public static ExchangeFilterFunction basicAuthentication(String username, String
.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();
}
}

}
Loading

0 comments on commit 2ed281f

Please sign in to comment.