Skip to content

Commit fc8f55f

Browse files
committed
Upgrade to OkHTTP 4.9.3
Closes gh-18506
1 parent 4232877 commit fc8f55f

3 files changed

Lines changed: 75 additions & 10 deletions

File tree

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,19 +1326,16 @@ bom {
13261326
]
13271327
}
13281328
}
1329-
library("OkHttp3", "3.14.9") {
1330-
prohibit("[4.0.0-alpha01,)") {
1331-
because "it requires Kotlin"
1332-
}
1329+
library("OkHttp", "4.9.3") {
13331330
group("com.squareup.okhttp3") {
13341331
modules = [
13351332
"logging-interceptor",
13361333
"mockwebserver",
13371334
"okcurl",
13381335
"okhttp",
1336+
"okhttp-brotli",
13391337
"okhttp-dnsoverhttps",
13401338
"okhttp-sse",
1341-
"okhttp-testing-support",
13421339
"okhttp-tls",
13431340
"okhttp-urlconnection"
13441341
]

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import java.util.Set;
2525
import java.util.function.Supplier;
2626

27+
import okhttp3.OkHttpClient;
2728
import org.apache.http.client.config.RequestConfig;
29+
import org.assertj.core.api.InstanceOfAssertFactories;
2830
import org.junit.jupiter.api.Test;
2931
import org.junit.jupiter.api.extension.ExtendWith;
3032
import org.mockito.InOrder;
@@ -523,19 +525,19 @@ void bufferRequestBodyCanBeConfiguredOnSimpleRequestFactory() {
523525
}
524526

525527
@Test
526-
void connectTimeoutCanBeConfiguredOnOkHttp3RequestFactory() {
528+
void connectTimeoutCanBeConfiguredOnOkHttpRequestFactory() {
527529
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class)
528530
.setConnectTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
529-
assertThat(
530-
ReflectionTestUtils.getField(ReflectionTestUtils.getField(requestFactory, "client"), "connectTimeout"))
531-
.isEqualTo(1234);
531+
assertThat(requestFactory).extracting("client", InstanceOfAssertFactories.type(OkHttpClient.class))
532+
.extracting(OkHttpClient::connectTimeoutMillis).isEqualTo(1234);
532533
}
533534

534535
@Test
535536
void readTimeoutCanBeConfiguredOnOkHttp3RequestFactory() {
536537
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class)
537538
.setReadTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
538-
assertThat(requestFactory).extracting("client").extracting("readTimeout").isEqualTo(1234);
539+
assertThat(requestFactory).extracting("client", InstanceOfAssertFactories.type(OkHttpClient.class))
540+
.extracting(OkHttpClient::readTimeoutMillis).isEqualTo(1234);
539541
}
540542

541543
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.web.client;
18+
19+
import java.time.Duration;
20+
21+
import okhttp3.OkHttpClient;
22+
import org.assertj.core.api.InstanceOfAssertFactories;
23+
import org.junit.jupiter.api.Test;
24+
25+
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
26+
import org.springframework.http.client.ClientHttpRequestFactory;
27+
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
31+
32+
/**
33+
* Tests for {@link RestTemplateBuilder} with OkHttp 3.x.
34+
*
35+
* @author Andy Wilkinson
36+
*/
37+
@ClassPathOverrides("com.squareup.okhttp3:okhttp:3.14.9")
38+
class RestTemplateBuilderTestsOkHttp3Tests {
39+
40+
private RestTemplateBuilder builder = new RestTemplateBuilder();
41+
42+
@Test
43+
void connectTimeoutCanBeConfiguredOnOkHttpRequestFactory() {
44+
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class)
45+
.setConnectTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
46+
assertThat(requestFactory).extracting("client", InstanceOfAssertFactories.type(OkHttpClient.class))
47+
.extracting(OkHttpClient::connectTimeoutMillis).isEqualTo(1234);
48+
}
49+
50+
@Test
51+
void readTimeoutCanBeConfiguredOnOkHttpRequestFactory() {
52+
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class)
53+
.setReadTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
54+
assertThat(requestFactory).extracting("client", InstanceOfAssertFactories.type(OkHttpClient.class))
55+
.extracting(OkHttpClient::readTimeoutMillis).isEqualTo(1234);
56+
}
57+
58+
@Test
59+
void bufferRequestBodyCanNotBeConfiguredOnOkHttpRequestFactory() {
60+
assertThatIllegalStateException()
61+
.isThrownBy(() -> this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class)
62+
.setBufferRequestBody(false).build().getRequestFactory())
63+
.withMessageContaining(OkHttp3ClientHttpRequestFactory.class.getName());
64+
}
65+
66+
}

0 commit comments

Comments
 (0)