From ed6f52ebe33c5d0b04257e287f1b57dca8628664 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 24 Apr 2023 12:20:29 +0800 Subject: [PATCH] fix code --- .../org/dromara/hutool/http/HttpUtil.java | 4 +- .../hutool/http/client/HttpDownloader.java | 2 +- .../client/engine/ClientEngineFactory.java | 14 ++-- .../http/client/engine/httpclient4/pom.xml | 78 ------------------- .../org/dromara/hutool/http/DownloadTest.java | 2 +- .../http/client/ClientEngineFactoryTest.java | 2 +- 6 files changed, 12 insertions(+), 90 deletions(-) delete mode 100644 hutool-http/src/main/java/org/dromara/hutool/http/client/engine/httpclient4/pom.xml diff --git a/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java b/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java index 7f61e1926..bc7079d3d 100644 --- a/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java +++ b/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java @@ -84,7 +84,7 @@ public class HttpUtil { */ @SuppressWarnings("resource") public static String get(final String urlString, final int timeout) { - return ClientEngineFactory.get() + return ClientEngineFactory.getEngine() .setConfig(ClientConfig.of().setConnectionTimeout(timeout).setReadTimeout(timeout)) .send(Request.of(urlString)).bodyStr(); } @@ -141,7 +141,7 @@ public class HttpUtil { * @return HTTP响应 */ public static Response send(final Request request){ - return ClientEngineFactory.get().send(request); + return ClientEngineFactory.getEngine().send(request); } /** diff --git a/hutool-http/src/main/java/org/dromara/hutool/http/client/HttpDownloader.java b/hutool-http/src/main/java/org/dromara/hutool/http/client/HttpDownloader.java index 707c4da2b..9ec253517 100644 --- a/hutool-http/src/main/java/org/dromara/hutool/http/client/HttpDownloader.java +++ b/hutool-http/src/main/java/org/dromara/hutool/http/client/HttpDownloader.java @@ -134,7 +134,7 @@ public class HttpDownloader { private static Response requestDownload(final String url, final int timeout) { Assert.notBlank(url, "[url] is blank !"); - final Response response = ClientEngineFactory.get() + final Response response = ClientEngineFactory.getEngine() .setConfig(ClientConfig.of().setConnectionTimeout(timeout).setReadTimeout(timeout)) .send(Request.of(url)); diff --git a/hutool-http/src/main/java/org/dromara/hutool/http/client/engine/ClientEngineFactory.java b/hutool-http/src/main/java/org/dromara/hutool/http/client/engine/ClientEngineFactory.java index c96605bca..b512c4a81 100644 --- a/hutool-http/src/main/java/org/dromara/hutool/http/client/engine/ClientEngineFactory.java +++ b/hutool-http/src/main/java/org/dromara/hutool/http/client/engine/ClientEngineFactory.java @@ -33,8 +33,8 @@ public class ClientEngineFactory { * * @return 单例的ClientEngine */ - public static ClientEngine get() { - return Singleton.get(ClientEngine.class.getName(), ClientEngineFactory::of); + public static ClientEngine getEngine() { + return Singleton.get(ClientEngine.class.getName(), ClientEngineFactory::getEngine); } /** @@ -45,8 +45,8 @@ public class ClientEngineFactory { * @return {@code ClientEngine} */ @SuppressWarnings("resource") - public static ClientEngine of(final ClientConfig config) { - return of().setConfig(config); + public static ClientEngine createEngine(final ClientConfig config) { + return createEngine().setConfig(config); } /** @@ -55,8 +55,8 @@ public class ClientEngineFactory { * * @return {@code ClientEngine} */ - public static ClientEngine of() { - final ClientEngine engine = doCreate(); + public static ClientEngine createEngine() { + final ClientEngine engine = doCreateEngine(); StaticLog.debug("Use [{}] Http Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine")); return engine; } @@ -67,7 +67,7 @@ public class ClientEngineFactory { * * @return {@code EngineFactory} */ - private static ClientEngine doCreate() { + private static ClientEngine doCreateEngine() { final ClientEngine engine = SpiUtil.loadFirstAvailable(ClientEngine.class); if (null != engine) { return engine; diff --git a/hutool-http/src/main/java/org/dromara/hutool/http/client/engine/httpclient4/pom.xml b/hutool-http/src/main/java/org/dromara/hutool/http/client/engine/httpclient4/pom.xml deleted file mode 100644 index c11cf402e..000000000 --- a/hutool-http/src/main/java/org/dromara/hutool/http/client/engine/httpclient4/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - 4.0.0 - - jar - - - org.dromara.hutool - hutool-parent - 6.0.0.M1 - - - hutool-http - ${project.artifactId} - Hutool Http客户端 - - - - org.dromara.hutool - hutool-core - ${project.parent.version} - - - javax.xml.soap - javax.xml.soap-api - 1.4.0 - provided - - - - - org.apache.httpcomponents.client5 - httpclient5 - 5.1.3 - provided - - - org.apache.httpcomponents - httpclient - 4.5.13 - provided - - - - org.dromara.hutool - hutool-json - ${project.parent.version} - test - - - org.brotli - dec - 0.1.2 - test - - - - org.slf4j - slf4j-simple - 1.7.25 - test - - - diff --git a/hutool-http/src/test/java/org/dromara/hutool/http/DownloadTest.java b/hutool-http/src/test/java/org/dromara/hutool/http/DownloadTest.java index 72728b9a3..ae986a685 100644 --- a/hutool-http/src/test/java/org/dromara/hutool/http/DownloadTest.java +++ b/hutool-http/src/test/java/org/dromara/hutool/http/DownloadTest.java @@ -39,7 +39,7 @@ public class DownloadTest { @Disabled public void downloadSizeTest() { final String url = "https://res.t-io.org/im/upload/img/67/8948/1119501/88097554/74541310922/85/231910/366466 - 副本.jpg"; - ClientEngineFactory.get().send(Request.of(url)).body().write("e:/pic/366466.jpg"); + ClientEngineFactory.getEngine().send(Request.of(url)).body().write("e:/pic/366466.jpg"); //HttpRequest.get(url).setSSLProtocol("TLSv1.2").executeAsync().body().write("e:/pic/366466.jpg"); } diff --git a/hutool-http/src/test/java/org/dromara/hutool/http/client/ClientEngineFactoryTest.java b/hutool-http/src/test/java/org/dromara/hutool/http/client/ClientEngineFactoryTest.java index dc8582ecd..00bb301cb 100644 --- a/hutool-http/src/test/java/org/dromara/hutool/http/client/ClientEngineFactoryTest.java +++ b/hutool-http/src/test/java/org/dromara/hutool/http/client/ClientEngineFactoryTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; public class ClientEngineFactoryTest { @Test public void getTest() { - final ClientEngine clientEngineFactory = ClientEngineFactory.get(); + final ClientEngine clientEngineFactory = ClientEngineFactory.getEngine(); Assertions.assertNotNull(clientEngineFactory); } }