Skip to content

Commit f595b46

Browse files
committed
Upgrade to HttpClient5 5.2.1
Closes gh-34086
1 parent 850d239 commit f595b46

File tree

8 files changed

+38
-30
lines changed

8 files changed

+38
-30
lines changed

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ bom {
390390
]
391391
}
392392
}
393-
library("HttpClient5", "5.1.4") {
393+
library("HttpClient5", "5.2.1") {
394394
group("org.apache.httpcomponents.client5") {
395395
modules = [
396396
"httpclient5",

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -144,7 +144,7 @@ private Response execute(HttpUriRequestBase request, String registryAuth) {
144144

145145
private Response execute(HttpUriRequest request) {
146146
try {
147-
ClassicHttpResponse response = this.client.execute(this.host, request);
147+
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null);
148148
int statusCode = response.getCode();
149149
if (statusCode >= 400 && statusCode <= 500) {
150150
HttpEntity entity = response.getEntity();

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -47,6 +47,7 @@
4747
import static org.assertj.core.api.Assertions.assertThat;
4848
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4949
import static org.mockito.ArgumentMatchers.any;
50+
import static org.mockito.ArgumentMatchers.isNull;
5051
import static org.mockito.BDDMockito.given;
5152
import static org.mockito.BDDMockito.then;
5253

@@ -98,7 +99,7 @@ void getShouldExecuteHttpGet() throws Exception {
9899
given(this.entity.getContent()).willReturn(this.content);
99100
given(this.response.getCode()).willReturn(200);
100101
Response response = this.http.get(this.uri);
101-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
102+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
102103
HttpUriRequest request = this.requestCaptor.getValue();
103104
assertThat(request).isInstanceOf(HttpGet.class);
104105
assertThat(request.getUri()).isEqualTo(this.uri);
@@ -112,7 +113,7 @@ void postShouldExecuteHttpPost() throws Exception {
112113
given(this.entity.getContent()).willReturn(this.content);
113114
given(this.response.getCode()).willReturn(200);
114115
Response response = this.http.post(this.uri);
115-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
116+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
116117
HttpUriRequest request = this.requestCaptor.getValue();
117118
assertThat(request).isInstanceOf(HttpPost.class);
118119
assertThat(request.getUri()).isEqualTo(this.uri);
@@ -127,7 +128,7 @@ void postWithRegistryAuthShouldExecuteHttpPostWithHeader() throws Exception {
127128
given(this.entity.getContent()).willReturn(this.content);
128129
given(this.response.getCode()).willReturn(200);
129130
Response response = this.http.post(this.uri, "auth token");
130-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
131+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
131132
HttpUriRequest request = this.requestCaptor.getValue();
132133
assertThat(request).isInstanceOf(HttpPost.class);
133134
assertThat(request.getUri()).isEqualTo(this.uri);
@@ -142,7 +143,7 @@ void postWithEmptyRegistryAuthShouldExecuteHttpPostWithoutHeader() throws Except
142143
given(this.entity.getContent()).willReturn(this.content);
143144
given(this.response.getCode()).willReturn(200);
144145
Response response = this.http.post(this.uri, "");
145-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
146+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
146147
HttpUriRequest request = this.requestCaptor.getValue();
147148
assertThat(request).isInstanceOf(HttpPost.class);
148149
assertThat(request.getUri()).isEqualTo(this.uri);
@@ -159,7 +160,7 @@ void postWithJsonContentShouldExecuteHttpPost() throws Exception {
159160
given(this.response.getCode()).willReturn(200);
160161
Response response = this.http.post(this.uri, APPLICATION_JSON,
161162
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
162-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
163+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
163164
HttpUriRequest request = this.requestCaptor.getValue();
164165
HttpEntity entity = request.getEntity();
165166
assertThat(request).isInstanceOf(HttpPost.class);
@@ -181,7 +182,7 @@ void postWithArchiveContentShouldExecuteHttpPost() throws Exception {
181182
given(this.response.getCode()).willReturn(200);
182183
Response response = this.http.post(this.uri, APPLICATION_X_TAR,
183184
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
184-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
185+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
185186
HttpUriRequest request = this.requestCaptor.getValue();
186187
HttpEntity entity = request.getEntity();
187188
assertThat(request).isInstanceOf(HttpPost.class);
@@ -203,7 +204,7 @@ void putWithJsonContentShouldExecuteHttpPut() throws Exception {
203204
given(this.response.getCode()).willReturn(200);
204205
Response response = this.http.put(this.uri, APPLICATION_JSON,
205206
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
206-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
207+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
207208
HttpUriRequest request = this.requestCaptor.getValue();
208209
HttpEntity entity = request.getEntity();
209210
assertThat(request).isInstanceOf(HttpPut.class);
@@ -225,7 +226,7 @@ void putWithArchiveContentShouldExecuteHttpPut() throws Exception {
225226
given(this.response.getCode()).willReturn(200);
226227
Response response = this.http.put(this.uri, APPLICATION_X_TAR,
227228
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
228-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
229+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
229230
HttpUriRequest request = this.requestCaptor.getValue();
230231
HttpEntity entity = request.getEntity();
231232
assertThat(request).isInstanceOf(HttpPut.class);
@@ -245,7 +246,7 @@ void deleteShouldExecuteHttpDelete() throws Exception {
245246
given(this.entity.getContent()).willReturn(this.content);
246247
given(this.response.getCode()).willReturn(200);
247248
Response response = this.http.delete(this.uri);
248-
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
249+
then(this.client).should().executeOpen(this.hostCaptor.capture(), this.requestCaptor.capture(), isNull());
249250
HttpUriRequest request = this.requestCaptor.getValue();
250251
assertThat(request).isInstanceOf(HttpDelete.class);
251252
assertThat(request.getUri()).isEqualTo(this.uri);
@@ -302,7 +303,7 @@ void executeWhenResponseIsIn500RangeWithOtherContentShouldThrowDockerException()
302303

303304
@Test
304305
void executeWhenClientThrowsIOExceptionRethrowsAsDockerException() throws IOException {
305-
given(this.client.execute(any(HttpHost.class), any(HttpUriRequest.class)))
306+
given(this.client.executeOpen(any(HttpHost.class), any(HttpUriRequest.class), isNull()))
306307
.willThrow(new IOException("test IO exception"));
307308
assertThatExceptionOfType(DockerConnectionException.class).isThrownBy(() -> this.http.get(this.uri))
308309
.satisfies((ex) -> assertThat(ex.getMessage()).contains("test IO exception"));
@@ -315,7 +316,8 @@ private String writeToString(HttpEntity entity) throws IOException {
315316
}
316317

317318
private void givenClientWillReturnResponse() throws IOException {
318-
given(this.client.execute(any(HttpHost.class), any(HttpUriRequest.class))).willReturn(this.response);
319+
given(this.client.executeOpen(any(HttpHost.class), any(HttpUriRequest.class), isNull()))
320+
.willReturn(this.response);
319321
given(this.response.getEntity()).willReturn(this.entity);
320322
}
321323

spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -184,7 +184,7 @@ private ClassicHttpResponse execute(HttpUriRequest request, URI url, String desc
184184
try {
185185
HttpHost host = HttpHost.create(url);
186186
request.addHeader("User-Agent", "SpringBootCli/" + getClass().getPackage().getImplementationVersion());
187-
return getHttp().execute(host, request);
187+
return getHttp().executeOpen(host, request, null);
188188
}
189189
catch (IOException ex) {
190190
throw new ReportableException(

spring-boot-project/spring-boot-tools/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/AbstractHttpClientMockTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -38,6 +38,7 @@
3838
import static org.mockito.ArgumentMatchers.any;
3939
import static org.mockito.ArgumentMatchers.argThat;
4040
import static org.mockito.ArgumentMatchers.isA;
41+
import static org.mockito.ArgumentMatchers.isNull;
4142
import static org.mockito.BDDMockito.given;
4243
import static org.mockito.Mockito.mock;
4344

@@ -70,7 +71,7 @@ protected void mockSuccessfulMetadataGet(String contentPath, String contentType,
7071
byte[] content = readClasspathResource(contentPath);
7172
mockHttpEntity(response, content, contentType);
7273
mockStatus(response, 200);
73-
given(this.http.execute(any(HttpHost.class), argThat(getForMetadata(serviceCapabilities))))
74+
given(this.http.executeOpen(any(HttpHost.class), argThat(getForMetadata(serviceCapabilities)), isNull()))
7475
.willReturn(response);
7576
}
7677

@@ -87,7 +88,7 @@ protected void mockSuccessfulProjectGeneration(MockHttpProjectGenerationRequest
8788
mockStatus(response, 200);
8889
String header = (request.fileName != null) ? contentDispositionValue(request.fileName) : null;
8990
mockHttpHeader(response, "Content-Disposition", header);
90-
given(this.http.execute(any(HttpHost.class), argThat(getForNonMetadata()))).willReturn(response);
91+
given(this.http.executeOpen(any(HttpHost.class), argThat(getForNonMetadata()), isNull())).willReturn(response);
9192
}
9293

9394
protected void mockProjectGenerationError(int status, String message) throws IOException, JSONException {
@@ -96,14 +97,14 @@ protected void mockProjectGenerationError(int status, String message) throws IOE
9697
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
9798
mockHttpEntity(response, createJsonError(status, message).getBytes(), "application/json");
9899
mockStatus(response, status);
99-
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
100+
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
100101
}
101102

102103
protected void mockMetadataGetError(int status, String message) throws IOException, JSONException {
103104
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
104105
mockHttpEntity(response, createJsonError(status, message).getBytes(), "application/json");
105106
mockStatus(response, status);
106-
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
107+
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
107108
}
108109

109110
protected HttpEntity mockHttpEntity(ClassicHttpResponse response, byte[] content, String contentType) {

spring-boot-project/spring-boot-tools/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import static org.assertj.core.api.Assertions.assertThat;
4141
import static org.junit.jupiter.api.Assertions.fail;
4242
import static org.mockito.ArgumentMatchers.any;
43+
import static org.mockito.ArgumentMatchers.isNull;
4344
import static org.mockito.BDDMockito.then;
4445

4546
/**
@@ -399,7 +400,7 @@ void parseMoreThanOneArg() throws Exception {
399400
@Test
400401
void userAgent() throws Exception {
401402
this.command.run("--list", "--target=https://fake-service");
402-
then(this.http).should().execute(any(HttpHost.class), this.requestCaptor.capture());
403+
then(this.http).should().executeOpen(any(HttpHost.class), this.requestCaptor.capture(), isNull());
403404
Header agent = this.requestCaptor.getValue().getHeaders("User-Agent")[0];
404405
assertThat(agent.getValue()).startsWith("SpringBootCli/");
405406
}

spring-boot-project/spring-boot-tools/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitializrServiceTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -25,6 +25,7 @@
2525
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2626
import static org.mockito.ArgumentMatchers.any;
2727
import static org.mockito.ArgumentMatchers.isA;
28+
import static org.mockito.ArgumentMatchers.isNull;
2829
import static org.mockito.BDDMockito.given;
2930
import static org.mockito.Mockito.mock;
3031

@@ -95,7 +96,7 @@ void generateProjectNoContent() throws Exception {
9596
mockSuccessfulMetadataGet(false);
9697
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
9798
mockStatus(response, 500);
98-
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
99+
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
99100
ProjectGenerationRequest request = new ProjectGenerationRequest();
100101
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
101102
.withMessageContaining("No content received from server");
@@ -115,7 +116,7 @@ void loadMetadataInvalidJson() throws Exception {
115116
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
116117
mockHttpEntity(response, "Foo-Bar-Not-JSON".getBytes(), "application/json");
117118
mockStatus(response, 200);
118-
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
119+
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
119120
ProjectGenerationRequest request = new ProjectGenerationRequest();
120121
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
121122
.withMessageContaining("Invalid content received from server");
@@ -125,7 +126,7 @@ void loadMetadataInvalidJson() throws Exception {
125126
void loadMetadataNoContent() throws Exception {
126127
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
127128
mockStatus(response, 500);
128-
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
129+
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
129130
ProjectGenerationRequest request = new ProjectGenerationRequest();
130131
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
131132
.withMessageContaining("No content received from server");

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesHttpComponentsTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -16,7 +16,9 @@
1616

1717
package org.springframework.boot.web.client;
1818

19+
import org.apache.hc.client5.http.HttpRoute;
1920
import org.apache.hc.client5.http.classic.HttpClient;
21+
import org.apache.hc.core5.function.Resolver;
2022
import org.apache.hc.core5.http.io.SocketConfig;
2123

2224
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
@@ -41,11 +43,12 @@ protected long connectTimeout(HttpComponentsClientHttpRequestFactory requestFact
4143
}
4244

4345
@Override
46+
@SuppressWarnings("unchecked")
4447
protected long readTimeout(HttpComponentsClientHttpRequestFactory requestFactory) {
4548
HttpClient httpClient = requestFactory.getHttpClient();
4649
Object connectionManager = ReflectionTestUtils.getField(httpClient, "connManager");
47-
SocketConfig socketConfig = (SocketConfig) ReflectionTestUtils.getField(connectionManager,
48-
"defaultSocketConfig");
50+
SocketConfig socketConfig = ((Resolver<HttpRoute, SocketConfig>) ReflectionTestUtils.getField(connectionManager,
51+
"socketConfigResolver")).resolve(null);
4952
return socketConfig.getSoTimeout().toMilliseconds();
5053
}
5154

0 commit comments

Comments
 (0)