Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
10801e7e
mica
项目概览
mica
/
mica
通知
10
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
10801e7e
编写于
6月 10, 2020
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
mica-http 优化 github #26 .
上级
dbe29a1e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
28 addition
and
14 deletion
+28
-14
mica-http/src/main/java/net/dreamlu/mica/http/AsyncCallback.java
...tp/src/main/java/net/dreamlu/mica/http/AsyncCallback.java
+7
-7
mica-http/src/main/java/net/dreamlu/mica/http/AsyncExchange.java
...tp/src/main/java/net/dreamlu/mica/http/AsyncExchange.java
+3
-3
mica-http/src/main/java/net/dreamlu/mica/http/Exchange.java
mica-http/src/main/java/net/dreamlu/mica/http/Exchange.java
+12
-0
mica-http/src/main/java/net/dreamlu/mica/http/FormBuilder.java
...http/src/main/java/net/dreamlu/mica/http/FormBuilder.java
+1
-1
mica-http/src/main/java/net/dreamlu/mica/http/HttpRequest.java
...http/src/main/java/net/dreamlu/mica/http/HttpRequest.java
+2
-2
mica-http/src/main/java/net/dreamlu/mica/http/MultipartFormBuilder.java
...main/java/net/dreamlu/mica/http/MultipartFormBuilder.java
+1
-1
mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java
...ttp/src/main/java/net/dreamlu/mica/http/ResponseSpec.java
+2
-0
未找到文件。
mica-http/src/main/java/net/dreamlu/mica/http/AsyncCallback.java
浏览文件 @
10801e7e
...
...
@@ -30,25 +30,25 @@ import java.io.IOException;
*/
@ParametersAreNonnullByDefault
public
class
AsyncCallback
implements
Callback
{
private
final
Async
Call
asyncCall
;
private
final
Async
Exchange
exchange
;
AsyncCallback
(
Async
Call
asyncCall
)
{
this
.
asyncCall
=
asyncCall
;
AsyncCallback
(
Async
Exchange
exchange
)
{
this
.
exchange
=
exchange
;
}
@Override
public
void
onFailure
(
Call
call
,
IOException
e
)
{
asyncCall
.
onFailure
(
call
.
request
(),
e
);
exchange
.
onFailure
(
call
.
request
(),
e
);
}
@Override
public
void
onResponse
(
Call
call
,
Response
response
)
throws
IOException
{
try
(
HttpResponse
httpResponse
=
new
HttpResponse
(
response
))
{
asyncCall
.
onResponse
(
httpResponse
);
exchange
.
onResponse
(
httpResponse
);
if
(
response
.
isSuccessful
())
{
asyncCall
.
onSuccessful
(
httpResponse
);
exchange
.
onSuccessful
(
httpResponse
);
}
else
{
asyncCall
.
onFailure
(
call
.
request
(),
new
IOException
(
httpResponse
.
message
()));
exchange
.
onFailure
(
call
.
request
(),
new
IOException
(
httpResponse
.
message
()));
}
}
}
...
...
mica-http/src/main/java/net/dreamlu/mica/http/Async
Call
.java
→
mica-http/src/main/java/net/dreamlu/mica/http/Async
Exchange
.java
浏览文件 @
10801e7e
...
...
@@ -28,7 +28,7 @@ import java.util.function.Consumer;
*
* @author L.cm
*/
public
class
Async
Call
{
public
class
Async
Exchange
{
private
final
static
Consumer
<
ResponseSpec
>
DEFAULT_CONSUMER
=
(
r
)
->
{};
private
final
static
BiConsumer
<
Request
,
IOException
>
DEFAULT_FAIL_CONSUMER
=
(
r
,
e
)
->
{};
private
final
Call
call
;
...
...
@@ -36,7 +36,7 @@ public class AsyncCall {
private
Consumer
<
ResponseSpec
>
responseConsumer
;
private
BiConsumer
<
Request
,
IOException
>
failedBiConsumer
;
Async
Call
(
Call
call
)
{
Async
Exchange
(
Call
call
)
{
this
.
call
=
call
;
this
.
successConsumer
=
DEFAULT_CONSUMER
;
this
.
responseConsumer
=
DEFAULT_CONSUMER
;
...
...
@@ -53,7 +53,7 @@ public class AsyncCall {
this
.
execute
();
}
public
Async
Call
onFailed
(
BiConsumer
<
Request
,
IOException
>
biConsumer
)
{
public
Async
Exchange
onFailed
(
BiConsumer
<
Request
,
IOException
>
biConsumer
)
{
this
.
failedBiConsumer
=
biConsumer
;
return
this
;
}
...
...
mica-http/src/main/java/net/dreamlu/mica/http/Exchange.java
浏览文件 @
10801e7e
...
...
@@ -22,6 +22,7 @@ import lombok.RequiredArgsConstructor;
import
net.dreamlu.mica.core.utils.Exceptions
;
import
okhttp3.Call
;
import
okhttp3.Request
;
import
okhttp3.Response
;
import
javax.annotation.Nullable
;
import
java.io.File
;
...
...
@@ -89,6 +90,15 @@ public class Exchange {
return
Optional
.
ofNullable
(
this
.
onSuccessful
(
func
));
}
/**
* Returns ok http response.
*
* @return Response
*/
public
Response
response
()
{
return
onResponse
(
ResponseSpec:
:
rawResponse
);
}
/**
* Returns body String.
*
...
...
@@ -171,6 +181,7 @@ public class Exchange {
* toFile.
*
* @param file File
* @return File
*/
public
File
toFile
(
File
file
)
{
return
onResponse
(
responseSpec
->
responseSpec
.
toFile
(
file
));
...
...
@@ -180,6 +191,7 @@ public class Exchange {
* toFile.
*
* @param path Path
* @return Path
*/
public
Path
toFile
(
Path
path
)
{
return
onResponse
(
responseSpec
->
responseSpec
.
toFile
(
path
));
...
...
mica-http/src/main/java/net/dreamlu/mica/http/FormBuilder.java
浏览文件 @
10801e7e
...
...
@@ -62,7 +62,7 @@ public class FormBuilder {
return
this
.
build
().
execute
();
}
public
Async
Call
async
()
{
public
Async
Exchange
async
()
{
return
this
.
build
().
async
();
}
}
mica-http/src/main/java/net/dreamlu/mica/http/HttpRequest.java
浏览文件 @
10801e7e
...
...
@@ -288,8 +288,8 @@ public class HttpRequest {
return
new
Exchange
(
internalCall
(
httpClient
));
}
public
Async
Call
async
()
{
return
new
Async
Call
(
internalCall
(
httpClient
));
public
Async
Exchange
async
()
{
return
new
Async
Exchange
(
internalCall
(
httpClient
));
}
public
HttpRequest
baseAuth
(
String
userName
,
String
password
)
{
...
...
mica-http/src/main/java/net/dreamlu/mica/http/MultipartFormBuilder.java
浏览文件 @
10801e7e
...
...
@@ -91,7 +91,7 @@ public class MultipartFormBuilder {
return
this
.
build
().
execute
();
}
public
Async
Call
async
()
{
public
Async
Exchange
async
()
{
return
this
.
build
().
async
();
}
}
mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java
浏览文件 @
10801e7e
...
...
@@ -176,6 +176,7 @@ public interface ResponseSpec {
* toFile.
*
* @param file File
* @return File
*/
File
toFile
(
File
file
);
...
...
@@ -183,6 +184,7 @@ public interface ResponseSpec {
* toFile.
*
* @param path Path
* @return Path
*/
Path
toFile
(
Path
path
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录