19 Commits
Author SHA1 Message Date
timi f4c5620ffb Merge pull request 'v0.0.14' (#19) from dev into master
Reviewed-on: #19
2026-08-07 07:45:34 +00:00
timi f073b8d7ad Merge pull request 'v0.0.13' (#18) from dev into master
Reviewed-on: #18
2026-07-23 07:10:59 +00:00
timi a1b6bf62df Merge pull request 'v0.0.12' (#17) from dev into master
Reviewed-on: #17
2026-06-30 07:41:11 +00:00
timi 21c19af696 Merge pull request 'v0.0.11' (#16) from dev into master
Reviewed-on: #16
2026-06-04 10:35:40 +00:00
timi fc04d50d0f Merge pull request 'v0.0.10' (#15) from dev into master
Reviewed-on: #15
2026-05-07 07:06:53 +00:00
timi 515387dd32 Merge pull request 'v0.0.9' (#14) from dev into master
Reviewed-on: #14
2026-05-06 09:27:58 +00:00
timi 9fb406427f Merge pull request 'v0.0.8' (#13) from dev into master
Reviewed-on: #13
2026-03-25 07:41:06 +00:00
timi 386fded0a3 Merge pull request 'v0.0.8' (#12) from dev into master
Reviewed-on: #12
2026-03-25 07:32:57 +00:00
timi 88fdc79c82 Merge pull request 'v0.0.8' (#11) from dev into master
Reviewed-on: #11
2026-03-25 07:25:09 +00:00
timi 571ed377a8 Merge pull request 'v0.0.8' (#10) from dev into master
Reviewed-on: #10
2026-03-25 07:22:40 +00:00
timi 6b84af1f16 Merge pull request 'v0.0.8' (#9) from dev into master
Reviewed-on: #9
2026-03-25 07:04:17 +00:00
timi 4302084b95 Merge pull request 'v0.0.8' (#8) from dev into master
Reviewed-on: #8
2026-03-25 06:48:12 +00:00
timi 4f8054dc94 Merge pull request 'v0.0.7' (#7) from dev into master
Reviewed-on: #7
2026-03-17 08:40:14 +00:00
timi 5c1e1ee52c Merge pull request 'v0.0.6' (#6) from dev into master
Reviewed-on: #6
2026-03-17 03:02:07 +00:00
timi 01074e1ac2 Merge pull request 'v0.0.5' (#5) from dev into master
Reviewed-on: #5
2026-03-16 09:13:40 +00:00
timi 1b60210c06 Merge pull request 'v0.0.4' (#4) from dev into master
Reviewed-on: #4
2026-03-09 03:14:26 +00:00
timi 2290ac5ecf Merge pull request 'v0.0.3' (#3) from dev into master
Reviewed-on: #3
2026-02-10 07:31:09 +00:00
timi 6101e8d462 Merge pull request 'v0.0.3' (#2) from dev into master
Reviewed-on: #2
2026-02-10 07:22:43 +00:00
timi aaea3a218b Merge pull request 'v0.0.2' (#1) from dev into master
Reviewed-on: #1
2026-01-19 10:00:36 +00:00
8 changed files with 14 additions and 230 deletions
+1 -12
View File
@@ -1,14 +1,3 @@
# timi-network # timi-network
Java 网络操作工具 Java 网络操作工具
静态工厂方法按 HTTP 方法命名,支持 `get`、`post`、`put`、`patch`、`delete`、`head` 和 `options`,分别用于读取、创建、替换、部分更新、删除资源、获取响应头和查询支持的请求方法
`CommonRequest`、`JacksonRequest`、`FileRequest` 和 `TimiRequest` 的工厂方法均返回对应类型,`ProgressiveRequest` 的工厂方法额外接收进度回调
```java
JacksonRequest.put("https://example.com/users/1").body(user).execute();
JacksonRequest.patch("https://example.com/users/1").body(changes).execute();
CommonRequest.delete("https://example.com/users/1").execute();
long length = FileRequest.head("https://example.com/files/1").length();
```
+2 -2
View File
@@ -6,7 +6,7 @@
<groupId>com.imyeyu.network</groupId> <groupId>com.imyeyu.network</groupId>
<artifactId>timi-network</artifactId> <artifactId>timi-network</artifactId>
<version>0.2.0</version> <version>0.0.14</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
@@ -106,7 +106,7 @@
<dependency> <dependency>
<groupId>com.imyeyu.io</groupId> <groupId>com.imyeyu.io</groupId>
<artifactId>timi-io</artifactId> <artifactId>timi-io</artifactId>
<version>0.1.0</version> <version>0.0.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents.client5</groupId> <groupId>org.apache.httpcomponents.client5</groupId>
@@ -39,46 +39,6 @@ public class CommonRequest {
return new CommonRequest(Request.post(url)); return new CommonRequest(Request.post(url));
} }
/// 创建 PUT 请求,用于替换资源
///
/// @param url 请求地址
/// @return CommonRequest 请求
public static CommonRequest put(String url) {
return new CommonRequest(Request.put(url));
}
/// 创建 PATCH 请求,用于部分更新资源
///
/// @param url 请求地址
/// @return CommonRequest 请求
public static CommonRequest patch(String url) {
return new CommonRequest(Request.patch(url));
}
/// 创建 DELETE 请求,用于删除资源
///
/// @param url 请求地址
/// @return CommonRequest 请求
public static CommonRequest delete(String url) {
return new CommonRequest(Request.delete(url));
}
/// 创建 HEAD 请求,用于获取响应头
///
/// @param url 请求地址
/// @return CommonRequest 请求
public static CommonRequest head(String url) {
return new CommonRequest(Request.head(url));
}
/// 创建 OPTIONS 请求,用于查询支持的请求方法
///
/// @param url 请求地址
/// @return CommonRequest 请求
public static CommonRequest options(String url) {
return new CommonRequest(Request.options(url));
}
public CommonRequest timeout(long ms) { public CommonRequest timeout(long ms) {
if (0 < ms) { if (0 < ms) {
request.connectTimeout(Timeout.ofMilliseconds(ms)).responseTimeout(Timeout.ofMilliseconds(ms)); request.connectTimeout(Timeout.ofMilliseconds(ms)).responseTimeout(Timeout.ofMilliseconds(ms));
@@ -36,46 +36,6 @@ public class FileRequest extends JacksonRequest {
return new FileRequest(Request.post(url)); return new FileRequest(Request.post(url));
} }
/// 创建 PUT 请求,用于替换资源
///
/// @param url 请求地址
/// @return FileRequest 请求
public static FileRequest put(String url) {
return new FileRequest(Request.put(url));
}
/// 创建 PATCH 请求,用于部分更新资源
///
/// @param url 请求地址
/// @return FileRequest 请求
public static FileRequest patch(String url) {
return new FileRequest(Request.patch(url));
}
/// 创建 DELETE 请求,用于删除资源
///
/// @param url 请求地址
/// @return FileRequest 请求
public static FileRequest delete(String url) {
return new FileRequest(Request.delete(url));
}
/// 创建 HEAD 请求,用于获取响应头
///
/// @param url 请求地址
/// @return FileRequest 请求
public static FileRequest head(String url) {
return new FileRequest(Request.head(url));
}
/// 创建 OPTIONS 请求,用于查询支持的请求方法
///
/// @param url 请求地址
/// @return FileRequest 请求
public static FileRequest options(String url) {
return new FileRequest(Request.options(url));
}
@Override @Override
public FileRequest timeout(long ms) { public FileRequest timeout(long ms) {
super.timeout(ms); super.timeout(ms);
@@ -31,7 +31,7 @@ public class JacksonRequest extends CommonRequest {
static { static {
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
OBJECT_MAPPER.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); OBJECT_MAPPER.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
OBJECT_MAPPER.setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL); OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
} }
private ObjectMapper objectMapper = null; private ObjectMapper objectMapper = null;
@@ -82,46 +82,6 @@ public class JacksonRequest extends CommonRequest {
return new JacksonRequest(Request.post(url)); return new JacksonRequest(Request.post(url));
} }
/// 创建 PUT 请求,用于替换资源
///
/// @param url 请求地址
/// @return JacksonRequest 请求
public static JacksonRequest put(String url) {
return new JacksonRequest(Request.put(url));
}
/// 创建 PATCH 请求,用于部分更新资源
///
/// @param url 请求地址
/// @return JacksonRequest 请求
public static JacksonRequest patch(String url) {
return new JacksonRequest(Request.patch(url));
}
/// 创建 DELETE 请求,用于删除资源
///
/// @param url 请求地址
/// @return JacksonRequest 请求
public static JacksonRequest delete(String url) {
return new JacksonRequest(Request.delete(url));
}
/// 创建 HEAD 请求,用于获取响应头
///
/// @param url 请求地址
/// @return JacksonRequest 请求
public static JacksonRequest head(String url) {
return new JacksonRequest(Request.head(url));
}
/// 创建 OPTIONS 请求,用于查询支持的请求方法
///
/// @param url 请求地址
/// @return JacksonRequest 请求
public static JacksonRequest options(String url) {
return new JacksonRequest(Request.options(url));
}
/** /**
* 指定对象映射器。 * 指定对象映射器。
* *
@@ -43,51 +43,6 @@ public class ProgressiveRequest extends FileRequest {
return new ProgressiveRequest(Request.post(url), callback); return new ProgressiveRequest(Request.post(url), callback);
} }
/// 创建 PUT 请求,用于替换资源
///
/// @param url 请求地址
/// @param callback 进度回调
/// @return ProgressiveRequest 请求
public static ProgressiveRequest put(String url, ProgressiveCallback callback) {
return new ProgressiveRequest(Request.put(url), callback);
}
/// 创建 PATCH 请求,用于部分更新资源
///
/// @param url 请求地址
/// @param callback 进度回调
/// @return ProgressiveRequest 请求
public static ProgressiveRequest patch(String url, ProgressiveCallback callback) {
return new ProgressiveRequest(Request.patch(url), callback);
}
/// 创建 DELETE 请求,用于删除资源
///
/// @param url 请求地址
/// @param callback 进度回调
/// @return ProgressiveRequest 请求
public static ProgressiveRequest delete(String url, ProgressiveCallback callback) {
return new ProgressiveRequest(Request.delete(url), callback);
}
/// 创建 HEAD 请求,用于获取响应头
///
/// @param url 请求地址
/// @param callback 进度回调
/// @return ProgressiveRequest 请求
public static ProgressiveRequest head(String url, ProgressiveCallback callback) {
return new ProgressiveRequest(Request.head(url), callback);
}
/// 创建 OPTIONS 请求,用于查询支持的请求方法
///
/// @param url 请求地址
/// @param callback 进度回调
/// @return ProgressiveRequest 请求
public static ProgressiveRequest options(String url, ProgressiveCallback callback) {
return new ProgressiveRequest(Request.options(url), callback);
}
@Override @Override
public ProgressiveRequest timeout(long ms) { public ProgressiveRequest timeout(long ms) {
super.timeout(ms); super.timeout(ms);
@@ -3,7 +3,7 @@ package com.imyeyu.network;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JavaType;
import com.imyeyu.java.bean.CallbackArg; import com.imyeyu.java.bean.CallbackArg;
import com.imyeyu.java.bean.Response; import com.imyeyu.java.bean.timi.TimiResponse;
import org.apache.hc.client5.http.fluent.Request; import org.apache.hc.client5.http.fluent.Request;
import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.HttpResponse;
@@ -33,46 +33,6 @@ public class TimiRequest extends JacksonRequest {
return new TimiRequest(Request.post(url)); return new TimiRequest(Request.post(url));
} }
/// 创建 PUT 请求,用于替换资源
///
/// @param url 请求地址
/// @return TimiRequest 请求
public static TimiRequest put(String url) {
return new TimiRequest(Request.put(url));
}
/// 创建 PATCH 请求,用于部分更新资源
///
/// @param url 请求地址
/// @return TimiRequest 请求
public static TimiRequest patch(String url) {
return new TimiRequest(Request.patch(url));
}
/// 创建 DELETE 请求,用于删除资源
///
/// @param url 请求地址
/// @return TimiRequest 请求
public static TimiRequest delete(String url) {
return new TimiRequest(Request.delete(url));
}
/// 创建 HEAD 请求,用于获取响应头
///
/// @param url 请求地址
/// @return TimiRequest 请求
public static TimiRequest head(String url) {
return new TimiRequest(Request.head(url));
}
/// 创建 OPTIONS 请求,用于查询支持的请求方法
///
/// @param url 请求地址
/// @return TimiRequest 请求
public static TimiRequest options(String url) {
return new TimiRequest(Request.options(url));
}
@Override @Override
public TimiRequest timeout(long ms) { public TimiRequest timeout(long ms) {
super.timeout(ms); super.timeout(ms);
@@ -134,7 +94,7 @@ public class TimiRequest extends JacksonRequest {
* @throws IOException 读取或解析失败 * @throws IOException 读取或解析失败
*/ */
public <T> T resultAs(Class<T> clazz) throws IOException { public <T> T resultAs(Class<T> clazz) throws IOException {
Response<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(clazz)); TimiResponse<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(clazz));
if (resp.isFail()) { if (resp.isFail()) {
throw resp.toException(); throw resp.toException();
} }
@@ -150,7 +110,7 @@ public class TimiRequest extends JacksonRequest {
* @throws IOException 读取或解析失败 * @throws IOException 读取或解析失败
*/ */
public <T> T resultAs(TypeReference<T> typeReference) throws IOException { public <T> T resultAs(TypeReference<T> typeReference) throws IOException {
Response<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(typeReference)); TimiResponse<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(typeReference));
if (resp.isFail()) { if (resp.isFail()) {
throw resp.toException(); throw resp.toException();
} }
@@ -166,7 +126,7 @@ public class TimiRequest extends JacksonRequest {
* @throws IOException 读取或解析失败 * @throws IOException 读取或解析失败
*/ */
public <T> T resultAs(Type type) throws IOException { public <T> T resultAs(Type type) throws IOException {
Response<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(type)); TimiResponse<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(type));
if (resp.isFail()) { if (resp.isFail()) {
throw resp.toException(); throw resp.toException();
} }
@@ -175,7 +135,7 @@ public class TimiRequest extends JacksonRequest {
@Override @Override
public void execute() throws IOException { public void execute() throws IOException {
Response<?> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(Object.class)); TimiResponse<?> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(Object.class));
if (resp.isFail()) { if (resp.isFail()) {
throw resp.toException(); throw resp.toException();
} }
@@ -188,7 +148,7 @@ public class TimiRequest extends JacksonRequest {
* @return Jackson 类型 * @return Jackson 类型
*/ */
protected JavaType timiResponseType(Class<?> clazz) { protected JavaType timiResponseType(Class<?> clazz) {
return getObjectMapper().getTypeFactory().constructParametricType(Response.class, clazz); return getObjectMapper().getTypeFactory().constructParametricType(TimiResponse.class, clazz);
} }
/** /**
@@ -198,7 +158,7 @@ public class TimiRequest extends JacksonRequest {
* @return Jackson 类型 * @return Jackson 类型
*/ */
protected JavaType timiResponseType(TypeReference<?> typeReference) { protected JavaType timiResponseType(TypeReference<?> typeReference) {
return getObjectMapper().getTypeFactory().constructParametricType(Response.class, getObjectMapper().constructType(typeReference)); return getObjectMapper().getTypeFactory().constructParametricType(TimiResponse.class, getObjectMapper().constructType(typeReference));
} }
/** /**
@@ -208,6 +168,6 @@ public class TimiRequest extends JacksonRequest {
* @return Jackson 类型 * @return Jackson 类型
*/ */
protected JavaType timiResponseType(Type type) { protected JavaType timiResponseType(Type type) {
return getObjectMapper().getTypeFactory().constructParametricType(Response.class, getObjectMapper().constructType(type)); return getObjectMapper().getTypeFactory().constructParametricType(TimiResponse.class, getObjectMapper().constructType(type));
} }
} }
@@ -28,7 +28,7 @@ public class ProgressRequestTest {
@Test @Test
public void testLength() throws Exception { public void testLength() throws Exception {
long length = FileRequest.head(URL2).length(); long length = FileRequest.wrap(Request.head(URL2)).length();
System.out.println(IOSize.format(length)); System.out.println(IOSize.format(length));
} }
@@ -38,4 +38,4 @@ public class ProgressRequestTest {
final Header contentLengthHeader = response.getHeader("Content-Length"); final Header contentLengthHeader = response.getHeader("Content-Length");
System.out.println(contentLengthHeader.getValue()); System.out.println(contentLengthHeader.getValue());
} }
} }