Remove deprecated support for OkHTTP

Closes gh-42780
This commit is contained in:
Andy Wilkinson
2024-10-18 11:03:07 +01:00
parent 68ed4b1d4f
commit 6161ef7581
11 changed files with 11 additions and 245 deletions

View File

@@ -1441,13 +1441,6 @@ bom {
site("https://netty.io")
}
}
library("OkHttp", "4.12.0") {
group("com.squareup.okhttp3") {
imports = [
"okhttp-bom"
]
}
}
library("OpenTelemetry", "1.43.0") {
group("io.opentelemetry") {
imports = [

View File

@@ -158,6 +158,13 @@ bom {
]
}
}
library("OkHttp", "4.12.0") {
group("com.squareup.okhttp3") {
imports = [
"okhttp-bom"
]
}
}
library("OpenTelemetry Logback Appender", "2.7.0-alpha") {
group("io.opentelemetry.instrumentation") {
modules = [

View File

@@ -29,7 +29,6 @@ dependencies {
optional("com.oracle.database.jdbc:ucp11")
optional("com.oracle.database.jdbc:ojdbc11")
optional("com.samskivert:jmustache")
optional("com.squareup.okhttp3:okhttp")
optional("com.zaxxer:HikariCP")
optional("io.netty:netty-tcnative-boringssl-static")
optional("io.projectreactor:reactor-tools")

View File

@@ -29,11 +29,8 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import io.netty.handler.ssl.SslContextBuilder;
import okhttp3.OkHttpClient;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
@@ -77,10 +74,6 @@ public final class ClientHttpRequestFactories {
private static final boolean APACHE_HTTP_CLIENT_PRESENT = ClassUtils.isPresent(APACHE_HTTP_CLIENT_CLASS, null);
static final String OKHTTP_CLIENT_CLASS = "okhttp3.OkHttpClient";
private static final boolean OKHTTP_CLIENT_PRESENT = ClassUtils.isPresent(OKHTTP_CLIENT_CLASS, null);
static final String JETTY_CLIENT_CLASS = "org.eclipse.jetty.client.HttpClient";
private static final boolean JETTY_CLIENT_PRESENT = ClassUtils.isPresent(JETTY_CLIENT_CLASS, null);
@@ -100,14 +93,11 @@ public final class ClientHttpRequestFactories {
* <li>{@link HttpComponentsClientHttpRequestFactory}</li>
* <li>{@link JettyClientHttpRequestFactory}</li>
* <li>{@link ReactorClientHttpRequestFactory}</li>
* <li>{@link org.springframework.http.client.OkHttp3ClientHttpRequestFactory
* OkHttp3ClientHttpRequestFactory} (deprecated)</li>
* <li>{@link SimpleClientHttpRequestFactory}</li>
* </ol>
* @param settings the settings to apply
* @return a new {@link ClientHttpRequestFactory}
*/
@SuppressWarnings("removal")
public static ClientHttpRequestFactory get(ClientHttpRequestFactorySettings settings) {
Assert.notNull(settings, "Settings must not be null");
if (APACHE_HTTP_CLIENT_PRESENT) {
@@ -119,9 +109,6 @@ public final class ClientHttpRequestFactories {
if (REACTOR_CLIENT_PRESENT) {
return Reactor.get(settings);
}
if (OKHTTP_CLIENT_PRESENT) {
return OkHttp.get(settings);
}
return Simple.get(settings);
}
@@ -135,8 +122,6 @@ public final class ClientHttpRequestFactories {
* <li>{@link JdkClientHttpRequestFactory}</li>
* <li>{@link JettyClientHttpRequestFactory}</li>
* <li>{@link ReactorClientHttpRequestFactory}</li>
* <li>{@link org.springframework.http.client.OkHttp3ClientHttpRequestFactory
* OkHttp3ClientHttpRequestFactory} (deprecated)</li>
* <li>{@link SimpleClientHttpRequestFactory}</li>
* </ul>
* A {@code requestFactoryType} of {@link ClientHttpRequestFactory} is equivalent to
@@ -146,7 +131,7 @@ public final class ClientHttpRequestFactories {
* @param settings the settings to apply
* @return a new {@link ClientHttpRequestFactory} instance
*/
@SuppressWarnings({ "unchecked", "removal" })
@SuppressWarnings("unchecked")
public static <T extends ClientHttpRequestFactory> T get(Class<T> requestFactoryType,
ClientHttpRequestFactorySettings settings) {
Assert.notNull(settings, "Settings must not be null");
@@ -168,9 +153,6 @@ public final class ClientHttpRequestFactories {
if (requestFactoryType == SimpleClientHttpRequestFactory.class) {
return (T) Simple.get(settings);
}
if (requestFactoryType == org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class) {
return (T) OkHttp.get(settings);
}
return get(() -> createRequestFactory(requestFactoryType), settings);
}
@@ -237,44 +219,6 @@ public final class ClientHttpRequestFactories {
}
/**
* Support for
* {@link org.springframework.http.client.OkHttp3ClientHttpRequestFactory}.
*
* @deprecated since 3.2.0 for removal in 3.4.0
*/
@Deprecated(since = "3.2.0", forRemoval = true)
@SuppressWarnings("removal")
static class OkHttp {
static org.springframework.http.client.OkHttp3ClientHttpRequestFactory get(
ClientHttpRequestFactorySettings settings) {
org.springframework.http.client.OkHttp3ClientHttpRequestFactory requestFactory = createRequestFactory(
settings.sslBundle());
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(settings::connectTimeout).asInt(Duration::toMillis).to(requestFactory::setConnectTimeout);
map.from(settings::readTimeout).asInt(Duration::toMillis).to(requestFactory::setReadTimeout);
return requestFactory;
}
private static org.springframework.http.client.OkHttp3ClientHttpRequestFactory createRequestFactory(
SslBundle sslBundle) {
if (sslBundle != null) {
Assert.state(!sslBundle.getOptions().isSpecified(), "SSL Options cannot be specified with OkHttp");
SSLSocketFactory socketFactory = sslBundle.createSslContext().getSocketFactory();
TrustManager[] trustManagers = sslBundle.getManagers().getTrustManagers();
Assert.state(trustManagers.length == 1,
"Trust material must be provided in the SSL bundle for OkHttp3ClientHttpRequestFactory");
OkHttpClient client = new OkHttpClient.Builder()
.sslSocketFactory(socketFactory, (X509TrustManager) trustManagers[0])
.build();
return new org.springframework.http.client.OkHttp3ClientHttpRequestFactory(client);
}
return new org.springframework.http.client.OkHttp3ClientHttpRequestFactory();
}
}
/**
* Support for {@link JettyClientHttpRequestFactory}.
*/

View File

@@ -63,17 +63,6 @@ class ClientHttpRequestFactoriesRuntimeHints implements RuntimeHintsRegistrar {
typeHint.onReachableType(HttpURLConnection.class);
registerReflectionHints(hints, SimpleClientHttpRequestFactory.class);
});
registerOkHttpHints(hints, classLoader);
}
@SuppressWarnings("removal")
@Deprecated(since = "3.2.0", forRemoval = true)
private void registerOkHttpHints(ReflectionHints hints, ClassLoader classLoader) {
hints.registerTypeIfPresent(classLoader, ClientHttpRequestFactories.OKHTTP_CLIENT_CLASS, (typeHint) -> {
typeHint.onReachableType(TypeReference.of(ClientHttpRequestFactories.OKHTTP_CLIENT_CLASS));
registerReflectionHints(hints, org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class);
});
}
private void registerReflectionHints(ReflectionHints hints,

View File

@@ -27,7 +27,7 @@ import org.springframework.test.util.ReflectionTestUtils;
*
* @author Arjen Poutsma
*/
@ClassPathExclusions({ "httpclient5-*.jar", "okhttp-*.jar" })
@ClassPathExclusions("httpclient5-*.jar")
class ClientHttpRequestFactoriesJettyTests
extends AbstractClientHttpRequestFactoriesTests<JettyClientHttpRequestFactory> {

View File

@@ -1,75 +0,0 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.web.client;
import java.io.File;
import okhttp3.OkHttpClient;
import org.junit.jupiter.api.Test;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ClientHttpRequestFactories} when OkHttp 3 is the predominant HTTP
* client.
*
* @author Andy Wilkinson
* @deprecated since 3.2.0 for removal in 3.4.0
*/
@ClassPathOverrides("com.squareup.okhttp3:okhttp:3.14.9")
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" })
@Deprecated(since = "3.2.0", forRemoval = true)
@SuppressWarnings("removal")
class ClientHttpRequestFactoriesOkHttp3Tests
extends AbstractClientHttpRequestFactoriesTests<OkHttp3ClientHttpRequestFactory> {
ClientHttpRequestFactoriesOkHttp3Tests() {
super(OkHttp3ClientHttpRequestFactory.class);
}
@Test
void okHttp3IsBeingUsed() {
assertThat(new File(OkHttpClient.class.getProtectionDomain().getCodeSource().getLocation().getFile()).getName())
.startsWith("okhttp-3.");
}
@Override
protected long connectTimeout(OkHttp3ClientHttpRequestFactory requestFactory) {
return ((OkHttpClient) ReflectionTestUtils.getField(requestFactory, "client")).connectTimeoutMillis();
}
@Override
protected long readTimeout(OkHttp3ClientHttpRequestFactory requestFactory) {
return ((OkHttpClient) ReflectionTestUtils.getField(requestFactory, "client")).readTimeoutMillis();
}
@Override
protected boolean supportsSettingConnectTimeout() {
return true;
}
@Override
protected boolean supportsSettingReadTimeout() {
return true;
}
}

View File

@@ -1,73 +0,0 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.web.client;
import java.io.File;
import okhttp3.OkHttpClient;
import org.junit.jupiter.api.Test;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ClientHttpRequestFactories} when OkHttp 4 is the predominant HTTP
* client.
*
* @author Andy Wilkinson
* @deprecated since 3.2.0 for removal in 3.4.0
*/
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" })
@Deprecated(since = "3.2.0", forRemoval = true)
@SuppressWarnings("removal")
class ClientHttpRequestFactoriesOkHttp4Tests
extends AbstractClientHttpRequestFactoriesTests<OkHttp3ClientHttpRequestFactory> {
ClientHttpRequestFactoriesOkHttp4Tests() {
super(OkHttp3ClientHttpRequestFactory.class);
}
@Test
void okHttp4IsBeingUsed() {
assertThat(new File(OkHttpClient.class.getProtectionDomain().getCodeSource().getLocation().getFile()).getName())
.startsWith("okhttp-4.");
}
@Override
protected long connectTimeout(OkHttp3ClientHttpRequestFactory requestFactory) {
return ((OkHttpClient) ReflectionTestUtils.getField(requestFactory, "client")).connectTimeoutMillis();
}
@Override
protected long readTimeout(OkHttp3ClientHttpRequestFactory requestFactory) {
return ((OkHttpClient) ReflectionTestUtils.getField(requestFactory, "client")).readTimeoutMillis();
}
@Override
protected boolean supportsSettingConnectTimeout() {
return true;
}
@Override
protected boolean supportsSettingReadTimeout() {
return true;
}
}

View File

@@ -61,24 +61,6 @@ class ClientHttpRequestFactoriesRuntimeHintsTests {
.accepts(hints);
}
@Test
@Deprecated(since = "3.2.0")
@SuppressWarnings("removal")
void shouldRegisterOkHttpHints() {
RuntimeHints hints = new RuntimeHints();
new ClientHttpRequestFactoriesRuntimeHints().registerHints(hints, getClass().getClassLoader());
ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection();
assertThat(reflection.onMethod(method(org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class,
"setConnectTimeout", int.class)))
.accepts(hints);
assertThat(reflection.onMethod(method(org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class,
"setReadTimeout", int.class)))
.accepts(hints);
assertThat(hints.reflection()
.getTypeHint(org.springframework.http.client.OkHttp3ClientHttpRequestFactory.class)
.methods()).hasSize(2);
}
@Test
void shouldRegisterJettyClientHints() {
RuntimeHints hints = new RuntimeHints();

View File

@@ -26,7 +26,7 @@ import org.springframework.test.util.ReflectionTestUtils;
*
* @author Andy Wilkinson
*/
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "okhttp-*.jar", "reactor-netty-http-*.jar" })
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" })
class ClientHttpRequestFactoriesSimpleTests
extends AbstractClientHttpRequestFactoriesTests<SimpleClientHttpRequestFactory> {

View File

@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Stephane Nicoll
*/
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "okhttp*.jar", "reactor-netty-http-*.jar" })
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" })
class HttpWebServiceMessageSenderBuilderSimpleIntegrationTests {
private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder();