mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
36e560842d
commit
d2e66a1ca2
@ -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>
|
||||
|
@ -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 !");
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
13
hutool-http/src/test/java/cn/hutool/http/client/ClientEngineFactoryTest.java
Executable file
13
hutool-http/src/test/java/cn/hutool/http/client/ClientEngineFactoryTest.java
Executable 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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
1
hutool-http/src/test/resources/simplelogger.properties
Executable file
1
hutool-http/src/test/resources/simplelogger.properties
Executable file
@ -0,0 +1 @@
|
||||
org.slf4j.simpleLogger.defaultLogLevel=debug
|
Loading…
x
Reference in New Issue
Block a user