Skip to content

Commit 8af1d8e

Browse files
committed
Remove applyAttributes flag from contribution
See gh-29958
1 parent 052b635 commit 8af1d8e

File tree

21 files changed

+47
-254
lines changed

21 files changed

+47
-254
lines changed

spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
9494
@Nullable
9595
private MultiValueMap<String, String> defaultCookies;
9696

97-
private boolean applyAttributes;
98-
9997
@Nullable
10098
private List<ExchangeFilterFunction> filters;
10199

@@ -157,7 +155,6 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
157155
}
158156
this.defaultCookies = (other.defaultCookies != null ?
159157
new LinkedMultiValueMap<>(other.defaultCookies) : null);
160-
this.applyAttributes = other.applyAttributes;
161158
this.filters = (other.filters != null ? new ArrayList<>(other.filters) : null);
162159
this.entityResultConsumer = other.entityResultConsumer;
163160
this.strategies = other.strategies;
@@ -216,12 +213,6 @@ private MultiValueMap<String, String> initCookies() {
216213
return this.defaultCookies;
217214
}
218215

219-
@Override
220-
public WebTestClient.Builder applyAttributes(boolean applyAttributes) {
221-
this.applyAttributes = applyAttributes;
222-
return this;
223-
}
224-
225216
@Override
226217
public WebTestClient.Builder filter(ExchangeFilterFunction filter) {
227218
Assert.notNull(filter, "ExchangeFilterFunction is required");
@@ -321,25 +312,22 @@ public WebTestClient build() {
321312
this.entityResultConsumer, this.responseTimeout, new DefaultWebTestClientBuilder(this));
322313
}
323314

324-
private ClientHttpConnector initConnector() {
325-
final ClientHttpConnector connector;
315+
private static ClientHttpConnector initConnector() {
326316
if (reactorNettyClientPresent) {
327-
connector = new ReactorClientHttpConnector();
317+
return new ReactorClientHttpConnector();
328318
}
329319
else if (reactorNetty2ClientPresent) {
330320
return new ReactorNetty2ClientHttpConnector();
331321
}
332322
else if (jettyClientPresent) {
333-
connector = new JettyClientHttpConnector();
323+
return new JettyClientHttpConnector();
334324
}
335325
else if (httpComponentsClientPresent) {
336-
connector = new HttpComponentsClientHttpConnector();
326+
return new HttpComponentsClientHttpConnector();
337327
}
338328
else {
339-
connector = new JdkClientHttpConnector();
329+
return new JdkClientHttpConnector();
340330
}
341-
connector.setApplyAttributes(this.applyAttributes);
342-
return connector;
343331
}
344332

345333
private ExchangeStrategies initExchangeStrategies() {

spring-test/src/main/java/org/springframework/test/web/reactive/server/HttpHandlerConnector.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public class HttpHandlerConnector implements ClientHttpConnector {
6464

6565
private final HttpHandler handler;
6666

67-
private boolean applyAttributes = true;
68-
6967

7068
/**
7169
* Constructor with the {@link HttpHandler} to handle requests with.
@@ -84,16 +82,6 @@ public Mono<ClientHttpResponse> connect(HttpMethod httpMethod, URI uri,
8482
.subscribeOn(Schedulers.parallel());
8583
}
8684

87-
@Override
88-
public void setApplyAttributes(boolean applyAttributes) {
89-
this.applyAttributes = applyAttributes;
90-
}
91-
92-
@Override
93-
public boolean getApplyAttributes() {
94-
return this.applyAttributes;
95-
}
96-
9785
private Mono<ClientHttpResponse> doConnect(
9886
HttpMethod httpMethod, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
9987

spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,6 @@ interface Builder {
425425
*/
426426
Builder defaultCookies(Consumer<MultiValueMap<String, String>> cookiesConsumer);
427427

428-
/**
429-
* Global option to specify whether or not attributes should be applied to every request,
430-
* if the used {@link ClientHttpConnector} allows it.
431-
* @param applyAttributes whether or not to apply attributes
432-
*/
433-
Builder applyAttributes(boolean applyAttributes);
434-
435428
/**
436429
* Add the given filter to the filter chain.
437430
* @param filter the filter to be added to the chain

spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class WiretapConnector implements ClientHttpConnector {
5555

5656
private final Map<String, ClientExchangeInfo> exchanges = new ConcurrentHashMap<>();
5757

58-
private boolean applyAttributes = true;
59-
6058

6159
WiretapConnector(ClientHttpConnector delegate) {
6260
this.delegate = delegate;
@@ -86,16 +84,6 @@ public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
8684
});
8785
}
8886

89-
@Override
90-
public void setApplyAttributes(boolean applyAttributes) {
91-
this.applyAttributes = applyAttributes;
92-
}
93-
94-
@Override
95-
public boolean getApplyAttributes() {
96-
return this.applyAttributes;
97-
}
98-
9987
/**
10088
* Create the {@link ExchangeResult} for the given "request-id" header value.
10189
*/

spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ public class MockMvcHttpConnector implements ClientHttpConnector {
8686

8787
private final List<RequestPostProcessor> requestPostProcessors;
8888

89-
private boolean applyAttributes = true;
90-
9189

9290
public MockMvcHttpConnector(MockMvc mockMvc) {
9391
this(mockMvc, Collections.emptyList());
@@ -117,16 +115,6 @@ public Mono<ClientHttpResponse> connect(
117115
}
118116
}
119117

120-
@Override
121-
public void setApplyAttributes(boolean applyAttributes) {
122-
this.applyAttributes = applyAttributes;
123-
}
124-
125-
@Override
126-
public boolean getApplyAttributes() {
127-
return this.applyAttributes;
128-
}
129-
130118
private RequestBuilder adaptRequest(
131119
HttpMethod httpMethod, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
132120

spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.net.URI;
2020
import java.time.Duration;
21-
import java.util.function.Function;
2221

2322
import org.junit.jupiter.api.Test;
2423
import reactor.core.publisher.Mono;
@@ -49,22 +48,7 @@ public class WiretapConnectorTests {
4948
public void captureAndClaim() {
5049
ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test");
5150
ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
52-
ClientHttpConnector connector = new ClientHttpConnector() {
53-
@Override
54-
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
55-
return requestCallback.apply(request).then(Mono.just(response));
56-
}
57-
58-
@Override
59-
public void setApplyAttributes(boolean applyAttributes) {
60-
61-
}
62-
63-
@Override
64-
public boolean getApplyAttributes() {
65-
return false;
66-
}
67-
};
51+
ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response));
6852

6953
ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
7054
.header(WebTestClient.WEBTESTCLIENT_REQUEST_ID, "1").build();

spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java

Lines changed: 8 additions & 15 deletions
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-2024 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.
@@ -60,8 +60,6 @@ private enum State {NEW, COMMITTING, COMMITTED}
6060

6161
private final Map<String, Object> attributes;
6262

63-
private final boolean applyAttributes;
64-
6563
private final AtomicReference<State> state = new AtomicReference<>(State.NEW);
6664

6765
private final List<Supplier<? extends Publisher<Void>>> commitActions = new ArrayList<>(4);
@@ -71,19 +69,14 @@ private enum State {NEW, COMMITTING, COMMITTED}
7169

7270

7371
public AbstractClientHttpRequest() {
74-
this(new HttpHeaders(), false);
75-
}
76-
77-
public AbstractClientHttpRequest(boolean applyAttributes) {
78-
this(new HttpHeaders(), applyAttributes);
72+
this(new HttpHeaders());
7973
}
8074

81-
public AbstractClientHttpRequest(HttpHeaders headers, boolean applyAttributes) {
75+
public AbstractClientHttpRequest(HttpHeaders headers) {
8276
Assert.notNull(headers, "HttpHeaders must not be null");
8377
this.headers = headers;
8478
this.cookies = new LinkedMultiValueMap<>();
8579
this.attributes = new LinkedHashMap<>();
86-
this.applyAttributes = applyAttributes;
8780
}
8881

8982

@@ -161,9 +154,7 @@ protected Mono<Void> doCommit(@Nullable Supplier<? extends Publisher<Void>> writ
161154
Mono.fromRunnable(() -> {
162155
applyHeaders();
163156
applyCookies();
164-
if (this.applyAttributes) {
165-
applyAttributes();
166-
}
157+
applyAttributes();
167158
this.state.set(State.COMMITTED);
168159
}));
169160

@@ -193,9 +184,11 @@ protected Mono<Void> doCommit(@Nullable Supplier<? extends Publisher<Void>> writ
193184
protected abstract void applyCookies();
194185

195186
/**
196-
* Add additional attributes from {@link #getAttributes()} to the underlying request.
187+
* Add attributes from {@link #getAttributes()} to the underlying request.
197188
* This method is called once only.
189+
* @since 6.2
198190
*/
199-
protected abstract void applyAttributes();
191+
protected void applyAttributes() {
192+
}
200193

201194
}

spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,4 @@ public interface ClientHttpConnector {
4848
Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
4949
Function<? super ClientHttpRequest, Mono<Void>> requestCallback);
5050

51-
/**
52-
* Set whether or not attributes should be applied to the underlying http-client library request.
53-
*/
54-
void setApplyAttributes(boolean applyAttributes);
55-
56-
/**
57-
* Whether or not attributes should be applied to the underlying http-client library request.
58-
*/
59-
boolean getApplyAttributes();
60-
6151
}

spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public class HttpComponentsClientHttpConnector implements ClientHttpConnector, C
5959

6060
private DataBufferFactory dataBufferFactory = DefaultDataBufferFactory.sharedInstance;
6161

62-
private boolean applyAttributes = true;
6362

6463
/**
6564
* Default constructor that creates and starts a new instance of {@link CloseableHttpAsyncClient}.
@@ -68,7 +67,6 @@ public HttpComponentsClientHttpConnector() {
6867
this(HttpAsyncClients.createDefault());
6968
}
7069

71-
7270
/**
7371
* Constructor with a pre-configured {@link CloseableHttpAsyncClient} instance.
7472
* @param client the client to use
@@ -113,22 +111,11 @@ public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
113111
context.setCookieStore(new BasicCookieStore());
114112
}
115113

116-
HttpComponentsClientHttpRequest request = new HttpComponentsClientHttpRequest(
117-
method, uri, context, this.dataBufferFactory, this.applyAttributes);
118-
114+
HttpComponentsClientHttpRequest request =
115+
new HttpComponentsClientHttpRequest(method, uri, context, this.dataBufferFactory);
119116
return requestCallback.apply(request).then(Mono.defer(() -> execute(request, context)));
120117
}
121118

122-
@Override
123-
public void setApplyAttributes(boolean applyAttributes) {
124-
this.applyAttributes = applyAttributes;
125-
}
126-
127-
@Override
128-
public boolean getApplyAttributes() {
129-
return this.applyAttributes;
130-
}
131-
132119
private Mono<ClientHttpResponse> execute(HttpComponentsClientHttpRequest request, HttpClientContext context) {
133120
AsyncRequestProducer requestProducer = request.toRequestProducer();
134121

spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java

Lines changed: 3 additions & 3 deletions
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-2024 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.
@@ -66,8 +66,8 @@ class HttpComponentsClientHttpRequest extends AbstractClientHttpRequest {
6666

6767

6868
public HttpComponentsClientHttpRequest(HttpMethod method, URI uri, HttpClientContext context,
69-
DataBufferFactory dataBufferFactory, boolean applyAttributes) {
70-
super(applyAttributes);
69+
DataBufferFactory dataBufferFactory) {
70+
7171
this.context = context;
7272
this.httpRequest = new BasicHttpRequest(method.name(), uri);
7373
this.dataBufferFactory = dataBufferFactory;

spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void setBufferFactory(DataBufferFactory bufferFactory) {
9696
public Mono<ClientHttpResponse> connect(
9797
HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
9898

99-
JdkClientHttpRequest jdkClientHttpRequest = new JdkClientHttpRequest(method, uri, this.bufferFactory, getApplyAttributes());
99+
JdkClientHttpRequest jdkClientHttpRequest = new JdkClientHttpRequest(method, uri, this.bufferFactory);
100100

101101
return requestCallback.apply(jdkClientHttpRequest).then(Mono.defer(() -> {
102102
HttpRequest httpRequest = jdkClientHttpRequest.getNativeRequest();
@@ -109,19 +109,4 @@ public Mono<ClientHttpResponse> connect(
109109
}));
110110
}
111111

112-
/**
113-
* Sets nothing, since {@link JdkClientHttpConnector} does not offer any possibility to add attributes.
114-
*/
115-
@Override
116-
public void setApplyAttributes(boolean applyAttributes) {
117-
}
118-
119-
/**
120-
* Returns false, since {@link JdkClientHttpConnector} does not offer any possibility to add attributes.
121-
*/
122-
@Override
123-
public boolean getApplyAttributes() {
124-
return false;
125-
}
126-
127112
}

spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class JdkClientHttpRequest extends AbstractClientHttpRequest {
5656
private final HttpRequest.Builder builder;
5757

5858

59-
public JdkClientHttpRequest(HttpMethod httpMethod, URI uri, DataBufferFactory bufferFactory, boolean applyAttributes) {
60-
super(applyAttributes);
59+
public JdkClientHttpRequest(HttpMethod httpMethod, URI uri, DataBufferFactory bufferFactory) {
6160
Assert.notNull(httpMethod, "HttpMethod is required");
6261
Assert.notNull(uri, "URI is required");
6362
Assert.notNull(bufferFactory, "DataBufferFactory is required");
@@ -113,15 +112,6 @@ protected void applyCookies() {
113112
.flatMap(List::stream).map(HttpCookie::toString).collect(Collectors.joining(";")));
114113
}
115114

116-
/**
117-
* Not implemented, since {@link HttpRequest} does not offer any possibility to add request attributes.
118-
*/
119-
@Override
120-
protected void applyAttributes() {
121-
// TODO
122-
throw new RuntimeException(String.format("Using attributes is not available for %s", HttpRequest.class.getName()));
123-
}
124-
125115
@Override
126116
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
127117
return doCommit(() -> {

0 commit comments

Comments
 (0)