mirror of
https://gitee.com/dromara/hutool.git
synced 2025-12-20 03:50:01 +08:00
add: 创建自定义引擎方法
This commit is contained in:
@@ -25,6 +25,8 @@ import org.dromara.hutool.http.client.ApacheHttpClientConfig;
|
|||||||
import org.dromara.hutool.http.client.ClientConfig;
|
import org.dromara.hutool.http.client.ClientConfig;
|
||||||
import org.dromara.hutool.log.LogUtil;
|
import org.dromara.hutool.log.LogUtil;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Http客户端引擎工厂类
|
* Http客户端引擎工厂类
|
||||||
*
|
*
|
||||||
@@ -82,6 +84,20 @@ public class ClientEngineFactory {
|
|||||||
throw new HttpException("No such engine named: " + engineName);
|
throw new HttpException("No such engine named: " + engineName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建自定义引擎
|
||||||
|
*
|
||||||
|
* @param engineType 引擎类型
|
||||||
|
* @return 引擎
|
||||||
|
* @throws HttpException 无对应名称的引擎
|
||||||
|
*/
|
||||||
|
public static ClientEngine createEngine(Class<? extends ClientEngine> engineType) throws HttpException {
|
||||||
|
if (engineType == null) {
|
||||||
|
throw new HttpException("No such engine name");
|
||||||
|
}
|
||||||
|
return ClientEngineFactory.createEngine(engineType.getName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户引入的HTTP客户端引擎jar,自动创建对应的HTTP客户端引擎对象<br>
|
* 根据用户引入的HTTP客户端引擎jar,自动创建对应的HTTP客户端引擎对象<br>
|
||||||
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎
|
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎
|
||||||
|
|||||||
Reference in New Issue
Block a user