mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
26b99c7b08
commit
ed6f52ebe3
@ -84,7 +84,7 @@ public class HttpUtil {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public static String get(final String urlString, final int timeout) {
|
public static String get(final String urlString, final int timeout) {
|
||||||
return ClientEngineFactory.get()
|
return ClientEngineFactory.getEngine()
|
||||||
.setConfig(ClientConfig.of().setConnectionTimeout(timeout).setReadTimeout(timeout))
|
.setConfig(ClientConfig.of().setConnectionTimeout(timeout).setReadTimeout(timeout))
|
||||||
.send(Request.of(urlString)).bodyStr();
|
.send(Request.of(urlString)).bodyStr();
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ public class HttpUtil {
|
|||||||
* @return HTTP响应
|
* @return HTTP响应
|
||||||
*/
|
*/
|
||||||
public static Response send(final Request request){
|
public static Response send(final Request request){
|
||||||
return ClientEngineFactory.get().send(request);
|
return ClientEngineFactory.getEngine().send(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,7 +134,7 @@ public class HttpDownloader {
|
|||||||
private static Response requestDownload(final String url, final int timeout) {
|
private static Response requestDownload(final String url, final int timeout) {
|
||||||
Assert.notBlank(url, "[url] is blank !");
|
Assert.notBlank(url, "[url] is blank !");
|
||||||
|
|
||||||
final Response response = ClientEngineFactory.get()
|
final Response response = ClientEngineFactory.getEngine()
|
||||||
.setConfig(ClientConfig.of().setConnectionTimeout(timeout).setReadTimeout(timeout))
|
.setConfig(ClientConfig.of().setConnectionTimeout(timeout).setReadTimeout(timeout))
|
||||||
.send(Request.of(url));
|
.send(Request.of(url));
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ public class ClientEngineFactory {
|
|||||||
*
|
*
|
||||||
* @return 单例的ClientEngine
|
* @return 单例的ClientEngine
|
||||||
*/
|
*/
|
||||||
public static ClientEngine get() {
|
public static ClientEngine getEngine() {
|
||||||
return Singleton.get(ClientEngine.class.getName(), ClientEngineFactory::of);
|
return Singleton.get(ClientEngine.class.getName(), ClientEngineFactory::getEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,8 +45,8 @@ public class ClientEngineFactory {
|
|||||||
* @return {@code ClientEngine}
|
* @return {@code ClientEngine}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public static ClientEngine of(final ClientConfig config) {
|
public static ClientEngine createEngine(final ClientConfig config) {
|
||||||
return of().setConfig(config);
|
return createEngine().setConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,8 +55,8 @@ public class ClientEngineFactory {
|
|||||||
*
|
*
|
||||||
* @return {@code ClientEngine}
|
* @return {@code ClientEngine}
|
||||||
*/
|
*/
|
||||||
public static ClientEngine of() {
|
public static ClientEngine createEngine() {
|
||||||
final ClientEngine engine = doCreate();
|
final ClientEngine engine = doCreateEngine();
|
||||||
StaticLog.debug("Use [{}] Http Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
|
StaticLog.debug("Use [{}] Http Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ public class ClientEngineFactory {
|
|||||||
*
|
*
|
||||||
* @return {@code EngineFactory}
|
* @return {@code EngineFactory}
|
||||||
*/
|
*/
|
||||||
private static ClientEngine doCreate() {
|
private static ClientEngine doCreateEngine() {
|
||||||
final ClientEngine engine = SpiUtil.loadFirstAvailable(ClientEngine.class);
|
final ClientEngine engine = SpiUtil.loadFirstAvailable(ClientEngine.class);
|
||||||
if (null != engine) {
|
if (null != engine) {
|
||||||
return engine;
|
return engine;
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
|
||||||
<!--
|
|
||||||
~ Copyright (c) 2023 looly(loolly@aliyun.com)
|
|
||||||
~ Hutool is licensed under Mulan PSL v2.
|
|
||||||
~ You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
||||||
~ You may obtain a copy of Mulan PSL v2 at:
|
|
||||||
~ http://license.coscl.org.cn/MulanPSL2
|
|
||||||
~ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
||||||
~ EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
||||||
~ MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
||||||
~ See the Mulan PSL v2 for more details.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>org.dromara.hutool</groupId>
|
|
||||||
<artifactId>hutool-parent</artifactId>
|
|
||||||
<version>6.0.0.M1</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>hutool-http</artifactId>
|
|
||||||
<name>${project.artifactId}</name>
|
|
||||||
<description>Hutool Http客户端</description>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.dromara.hutool</groupId>
|
|
||||||
<artifactId>hutool-core</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.xml.soap</groupId>
|
|
||||||
<artifactId>javax.xml.soap-api</artifactId>
|
|
||||||
<version>1.4.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 第三方HTTP客户端库 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
|
||||||
<artifactId>httpclient5</artifactId>
|
|
||||||
<version>5.1.3</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
|
||||||
<artifactId>httpclient</artifactId>
|
|
||||||
<version>4.5.13</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.dromara.hutool</groupId>
|
|
||||||
<artifactId>hutool-json</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.brotli</groupId>
|
|
||||||
<artifactId>dec</artifactId>
|
|
||||||
<version>0.1.2</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- 仅用于测试 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
<version>1.7.25</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@ -39,7 +39,7 @@ public class DownloadTest {
|
|||||||
@Disabled
|
@Disabled
|
||||||
public void downloadSizeTest() {
|
public void downloadSizeTest() {
|
||||||
final String url = "https://res.t-io.org/im/upload/img/67/8948/1119501/88097554/74541310922/85/231910/366466 - 副本.jpg";
|
final String url = "https://res.t-io.org/im/upload/img/67/8948/1119501/88097554/74541310922/85/231910/366466 - 副本.jpg";
|
||||||
ClientEngineFactory.get().send(Request.of(url)).body().write("e:/pic/366466.jpg");
|
ClientEngineFactory.getEngine().send(Request.of(url)).body().write("e:/pic/366466.jpg");
|
||||||
//HttpRequest.get(url).setSSLProtocol("TLSv1.2").executeAsync().body().write("e:/pic/366466.jpg");
|
//HttpRequest.get(url).setSSLProtocol("TLSv1.2").executeAsync().body().write("e:/pic/366466.jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
public class ClientEngineFactoryTest {
|
public class ClientEngineFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void getTest() {
|
public void getTest() {
|
||||||
final ClientEngine clientEngineFactory = ClientEngineFactory.get();
|
final ClientEngine clientEngineFactory = ClientEngineFactory.getEngine();
|
||||||
Assertions.assertNotNull(clientEngineFactory);
|
Assertions.assertNotNull(clientEngineFactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user