Skip to content

Commit 6161ef7

Browse files
committed
Remove deprecated support for OkHTTP
Closes gh-42780
1 parent 68ed4b1 commit 6161ef7

11 files changed

+11
-245
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,13 +1441,6 @@ bom {
14411441
site("https://netty.io")
14421442
}
14431443
}
1444-
library("OkHttp", "4.12.0") {
1445-
group("com.squareup.okhttp3") {
1446-
imports = [
1447-
"okhttp-bom"
1448-
]
1449-
}
1450-
}
14511444
library("OpenTelemetry", "1.43.0") {
14521445
group("io.opentelemetry") {
14531446
imports = [

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ bom {
158158
]
159159
}
160160
}
161+
library("OkHttp", "4.12.0") {
162+
group("com.squareup.okhttp3") {
163+
imports = [
164+
"okhttp-bom"
165+
]
166+
}
167+
}
161168
library("OpenTelemetry Logback Appender", "2.7.0-alpha") {
162169
group("io.opentelemetry.instrumentation") {
163170
modules = [

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ dependencies {
2929
optional("com.oracle.database.jdbc:ucp11")
3030
optional("com.oracle.database.jdbc:ojdbc11")
3131
optional("com.samskivert:jmustache")
32-
optional("com.squareup.okhttp3:okhttp")
3332
optional("com.zaxxer:HikariCP")
3433
optional("io.netty:netty-tcnative-boringssl-static")
3534
optional("io.projectreactor:reactor-tools")

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactories.java

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
import javax.net.ssl.SSLContext;
3030
import javax.net.ssl.SSLException;
3131
import javax.net.ssl.SSLSocketFactory;
32-
import javax.net.ssl.TrustManager;
33-
import javax.net.ssl.X509TrustManager;
3432

3533
import io.netty.handler.ssl.SslContextBuilder;
36-
import okhttp3.OkHttpClient;
3734
import org.apache.hc.client5.http.classic.HttpClient;
3835
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
3936
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
@@ -77,10 +74,6 @@ public final class ClientHttpRequestFactories {
7774

7875
private static final boolean APACHE_HTTP_CLIENT_PRESENT = ClassUtils.isPresent(APACHE_HTTP_CLIENT_CLASS, null);
7976

80-
static final String OKHTTP_CLIENT_CLASS = "okhttp3.OkHttpClient";
81-
82-
private static final boolean OKHTTP_CLIENT_PRESENT = ClassUtils.isPresent(OKHTTP_CLIENT_CLASS, null);
83-
8477
static final String JETTY_CLIENT_CLASS = "org.eclipse.jetty.client.HttpClient";
8578

8679
private static final boolean JETTY_CLIENT_PRESENT = ClassUtils.isPresent(JETTY_CLIENT_CLASS, null);
@@ -100,14 +93,11 @@ private ClientHttpRequestFactories() {
10093
* <li>{@link HttpComponentsClientHttpRequestFactory}</li>
10194
* <li>{@link JettyClientHttpRequestFactory}</li>
10295
* <li>{@link ReactorClientHttpRequestFactory}</li>
103-
* <li>{@link org.springframework.http.client.OkHttp3ClientHttpRequestFactory
104-
* OkHttp3ClientHttpRequestFactory} (deprecated)</li>
10596
* <li>{@link SimpleClientHttpRequestFactory}</li>
10697
* </ol>
10798
* @param settings the settings to apply
10899
* @return a new {@link ClientHttpRequestFactory}
109100
*/
110-
@SuppressWarnings("removal")
111101
public static ClientHttpRequestFactory get(ClientHttpRequestFactorySettings settings) {
112102
Assert.notNull(settings, "Settings must not be null");
113103
if (APACHE_HTTP_CLIENT_PRESENT) {
@@ -119,9 +109,6 @@ public static ClientHttpRequestFactory get(ClientHttpRequestFactorySettings sett
119109
if (REACTOR_CLIENT_PRESENT) {
120110
return Reactor.get(settings);
121111
}
122-
if (OKHTTP_CLIENT_PRESENT) {
123-
return OkHttp.get(settings);
124-
}
125112
return Simple.get(settings);
126113
}
127114

@@ -135,8 +122,6 @@ public static ClientHttpRequestFactory get(ClientHttpRequestFactorySettings sett
135122
* <li>{@link JdkClientHttpRequestFactory}</li>
136123
* <li>{@link JettyClientHttpRequestFactory}</li>
137124
* <li>{@link ReactorClientHttpRequestFactory}</li>
138-
* <li>{@link org.springframework.http.client.OkHttp3ClientHttpRequestFactory
139-
* OkHttp3ClientHttpRequestFactory} (deprecated)</li>
140125
* <li>{@link SimpleClientHttpRequestFactory}</li>
141126
* </ul>
142127
* A {@code requestFactoryType} of {@link ClientHttpRequestFactory} is equivalent to
@@ -146,7 +131,7 @@ public static ClientHttpRequestFactory get(ClientHttpRequestFactorySettings sett
146131
* @param settings the settings to apply
147132
* @return a new {@link ClientHttpRequestFactory} instance
148133
*/
149-
@SuppressWarnings({ "unchecked", "removal" })
134+
@SuppressWarnings("unchecked")
150135
public static <T extends ClientHttpRequestFactory> T get(Class<T> requestFactoryType,
151136
ClientHttpRequestFactorySettings settings) {
152137
Assert.notNull(settings, "Settings must not be null");
@@ -168,9 +153,6 @@ public static <T extends ClientHttpRequestFactory> T get(Class<T> requestFactory
168153
if (requestFactoryType == SimpleClientHttpRequestFactory.class) {
169154
return (T) Simple.get(settings);
170155
}
171-
if (requestFactoryType == org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class) {
172-
return (T) OkHttp.get(settings);
173-
}
174156
return get(() -> createRequestFactory(requestFactoryType), settings);
175157
}
176158

@@ -237,44 +219,6 @@ private static HttpClient createHttpClient(Duration readTimeout, SslBundle sslBu
237219

238220
}
239221

240-
/**
241-
* Support for
242-
* {@link org.springframework.http.client.OkHttp3ClientHttpRequestFactory}.
243-
*
244-
* @deprecated since 3.2.0 for removal in 3.4.0
245-
*/
246-
@Deprecated(since = "3.2.0", forRemoval = true)
247-
@SuppressWarnings("removal")
248-
static class OkHttp {
249-
250-
static org.springframework.http.client.OkHttp3ClientHttpRequestFactory get(
251-
ClientHttpRequestFactorySettings settings) {
252-
org.springframework.http.client.OkHttp3ClientHttpRequestFactory requestFactory = createRequestFactory(
253-
settings.sslBundle());
254-
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
255-
map.from(settings::connectTimeout).asInt(Duration::toMillis).to(requestFactory::setConnectTimeout);
256-
map.from(settings::readTimeout).asInt(Duration::toMillis).to(requestFactory::setReadTimeout);
257-
return requestFactory;
258-
}
259-
260-
private static org.springframework.http.client.OkHttp3ClientHttpRequestFactory createRequestFactory(
261-
SslBundle sslBundle) {
262-
if (sslBundle != null) {
263-
Assert.state(!sslBundle.getOptions().isSpecified(), "SSL Options cannot be specified with OkHttp");
264-
SSLSocketFactory socketFactory = sslBundle.createSslContext().getSocketFactory();
265-
TrustManager[] trustManagers = sslBundle.getManagers().getTrustManagers();
266-
Assert.state(trustManagers.length == 1,
267-
"Trust material must be provided in the SSL bundle for OkHttp3ClientHttpRequestFactory");
268-
OkHttpClient client = new OkHttpClient.Builder()
269-
.sslSocketFactory(socketFactory, (X509TrustManager) trustManagers[0])
270-
.build();
271-
return new org.springframework.http.client.OkHttp3ClientHttpRequestFactory(client);
272-
}
273-
return new org.springframework.http.client.OkHttp3ClientHttpRequestFactory();
274-
}
275-
276-
}
277-
278222
/**
279223
* Support for {@link JettyClientHttpRequestFactory}.
280224
*/

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesRuntimeHints.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,6 @@ private void registerHints(ReflectionHints hints, ClassLoader classLoader) {
6363
typeHint.onReachableType(HttpURLConnection.class);
6464
registerReflectionHints(hints, SimpleClientHttpRequestFactory.class);
6565
});
66-
registerOkHttpHints(hints, classLoader);
67-
}
68-
69-
@SuppressWarnings("removal")
70-
@Deprecated(since = "3.2.0", forRemoval = true)
71-
private void registerOkHttpHints(ReflectionHints hints, ClassLoader classLoader) {
72-
hints.registerTypeIfPresent(classLoader, ClientHttpRequestFactories.OKHTTP_CLIENT_CLASS, (typeHint) -> {
73-
typeHint.onReachableType(TypeReference.of(ClientHttpRequestFactories.OKHTTP_CLIENT_CLASS));
74-
registerReflectionHints(hints, org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class);
75-
});
76-
7766
}
7867

7968
private void registerReflectionHints(ReflectionHints hints,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author Arjen Poutsma
2929
*/
30-
@ClassPathExclusions({ "httpclient5-*.jar", "okhttp-*.jar" })
30+
@ClassPathExclusions("httpclient5-*.jar")
3131
class ClientHttpRequestFactoriesJettyTests
3232
extends AbstractClientHttpRequestFactoriesTests<JettyClientHttpRequestFactory> {
3333

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

Lines changed: 0 additions & 75 deletions
This file was deleted.

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

Lines changed: 0 additions & 73 deletions
This file was deleted.

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,6 @@ void shouldRegisterHttpComponentHints() {
6161
.accepts(hints);
6262
}
6363

64-
@Test
65-
@Deprecated(since = "3.2.0")
66-
@SuppressWarnings("removal")
67-
void shouldRegisterOkHttpHints() {
68-
RuntimeHints hints = new RuntimeHints();
69-
new ClientHttpRequestFactoriesRuntimeHints().registerHints(hints, getClass().getClassLoader());
70-
ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection();
71-
assertThat(reflection.onMethod(method(org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class,
72-
"setConnectTimeout", int.class)))
73-
.accepts(hints);
74-
assertThat(reflection.onMethod(method(org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class,
75-
"setReadTimeout", int.class)))
76-
.accepts(hints);
77-
assertThat(hints.reflection()
78-
.getTypeHint(org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class)
79-
.methods()).hasSize(2);
80-
}
81-
8264
@Test
8365
void shouldRegisterJettyClientHints() {
8466
RuntimeHints hints = new RuntimeHints();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @author Andy Wilkinson
2828
*/
29-
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "okhttp-*.jar", "reactor-netty-http-*.jar" })
29+
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" })
3030
class ClientHttpRequestFactoriesSimpleTests
3131
extends AbstractClientHttpRequestFactoriesTests<SimpleClientHttpRequestFactory> {
3232

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/HttpWebServiceMessageSenderBuilderSimpleIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
* @author Stephane Nicoll
3636
*/
37-
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "okhttp*.jar", "reactor-netty-http-*.jar" })
37+
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" })
3838
class HttpWebServiceMessageSenderBuilderSimpleIntegrationTests {
3939

4040
private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder();

0 commit comments

Comments
 (0)