From e6ab8a6d618b2b22edbc9a3eb8aeccc0e984c931 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 21 Nov 2023 11:19:54 +0100 Subject: [PATCH] Remove attributes from RestClient This commit removes any references to attributes from RestClient, which were left by mistake. Closes gh-31625 --- .../web/client/DefaultRestClient.java | 26 +++++-------------- .../web/client/RestClient.java | 16 ------------ .../web/client/support/RestClientAdapter.java | 2 -- 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java index e1ba9f80d3..702ffc854e 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java @@ -26,7 +26,6 @@ import java.nio.charset.Charset; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -83,8 +82,6 @@ final class DefaultRestClient implements RestClient { private static final ClientRequestObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultClientRequestObservationConvention(); - private static final String URI_TEMPLATE_ATTRIBUTE = RestClient.class.getName() + ".uriTemplate"; - private final ClientHttpRequestFactory clientRequestFactory; @@ -256,7 +253,8 @@ final class DefaultRestClient implements RestClient { @Nullable private InternalBody body; - private final Map attributes = new LinkedHashMap<>(4); + @Nullable + private String uriTemplate; @Nullable private Consumer httpRequestConsumer; @@ -267,19 +265,19 @@ final class DefaultRestClient implements RestClient { @Override public RequestBodySpec uri(String uriTemplate, Object... uriVariables) { - attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate); + this.uriTemplate = uriTemplate; return uri(DefaultRestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables)); } @Override public RequestBodySpec uri(String uriTemplate, Map uriVariables) { - attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate); + this.uriTemplate = uriTemplate; return uri(DefaultRestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables)); } @Override public RequestBodySpec uri(String uriTemplate, Function uriFunction) { - attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate); + this.uriTemplate = uriTemplate; return uri(uriFunction.apply(DefaultRestClient.this.uriBuilderFactory.uriString(uriTemplate))); } @@ -351,18 +349,6 @@ final class DefaultRestClient implements RestClient { return this; } - @Override - public RequestBodySpec attribute(String name, Object value) { - this.attributes.put(name, value); - return this; - } - - @Override - public RequestBodySpec attributes(Consumer> attributesConsumer) { - attributesConsumer.accept(this.attributes); - return this; - } - @Override public RequestBodySpec httpRequest(Consumer requestConsumer) { this.httpRequestConsumer = (this.httpRequestConsumer != null ? @@ -455,7 +441,7 @@ final class DefaultRestClient implements RestClient { ClientHttpRequest clientRequest = createRequest(uri); clientRequest.getHeaders().addAll(headers); ClientRequestObservationContext observationContext = new ClientRequestObservationContext(clientRequest); - observationContext.setUriTemplate((String) this.attributes.get(URI_TEMPLATE_ATTRIBUTE)); + observationContext.setUriTemplate(this.uriTemplate); observation = ClientHttpObservationDocumentation.HTTP_CLIENT_EXCHANGES.observation(observationConvention, DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, observationRegistry).start(); if (this.body != null) { diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClient.java b/spring-web/src/main/java/org/springframework/web/client/RestClient.java index 0b7751e38e..4d2c9ca062 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClient.java @@ -498,22 +498,6 @@ public interface RestClient { */ S headers(Consumer headersConsumer); - /** - * Set the attribute with the given name to the given value. - * @param name the name of the attribute to add - * @param value the value of the attribute to add - * @return this builder - */ - S attribute(String name, Object value); - - /** - * Provides access to every attribute declared so far with the - * possibility to add, replace, or remove values. - * @param attributesConsumer the consumer to provide access to - * @return this builder - */ - S attributes(Consumer> attributesConsumer); - /** * Callback for access to the {@link ClientHttpRequest} that in turn * provides access to the native request of the underlying HTTP library. diff --git a/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java b/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java index 1c0377784a..2aa65e9a3f 100644 --- a/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java @@ -119,8 +119,6 @@ public final class RestClientAdapter implements HttpExchangeAdapter { bodySpec.header(HttpHeaders.COOKIE, String.join("; ", cookies)); } - bodySpec.attributes(attributes -> attributes.putAll(values.getAttributes())); - if (values.getBodyValue() != null) { bodySpec.body(values.getBodyValue()); }