From cf0c1c1dbe3b0c7c8c7ec1f1e27b62a3a30e7657 Mon Sep 17 00:00:00 2001 From: Toint <599818663@qq.com> Date: Sun, 16 Mar 2025 08:30:08 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=88=9B=E5=BB=BA=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=BC=95=E6=93=8E=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../http/client/engine/ClientEngineFactory.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 9f1ce55e6..83706700a 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 @@ -25,6 +25,8 @@ import org.dromara.hutool.http.client.ApacheHttpClientConfig; import org.dromara.hutool.http.client.ClientConfig; import org.dromara.hutool.log.LogUtil; +import java.util.Objects; + /** * Http客户端引擎工厂类 * @@ -82,6 +84,20 @@ public class ClientEngineFactory { throw new HttpException("No such engine named: " + engineName); } + /** + * 创建自定义引擎 + * + * @param engineType 引擎类型 + * @return 引擎 + * @throws HttpException 无对应名称的引擎 + */ + public static ClientEngine createEngine(Class engineType) throws HttpException { + if (engineType == null) { + throw new HttpException("No such engine name"); + } + return ClientEngineFactory.createEngine(engineType.getName()); + } + /** * 根据用户引入的HTTP客户端引擎jar,自动创建对应的HTTP客户端引擎对象
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎