This commit is contained in:
Looly 2022-10-26 12:57:01 +08:00
parent 36e560842d
commit d2e66a1ca2
7 changed files with 76 additions and 14 deletions

View File

@ -22,6 +22,11 @@
<artifactId>hutool-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-log</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>

View File

@ -0,0 +1,53 @@
package cn.hutool.http.client.engine;
import cn.hutool.core.lang.Singleton;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.ServiceLoaderUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.client.ClientEngine;
import cn.hutool.log.StaticLog;
/**
* Http客户端引擎工厂类
*
* @author looly
* @since 6.0.0
*/
public class ClientEngineFactory {
/**
* 获得单例的ClientEngine
*
* @return 单例的ClientEngine
*/
public static ClientEngine get() {
return Singleton.get(ClientEngine.class.getName(), ClientEngineFactory::of);
}
/**
* 根据用户引入的拼音引擎jar自动创建对应的拼音引擎对象<br>
* 推荐创建的引擎单例使用此方法每次调用会返回新的引擎
*
* @return {@code ClientEngine}
*/
public static ClientEngine of() {
final ClientEngine engine = doCreate();
StaticLog.debug("Use [{}] Http Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
return engine;
}
/**
* 根据用户引入的拼音引擎jar自动创建对应的拼音引擎对象<br>
* 推荐创建的引擎单例使用此方法每次调用会返回新的引擎
*
* @return {@code EngineFactory}
*/
private static ClientEngine doCreate() {
final ClientEngine engine = ServiceLoaderUtil.loadFirstAvailable(ClientEngine.class);
if (null != engine) {
return engine;
}
throw new HttpException("No http jar found ! Please add one of it to your project !");
}
}

View File

@ -1,13 +0,0 @@
package cn.hutool.http.client.engine;
import cn.hutool.http.client.ClientEngine;
/**
* Http客户端引擎工厂类
*/
public class EngineFactory {
public static ClientEngine getEngine(){
return null;
}
}

View File

@ -0,0 +1,3 @@
cn.hutool.http.client.engine.httpclient5.HttpClient5Engine
cn.hutool.http.client.engine.httpclient4.HttpClient4Engine
cn.hutool.http.client.engine.okhttp.OkHttpEngine

View File

@ -0,0 +1,13 @@
package cn.hutool.http.client;
import cn.hutool.http.client.engine.ClientEngineFactory;
import org.junit.Assert;
import org.junit.Test;
public class ClientEngineFactoryTest {
@Test
public void getTest() {
final ClientEngine clientEngineFactory = ClientEngineFactory.get();
Assert.assertNotNull(clientEngineFactory);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.http.client;
import cn.hutool.core.lang.Console;
import cn.hutool.http.meta.Method;
import cn.hutool.http.client.engine.httpclient4.HttpClient4Engine;
import cn.hutool.http.meta.Method;
import org.junit.Ignore;
import org.junit.Test;

View File

@ -0,0 +1 @@
org.slf4j.simpleLogger.defaultLogLevel=debug