diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactories.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactories.java index 63b6595ae9b3..1af4d92bc901 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactories.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactories.java @@ -80,10 +80,6 @@ public final class ClientHttpRequestFactories { private static final boolean JETTY_CLIENT_PRESENT = ClassUtils.isPresent(JETTY_CLIENT_CLASS, null); - static final String JDK_CLIENT_CLASS = "java.net.http.HttpClient"; - - private static final boolean JDK_CLIENT_PRESENT = ClassUtils.isPresent(JDK_CLIENT_CLASS, null); - private ClientHttpRequestFactories() { } @@ -104,9 +100,6 @@ public static ClientHttpRequestFactory get(ClientHttpRequestFactorySettings sett if (JETTY_CLIENT_PRESENT) { return Jetty.get(settings); } - if (JDK_CLIENT_PRESENT) { - return Jdk.get(settings); - } return Simple.get(settings); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesJdkClientTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesJdkClientTests.java deleted file mode 100644 index a3dd693ec7b2..000000000000 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesJdkClientTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2023 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.net.http.HttpClient; -import java.time.Duration; - -import org.springframework.boot.testsupport.classpath.ClassPathExclusions; -import org.springframework.http.client.JdkClientHttpRequestFactory; -import org.springframework.test.util.ReflectionTestUtils; - -/** - * Tests for {@link ClientHttpRequestFactories} when JDK HttpClient is the - * predominant HTTP client. - * - * @author Andy Wilkinson - */ -@ClassPathExclusions({ "httpclient5-*.jar", "okhttp-*.jar" }) -class ClientHttpRequestFactoriesJdkClientTests - extends AbstractClientHttpRequestFactoriesTests { - - ClientHttpRequestFactoriesJdkClientTests() { - super(JdkClientHttpRequestFactory.class); - } - - @Override - protected long connectTimeout(JdkClientHttpRequestFactory requestFactory) { - HttpClient httpClient = (HttpClient) ReflectionTestUtils.getField(requestFactory, "httpClient"); - return httpClient.connectTimeout().map(Duration::toMillis).orElse(-1L); - } - - @Override - @SuppressWarnings("unchecked") - protected long readTimeout(JdkClientHttpRequestFactory requestFactory) { - return ((Duration) ReflectionTestUtils.getField(requestFactory, "readTimeout")).toMillis(); - } - -} diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesSimpleTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesSimpleTests.java index 189901f20c42..bb4425484511 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesSimpleTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesSimpleTests.java @@ -26,7 +26,7 @@ * * @author Andy Wilkinson */ -@ClassPathExclusions(files = {"httpclient5-*.jar", "jetty-client-*.jar", "okhttp-*.jar"}, packages = "java.net.http") +@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "okhttp-*.jar" }) class ClientHttpRequestFactoriesSimpleTests extends AbstractClientHttpRequestFactoriesTests { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesTests.java index 546b862d987a..239023e8b9c0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesTests.java @@ -27,6 +27,7 @@ import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.client.JdkClientHttpRequestFactory; import org.springframework.http.client.OkHttp3ClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; @@ -75,6 +76,13 @@ void getOfOkHttpFactoryReturnsOkHttpFactory() { assertThat(requestFactory).isInstanceOf(OkHttp3ClientHttpRequestFactory.class); } + @Test + void getOfJdkFactoryReturnsJdkFactory() { + ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories.get(JdkClientHttpRequestFactory.class, + ClientHttpRequestFactorySettings.DEFAULTS); + assertThat(requestFactory).isInstanceOf(JdkClientHttpRequestFactory.class); + } + @Test void getOfUnknownTypeCreatesFactory() { ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories.get(TestClientHttpRequestFactory.class, diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/HttpWebServiceMessageSenderBuilderSimpleIntegrationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/HttpWebServiceMessageSenderBuilderSimpleIntegrationTests.java index 5872c3a092dc..6c3a0b2ef18e 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/HttpWebServiceMessageSenderBuilderSimpleIntegrationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/HttpWebServiceMessageSenderBuilderSimpleIntegrationTests.java @@ -34,7 +34,7 @@ * * @author Stephane Nicoll */ -@ClassPathExclusions(files = { "httpclient5-*.jar", "jetty-client-*.jar", "okhttp*.jar" }, packages = "java.net.http") +@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "okhttp*.jar" }) class HttpWebServiceMessageSenderBuilderSimpleIntegrationTests { private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder();