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客户端引擎对象
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎