diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..dd84ea78 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 00000000..48d5f81f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,10 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ea5b62f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +/*/target/ +/*/bin/ +/*/.settings/ +/*/.classpath +/*/.project +/*/.idea/ +/*/package-lock.json +/*/node_modules/ +/*/.vuepress/dist/* +/*/*.iml +**.versionsBackup +/target/ +*.iml +/.idea/ +.settings/ +.classpath +.project \ No newline at end of file diff --git a/README.md b/README.md index eeec7cf0..38e0bd00 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,23 @@

- + logo

- Maven Central - License - Troy.Zhou + Maven Central + License + Troy.Zhou

## 文档 -网址:https://ok.zhxu.cn +网址:https://okhttps.ejlchina.com/ + +若以上地址不可用,请使用以下备用地址: + +* http://okhttps.ejlchina-app.com/ +* http://okhttps.zhoxu.cn/ +* http://okhttps.zhxu.cc/ ## 为什么用 @@ -25,8 +31,6 @@ * 单方法回调,充分利用 Lambda 表达式,让你代码超级简洁! * 超级轻量,但性能卓越! -* **阿里云最低 1 折**:https://www.aliyun.com/minisite/goods?userCode=zugtbi5w - ## 如何使用 ### 如艺术一般优雅,像 1、2、3 一样简单 @@ -92,25 +96,22 @@ Websocket 方法: 项目 | 最新版本 | 描述 -|-|- -[okhttps](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps) | 4.1.0 | OkHttps 核心模块 -[okhttps-fastjson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-fastjson) | 4.1.0 | 与 fastjson 集成 -[okhttps-fastjson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-fastjson2) | 4.1.0 | 与 fastjson2 集成 -[okhttps-fastjson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-fastjson2-jsonb) | 4.1.0 | 与 fastjson2-jsonb 集成 -[okhttps-gson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-gson) | 4.1.0 | 与 gson 集成 -[okhttps-jackson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-jackson) | 4.1.0 | 与 jackson 集成 -[okhttps-jackson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-jackson-xml) | 4.1.0 | 与 jackson-xml 集成 -[okhttps-jackson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-jackson-yaml) | 4.1.0 | 与 jackson-yaml 集成 -[okhttps-jackson](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-snack3) | 4.1.0 | 与 jackson-yaml 集成 -[okhttps-stomp](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-stomp) | 4.1.0 | 超级轻量的 Stomp 客户端 -[okhttps-xml](https://gitee.com/troyzhxu/okhttps/tree/dev/okhttps-xml) | 3.5.3 | XML 解析扩展 - -## 超详细教程,请查看:https://ok.zhxu.cn +[okhttps](https://gitee.com/ejlchina-zhxu/okhttps/tree/dev/okhttps) | 3.4.5 | OkHttps 核心模块 +[okhttps-fastjson](https://gitee.com/ejlchina-zhxu/okhttps/tree/dev/okhttps-fastjson) | 3.4.5 | 与 fastjson 集成 +[okhttps-gson](https://gitee.com/ejlchina-zhxu/okhttps/tree/dev/okhttps-gson) | 3.4.5 | 与 gson 集成 +[okhttps-jackson](https://gitee.com/ejlchina-zhxu/okhttps/tree/dev/okhttps-jackson) | 3.4.5 | 与 jackson 集成 +[okhttps-stomp](https://gitee.com/ejlchina-zhxu/okhttps/tree/dev/okhttps-stomp) | 3.4.5 | 超级轻量的 Stomp 客户端 +[okhttps-xml](https://gitee.com/ejlchina-zhxu/okhttps/tree/dev/okhttps-xml) | 3.4.5 | XML 解析扩展 + +## 超详细教程,请查看:https://okhttps.ejlchina.com/ +若以上地址不可用,请访问:http://okhttps.ejlchina-app.com/ ## 联系方式 * 微信: * 由于近期交流群的二维码被爬,扫码入群方式已被关闭 库的使用上若有疑问,可先加微信【18556739726】(请备注 OkHttps)再入群交流 +* 邮箱:zhou.xu@ejlchina.com ## 友情链接 @@ -120,7 +121,7 @@ Websocket 方法: [**[ hrun4j ]** 接口自动化测试解决方案 --工具选得好,下班回家早;测试用得对,半夜安心睡 ](https://github.com/lematechvip/hrun4j) -[**[ Json Kit ]** 超轻量级 JSON 门面工具,用法简单,不依赖具体实现,让业务代码与 Jackson、Gson、Fastjson 等解耦!](https://gitee.com/troyzhxu/jsonkit) +[**[ Json Kit ]** 超轻量级 JSON 门面工具,用法简单,不依赖具体实现,让业务代码与 Jackson、Gson、Fastjson 等解耦!](https://gitee.com/ejlchina-zhxu/jsonkit) ## 参与贡献 @@ -129,3 +130,8 @@ Websocket 方法: 3. 提交代码 4. 新建 Pull Request +## Next + +* Java 9 的模块系统 +* 请求参数支持重复的 key +* 验证 nps 代理 diff --git a/okhttps-fastjson/README.md b/okhttps-fastjson/README.md index bbf641f0..3e857ab4 100644 --- a/okhttps-fastjson/README.md +++ b/okhttps-fastjson/README.md @@ -9,16 +9,16 @@ ```xml - cn.zhxu + com.ejlchina okhttps-fastjson - 3.5.3 + 3.4.5 ``` ##### Gradle ```groovy -implementation 'cn.zhxu:okhttps-fastjson:3.5.3' +implementation 'com.ejlchina:okhttps-fastjson:3.4.5' ``` -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) +#### 更多请参阅 [http://okhttps.ejlchina.com/](http://okhttps.ejlchina.com/) diff --git a/okhttps-fastjson/pom.xml b/okhttps-fastjson/pom.xml index 219950e4..67d72267 100644 --- a/okhttps-fastjson/pom.xml +++ b/okhttps-fastjson/pom.xml @@ -6,24 +6,24 @@ jar - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 - cn.zhxu + com.ejlchina okhttps ${project.version} - cn.zhxu + com.ejlchina data-fastjson ${data.version} - cn.zhxu + com.ejlchina okhttps-test ${project.version} test diff --git a/okhttps-fastjson/src/main/java/cn/zhxu/okhttps/fastjson/FastjsonMsgConvertor.java b/okhttps-fastjson/src/main/java/cn/zhxu/okhttps/fastjson/FastjsonMsgConvertor.java deleted file mode 100644 index 1ed65148..00000000 --- a/okhttps-fastjson/src/main/java/cn/zhxu/okhttps/fastjson/FastjsonMsgConvertor.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.zhxu.okhttps.fastjson; - -import cn.zhxu.data.fastjson.FastjsonDataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; - -public class FastjsonMsgConvertor extends FastjsonDataConvertor implements MsgConvertor, ConvertProvider { - - @Override - public String mediaType() { - return "application/json"; - } - - @Override - public MsgConvertor getConvertor() { - return new FastjsonMsgConvertor(); - } - -} diff --git a/okhttps-fastjson/src/main/java/com/ejlchina/okhttps/fastjson/FastjsonMsgConvertor.java b/okhttps-fastjson/src/main/java/com/ejlchina/okhttps/fastjson/FastjsonMsgConvertor.java new file mode 100644 index 00000000..426c31cd --- /dev/null +++ b/okhttps-fastjson/src/main/java/com/ejlchina/okhttps/fastjson/FastjsonMsgConvertor.java @@ -0,0 +1,41 @@ +package com.ejlchina.okhttps.fastjson; + +import com.alibaba.fastjson.JSON; +import com.ejlchina.data.fastjson.FastjsonDataConvertor; +import com.ejlchina.okhttps.ConvertProvider; +import com.ejlchina.okhttps.MsgConvertor; +import com.ejlchina.okhttps.OkHttpsException; +import okio.Okio; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Type; +import java.nio.charset.Charset; + +public class FastjsonMsgConvertor extends FastjsonDataConvertor implements MsgConvertor, ConvertProvider { + + @Override + public String mediaType() { + return "application/json; charset={charset}"; + } + + @Override + public T toBean(Type type, InputStream in, Charset charset) { + return JSON.parseObject(toString(in, charset), type); + } + + @Override + public MsgConvertor getConvertor() { + return new FastjsonMsgConvertor(); + } + + @Override + protected String toString(InputStream in, Charset charset) { + try { + return Okio.buffer(Okio.source(in)).readString(charset); + } catch (IOException e) { + throw new OkHttpsException("读取文本异常", e); + } + } + +} diff --git a/okhttps-fastjson/src/main/java/module-info.java b/okhttps-fastjson/src/main/java/module-info.java new file mode 100644 index 00000000..9ff813ce --- /dev/null +++ b/okhttps-fastjson/src/main/java/module-info.java @@ -0,0 +1,13 @@ +module okhttps.fastjson { + + requires okhttps; + requires data.fastjson; + requires fastjson; + requires okio; + + provides com.ejlchina.okhttps.ConvertProvider with + com.ejlchina.okhttps.fastjson.FastjsonMsgConvertor; + + exports com.ejlchina.okhttps.fastjson; + +} \ No newline at end of file diff --git a/okhttps-fastjson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-fastjson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index 5ae917c7..00000000 --- a/okhttps-fastjson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.fastjson.FastjsonMsgConvertor \ No newline at end of file diff --git a/okhttps-fastjson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider b/okhttps-fastjson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider new file mode 100644 index 00000000..5fcea44a --- /dev/null +++ b/okhttps-fastjson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider @@ -0,0 +1 @@ +com.ejlchina.okhttps.fastjson.FastjsonMsgConvertor \ No newline at end of file diff --git a/okhttps-fastjson/src/test/java/cn/zhxu/okhttps/fastjson/TestCase.java b/okhttps-fastjson/src/test/java/com/ejlchina/okhttps/TestCase.java similarity index 59% rename from okhttps-fastjson/src/test/java/cn/zhxu/okhttps/fastjson/TestCase.java rename to okhttps-fastjson/src/test/java/com/ejlchina/okhttps/TestCase.java index 2f0cc7e6..4b350349 100644 --- a/okhttps-fastjson/src/test/java/cn/zhxu/okhttps/fastjson/TestCase.java +++ b/okhttps-fastjson/src/test/java/com/ejlchina/okhttps/TestCase.java @@ -1,9 +1,10 @@ -package cn.zhxu.okhttps.fastjson; +package com.ejlchina.okhttps; -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.JsonTestCases; +import com.ejlchina.okhttps.fastjson.FastjsonMsgConvertor; +import com.ejlchina.okhttps.test.JsonTestCases; import org.junit.Test; + public class TestCase { @Test diff --git a/okhttps-fastjson2-jsonb/README.md b/okhttps-fastjson2-jsonb/README.md deleted file mode 100644 index 56d4f135..00000000 --- a/okhttps-fastjson2-jsonb/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# OkHttps FastJson - -#### 介绍 - -基于 OkHttps 与 Fastjson2Jsonb 集成扩展 - - -##### Maven - -```xml - - cn.zhxu - okhttps-fastjson2-jsonb - 3.5.3 - -``` - -##### Gradle - -```groovy -implementation 'cn.zhxu:okhttps-fastjson2-jsonb:3.5.3' -``` - -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) diff --git a/okhttps-fastjson2-jsonb/pom.xml b/okhttps-fastjson2-jsonb/pom.xml deleted file mode 100644 index dc2a91c0..00000000 --- a/okhttps-fastjson2-jsonb/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - okhttps-fastjson2-jsonb - OkHttps Fastjson2 JSONB - jar - - - cn.zhxu - okhttps-parent - 4.1.0 - - - - - cn.zhxu - okhttps - ${project.version} - - - cn.zhxu - data-fastjson2-jsonb - ${data.version} - - - cn.zhxu - okhttps-test - ${project.version} - test - - - - - okhttps-fastjson2-jsonb - - \ No newline at end of file diff --git a/okhttps-fastjson2-jsonb/src/main/java/cn/zhxu/okhttps/fastjson2/jsonb/Fastjson2JsonbMsgConvertor.java b/okhttps-fastjson2-jsonb/src/main/java/cn/zhxu/okhttps/fastjson2/jsonb/Fastjson2JsonbMsgConvertor.java deleted file mode 100644 index 17867cd8..00000000 --- a/okhttps-fastjson2-jsonb/src/main/java/cn/zhxu/okhttps/fastjson2/jsonb/Fastjson2JsonbMsgConvertor.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.zhxu.okhttps.fastjson2.jsonb; - -import cn.zhxu.data.fastjson2.jsonb.Fastjson2JsonbDataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; - -public class Fastjson2JsonbMsgConvertor extends Fastjson2JsonbDataConvertor implements MsgConvertor, ConvertProvider { - - @Override - public String mediaType() { - return "application/jsonb"; - } - - @Override - public MsgConvertor getConvertor() { - return new Fastjson2JsonbMsgConvertor(); - } - -} diff --git a/okhttps-fastjson2-jsonb/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-fastjson2-jsonb/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index 3683502a..00000000 --- a/okhttps-fastjson2-jsonb/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.fastjson2.jsonb.Fastjson2JsonbMsgConvertor \ No newline at end of file diff --git a/okhttps-fastjson2-jsonb/src/test/java/cn/zhxu/okhttps/fastjson2/jsonb/TestCase.java b/okhttps-fastjson2-jsonb/src/test/java/cn/zhxu/okhttps/fastjson2/jsonb/TestCase.java deleted file mode 100644 index 835408ba..00000000 --- a/okhttps-fastjson2-jsonb/src/test/java/cn/zhxu/okhttps/fastjson2/jsonb/TestCase.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.zhxu.okhttps.fastjson2.jsonb; - -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.JsonTestCases; -import org.junit.Test; - - -public class TestCase { - - @Test - public void doTest() throws Exception { - MsgConvertor msgConvertor = new Fastjson2JsonbMsgConvertor(); -// new JsonTestCases(msgConvertor).run(); - } - -} diff --git a/okhttps-fastjson2/README.md b/okhttps-fastjson2/README.md deleted file mode 100644 index cdaa2cf2..00000000 --- a/okhttps-fastjson2/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# OkHttps FastJson - -#### 介绍 - -基于 OkHttps 与 Fastjson2 集成扩展 - - -##### Maven - -```xml - - cn.zhxu - okhttps-fastjson2 - 3.5.3 - -``` - -##### Gradle - -```groovy -implementation 'cn.zhxu:okhttps-fastjson2:3.5.3' -``` - -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) diff --git a/okhttps-fastjson2/pom.xml b/okhttps-fastjson2/pom.xml deleted file mode 100644 index dd971348..00000000 --- a/okhttps-fastjson2/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - okhttps-fastjson2 - OkHttps Fastjson2 - jar - - - cn.zhxu - okhttps-parent - 4.1.0 - - - - - cn.zhxu - okhttps - ${project.version} - - - cn.zhxu - data-fastjson2 - ${data.version} - - - cn.zhxu - okhttps-test - ${project.version} - test - - - - - okhttps-fastjson2 - - \ No newline at end of file diff --git a/okhttps-fastjson2/src/main/java/cn/zhxu/okhttps/fastjson2/Fastjson2MsgConvertor.java b/okhttps-fastjson2/src/main/java/cn/zhxu/okhttps/fastjson2/Fastjson2MsgConvertor.java deleted file mode 100644 index a7199847..00000000 --- a/okhttps-fastjson2/src/main/java/cn/zhxu/okhttps/fastjson2/Fastjson2MsgConvertor.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.zhxu.okhttps.fastjson2; - -import cn.zhxu.data.fastjson2.Fastjson2DataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; - -public class Fastjson2MsgConvertor extends Fastjson2DataConvertor implements MsgConvertor, ConvertProvider { - - @Override - public String mediaType() { - return "application/json"; - } - - @Override - public MsgConvertor getConvertor() { - return new Fastjson2MsgConvertor(); - } - -} diff --git a/okhttps-fastjson2/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-fastjson2/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index 37efd499..00000000 --- a/okhttps-fastjson2/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.fastjson2.Fastjson2MsgConvertor \ No newline at end of file diff --git a/okhttps-fastjson2/src/test/java/cn/zhxu/okhttps/fastjson2/TestCase.java b/okhttps-fastjson2/src/test/java/cn/zhxu/okhttps/fastjson2/TestCase.java deleted file mode 100644 index cc5051ad..00000000 --- a/okhttps-fastjson2/src/test/java/cn/zhxu/okhttps/fastjson2/TestCase.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.zhxu.okhttps.fastjson2; - -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.JsonTestCases; -import org.junit.Test; - - -public class TestCase { - - @Test - public void doTest() throws Exception { - MsgConvertor msgConvertor = new Fastjson2MsgConvertor(); - new JsonTestCases(msgConvertor).run(); - } - -} diff --git a/okhttps-gson/README.md b/okhttps-gson/README.md index 938f5181..5c3ad57a 100644 --- a/okhttps-gson/README.md +++ b/okhttps-gson/README.md @@ -9,16 +9,16 @@ ```xml - cn.zhxu + com.ejlchina okhttps-gson - 3.5.3 + 3.4.5 ``` ##### Gradle ```groovy -implementation 'cn.zhxu:okhttps-gson:3.5.3' +implementation 'com.ejlchina:okhttps-gson:3.4.5' ``` -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) +#### 更多请参阅 [http://okhttps.ejlchina.com/](http://okhttps.ejlchina.com/) diff --git a/okhttps-gson/pom.xml b/okhttps-gson/pom.xml index ef0d2ad7..351c38e6 100644 --- a/okhttps-gson/pom.xml +++ b/okhttps-gson/pom.xml @@ -6,24 +6,24 @@ jar - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 - cn.zhxu + com.ejlchina okhttps ${project.version} - cn.zhxu + com.ejlchina data-gson ${data.version} - cn.zhxu + com.ejlchina okhttps-test ${project.version} test diff --git a/okhttps-gson/src/main/java/cn/zhxu/okhttps/gson/GsonMsgConvertor.java b/okhttps-gson/src/main/java/com/ejlchina/okhttps/gson/GsonMsgConvertor.java similarity index 62% rename from okhttps-gson/src/main/java/cn/zhxu/okhttps/gson/GsonMsgConvertor.java rename to okhttps-gson/src/main/java/com/ejlchina/okhttps/gson/GsonMsgConvertor.java index 15272f4b..19ef3e74 100644 --- a/okhttps-gson/src/main/java/cn/zhxu/okhttps/gson/GsonMsgConvertor.java +++ b/okhttps-gson/src/main/java/com/ejlchina/okhttps/gson/GsonMsgConvertor.java @@ -1,8 +1,8 @@ -package cn.zhxu.okhttps.gson; +package com.ejlchina.okhttps.gson; -import cn.zhxu.data.gson.GsonDataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; +import com.ejlchina.data.gson.GsonDataConvertor; +import com.ejlchina.okhttps.ConvertProvider; +import com.ejlchina.okhttps.MsgConvertor; import com.google.gson.Gson; public class GsonMsgConvertor extends GsonDataConvertor implements MsgConvertor, ConvertProvider { @@ -15,7 +15,7 @@ public GsonMsgConvertor(Gson gson) { @Override public String mediaType() { - return "application/json"; + return "application/json; charset={charset}"; } @Override diff --git a/okhttps-gson/src/main/java/module-info.java b/okhttps-gson/src/main/java/module-info.java new file mode 100644 index 00000000..50da738e --- /dev/null +++ b/okhttps-gson/src/main/java/module-info.java @@ -0,0 +1,12 @@ +module okhttps.gson { + + requires okhttps; + requires data.gson; + requires com.google.gson; + + provides com.ejlchina.okhttps.ConvertProvider with + com.ejlchina.okhttps.gson.GsonMsgConvertor; + + exports com.ejlchina.okhttps.gson; + +} \ No newline at end of file diff --git a/okhttps-gson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-gson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index 122472d4..00000000 --- a/okhttps-gson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.gson.GsonMsgConvertor \ No newline at end of file diff --git a/okhttps-gson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider b/okhttps-gson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider new file mode 100644 index 00000000..ccde028b --- /dev/null +++ b/okhttps-gson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider @@ -0,0 +1 @@ +com.ejlchina.okhttps.gson.GsonMsgConvertor \ No newline at end of file diff --git a/okhttps-gson/src/test/java/cn/zhxu/okhttps/gson/TestCase.java b/okhttps-gson/src/test/java/com/ejlchina/okhttps/TestCase.java similarity index 60% rename from okhttps-gson/src/test/java/cn/zhxu/okhttps/gson/TestCase.java rename to okhttps-gson/src/test/java/com/ejlchina/okhttps/TestCase.java index 71406abe..d49c26ce 100644 --- a/okhttps-gson/src/test/java/cn/zhxu/okhttps/gson/TestCase.java +++ b/okhttps-gson/src/test/java/com/ejlchina/okhttps/TestCase.java @@ -1,7 +1,7 @@ -package cn.zhxu.okhttps.gson; +package com.ejlchina.okhttps; -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.JsonTestCases; +import com.ejlchina.okhttps.gson.GsonMsgConvertor; +import com.ejlchina.okhttps.test.JsonTestCases; import org.junit.Test; diff --git a/okhttps-jackson-xml/README.md b/okhttps-jackson-xml/README.md deleted file mode 100644 index e2505225..00000000 --- a/okhttps-jackson-xml/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# OkHttps Jackson - -#### 介绍 - -基于 OkHttps 与 JacksonXml 集成扩展 - - -##### Maven - -```xml - - cn.zhxu - okhttps-jackson-xml - 3.5.3 - -``` - -##### Gradle - -```groovy -implementation 'cn.zhxu:okhttps-jackson-xml:3.5.3' -``` - -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) diff --git a/okhttps-jackson-xml/pom.xml b/okhttps-jackson-xml/pom.xml deleted file mode 100644 index 54aa1fce..00000000 --- a/okhttps-jackson-xml/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - okhttps-jackson-xml - OkHttps Jackson Xml - jar - - - cn.zhxu - okhttps-parent - 4.1.0 - - - - - cn.zhxu - okhttps - ${project.version} - - - cn.zhxu - data-jackson-xml - ${data.version} - - - cn.zhxu - okhttps-test - ${project.version} - test - - - - - okhttps-jackson-xml - - \ No newline at end of file diff --git a/okhttps-jackson-xml/src/main/java/cn/zhxu/okhttps/jackson/xml/JacksonXmlMsgConvertor.java b/okhttps-jackson-xml/src/main/java/cn/zhxu/okhttps/jackson/xml/JacksonXmlMsgConvertor.java deleted file mode 100644 index 44a29fca..00000000 --- a/okhttps-jackson-xml/src/main/java/cn/zhxu/okhttps/jackson/xml/JacksonXmlMsgConvertor.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.zhxu.okhttps.jackson.xml; - -import cn.zhxu.data.jackson.xml.JacksonXmlDataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; - -public class JacksonXmlMsgConvertor extends JacksonXmlDataConvertor implements MsgConvertor, ConvertProvider { - - public JacksonXmlMsgConvertor() { } - - public JacksonXmlMsgConvertor(XmlMapper xmlMapper) { - super(xmlMapper); - } - - @Override - public String mediaType() { - return "application/xml"; - } - - @Override - public MsgConvertor getConvertor() { - return new JacksonXmlMsgConvertor(); - } - -} diff --git a/okhttps-jackson-xml/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-jackson-xml/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index 344c3d0b..00000000 --- a/okhttps-jackson-xml/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.jackson.xml.JacksonXmlMsgConvertor \ No newline at end of file diff --git a/okhttps-jackson-xml/src/test/java/cn/zhxu/okhttps/jackson/xml/TestCase.java b/okhttps-jackson-xml/src/test/java/cn/zhxu/okhttps/jackson/xml/TestCase.java deleted file mode 100644 index 20af4b4c..00000000 --- a/okhttps-jackson-xml/src/test/java/cn/zhxu/okhttps/jackson/xml/TestCase.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.zhxu.okhttps.jackson.xml; - -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.XmlTestCases; -import org.junit.Test; - - -public class TestCase { - - @Test - public void doTest() throws Exception { - MsgConvertor convertor = new JacksonXmlMsgConvertor(); -// new XmlTestCases(convertor).run(); - } - -} diff --git a/okhttps-jackson-yaml/README.md b/okhttps-jackson-yaml/README.md deleted file mode 100644 index dbd3b23f..00000000 --- a/okhttps-jackson-yaml/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# OkHttps Jackson - -#### 介绍 - -基于 OkHttps 与 JacksonYamls 集成扩展 - - -##### Maven - -```xml - - cn.zhxu - okhttps-jackson-yaml - 3.5.3 - -``` - -##### Gradle - -```groovy -implementation 'cn.zhxu:okhttps-jackson-yaml:3.5.3' -``` - -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) diff --git a/okhttps-jackson-yaml/pom.xml b/okhttps-jackson-yaml/pom.xml deleted file mode 100644 index c550aa50..00000000 --- a/okhttps-jackson-yaml/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - okhttps-jackson-yaml - OkHttps Jackson Yaml - jar - - - cn.zhxu - okhttps-parent - 4.1.0 - - - - - cn.zhxu - okhttps - ${project.version} - - - cn.zhxu - data-jackson-yaml - ${data.version} - - - cn.zhxu - okhttps-test - ${project.version} - test - - - - - okhttps-jackson-yaml - - \ No newline at end of file diff --git a/okhttps-jackson-yaml/src/main/java/cn/zhxu/okhttps/jackson/yaml/JacksonYamlMsgConvertor.java b/okhttps-jackson-yaml/src/main/java/cn/zhxu/okhttps/jackson/yaml/JacksonYamlMsgConvertor.java deleted file mode 100644 index e0dc08e1..00000000 --- a/okhttps-jackson-yaml/src/main/java/cn/zhxu/okhttps/jackson/yaml/JacksonYamlMsgConvertor.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.zhxu.okhttps.jackson.yaml; - -import cn.zhxu.data.jackson.yaml.JacksonYamlDataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; - -public class JacksonYamlMsgConvertor extends JacksonYamlDataConvertor implements MsgConvertor, ConvertProvider { - - public JacksonYamlMsgConvertor() { } - - public JacksonYamlMsgConvertor(YAMLMapper yamlMapper) { - super(yamlMapper); - } - - @Override - public String mediaType() { - return "application/yaml"; - } - - @Override - public MsgConvertor getConvertor() { - return new JacksonYamlMsgConvertor(); - } - -} diff --git a/okhttps-jackson-yaml/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-jackson-yaml/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index 8b8befc7..00000000 --- a/okhttps-jackson-yaml/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.jackson.yaml.JacksonYamlMsgConvertor \ No newline at end of file diff --git a/okhttps-jackson-yaml/src/test/java/cn/zhxu/okhttps/jackson/yaml/TestCase.java b/okhttps-jackson-yaml/src/test/java/cn/zhxu/okhttps/jackson/yaml/TestCase.java deleted file mode 100644 index 9f781a72..00000000 --- a/okhttps-jackson-yaml/src/test/java/cn/zhxu/okhttps/jackson/yaml/TestCase.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.zhxu.okhttps.jackson.yaml; - -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.JsonTestCases; -import org.junit.Test; - - -public class TestCase { - - @Test - public void doTest() throws Exception { - MsgConvertor convertor = new JacksonYamlMsgConvertor(); -// new JsonTestCases(convertor).run(); - } - -} diff --git a/okhttps-jackson/README.md b/okhttps-jackson/README.md index 54c1cf5e..d1f43c59 100644 --- a/okhttps-jackson/README.md +++ b/okhttps-jackson/README.md @@ -9,16 +9,16 @@ ```xml - cn.zhxu + com.ejlchina okhttps-jackson - 3.5.3 + 3.4.5 ``` ##### Gradle ```groovy -implementation 'cn.zhxu:okhttps-jackson:3.5.3' +implementation 'com.ejlchina:okhttps-jackson:3.4.5' ``` -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) +#### 更多请参阅 [http://okhttps.ejlchina.com/](http://okhttps.ejlchina.com/) diff --git a/okhttps-jackson/pom.xml b/okhttps-jackson/pom.xml index d9cef0e0..72667ce8 100644 --- a/okhttps-jackson/pom.xml +++ b/okhttps-jackson/pom.xml @@ -6,24 +6,24 @@ jar - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 - cn.zhxu + com.ejlchina okhttps ${project.version} - cn.zhxu + com.ejlchina data-jackson ${data.version} - cn.zhxu + com.ejlchina okhttps-test ${project.version} test diff --git a/okhttps-jackson/src/main/java/cn/zhxu/okhttps/jackson/JacksonMsgConvertor.java b/okhttps-jackson/src/main/java/com/ejlchina/okhttps/jackson/JacksonMsgConvertor.java similarity index 54% rename from okhttps-jackson/src/main/java/cn/zhxu/okhttps/jackson/JacksonMsgConvertor.java rename to okhttps-jackson/src/main/java/com/ejlchina/okhttps/jackson/JacksonMsgConvertor.java index 1c0e561d..ea9c57c4 100644 --- a/okhttps-jackson/src/main/java/cn/zhxu/okhttps/jackson/JacksonMsgConvertor.java +++ b/okhttps-jackson/src/main/java/com/ejlchina/okhttps/jackson/JacksonMsgConvertor.java @@ -1,8 +1,8 @@ -package cn.zhxu.okhttps.jackson; +package com.ejlchina.okhttps.jackson; -import cn.zhxu.data.jackson.JacksonDataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; +import com.ejlchina.data.jackson.JacksonDataConvertor; +import com.ejlchina.okhttps.ConvertProvider; +import com.ejlchina.okhttps.MsgConvertor; import com.fasterxml.jackson.databind.ObjectMapper; public class JacksonMsgConvertor extends JacksonDataConvertor implements MsgConvertor, ConvertProvider { @@ -13,9 +13,13 @@ public JacksonMsgConvertor(ObjectMapper objectMapper) { super(objectMapper); } + public JacksonMsgConvertor(ObjectMapper objectMapper, boolean typeCached) { + super(objectMapper, typeCached); + } + @Override public String mediaType() { - return "application/json"; + return "application/json; charset={charset}"; } @Override diff --git a/okhttps-jackson/src/main/java/module-info.java b/okhttps-jackson/src/main/java/module-info.java new file mode 100644 index 00000000..5563d1b5 --- /dev/null +++ b/okhttps-jackson/src/main/java/module-info.java @@ -0,0 +1,12 @@ +module okhttps.jackson { + + requires okhttps; + requires data.jackson; + requires com.fasterxml.jackson.databind; + + provides com.ejlchina.okhttps.ConvertProvider with + com.ejlchina.okhttps.jackson.JacksonMsgConvertor; + + exports com.ejlchina.okhttps.jackson; + +} \ No newline at end of file diff --git a/okhttps-jackson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-jackson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index dd5ee602..00000000 --- a/okhttps-jackson/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.jackson.JacksonMsgConvertor \ No newline at end of file diff --git a/okhttps-jackson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider b/okhttps-jackson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider new file mode 100644 index 00000000..1925461f --- /dev/null +++ b/okhttps-jackson/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider @@ -0,0 +1 @@ +com.ejlchina.okhttps.jackson.JacksonMsgConvertor \ No newline at end of file diff --git a/okhttps-jackson/src/test/java/cn/zhxu/okhttps/jackson/TestCase.java b/okhttps-jackson/src/test/java/cn/zhxu/okhttps/jackson/TestCase.java deleted file mode 100644 index 74ea88f9..00000000 --- a/okhttps-jackson/src/test/java/cn/zhxu/okhttps/jackson/TestCase.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.zhxu.okhttps.jackson; - -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.JsonTestCases; -import org.junit.Test; - - -public class TestCase { - - @Test - public void doTest() throws Exception { - MsgConvertor convertor = new JacksonMsgConvertor(); - new JsonTestCases(convertor).run(); - } - -} diff --git a/okhttps-jackson/src/test/java/com/ejlchina/okhttps/TestCase.java b/okhttps-jackson/src/test/java/com/ejlchina/okhttps/TestCase.java new file mode 100644 index 00000000..75df5a3c --- /dev/null +++ b/okhttps-jackson/src/test/java/com/ejlchina/okhttps/TestCase.java @@ -0,0 +1,16 @@ +package com.ejlchina.okhttps; + +import com.ejlchina.okhttps.jackson.JacksonMsgConvertor; +import com.ejlchina.okhttps.test.JsonTestCases; +import org.junit.Test; + + +public class TestCase { + + @Test + public void doTest() throws Exception { + MsgConvertor msgConvertor = new JacksonMsgConvertor(); + new JsonTestCases(msgConvertor).run(); + } + +} diff --git a/okhttps-snack3/README.md b/okhttps-snack3/README.md deleted file mode 100644 index 22af945b..00000000 --- a/okhttps-snack3/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# OkHttps Gson - -#### 介绍 - -基于 OkHttps 与 Gson 集成扩展 - - -##### Maven - -```xml - - cn.zhxu - okhttps-snack3 - 3.5.3 - -``` - -##### Gradle - -```groovy -implementation 'cn.zhxu:okhttps-snack3:3.5.3' -``` - -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) diff --git a/okhttps-snack3/src/main/java/cn/zhxu/okhttps/snack3/Snack3MsgConvertor.java b/okhttps-snack3/src/main/java/cn/zhxu/okhttps/snack3/Snack3MsgConvertor.java deleted file mode 100644 index 2c56dd55..00000000 --- a/okhttps-snack3/src/main/java/cn/zhxu/okhttps/snack3/Snack3MsgConvertor.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.zhxu.okhttps.snack3; - -import cn.zhxu.data.snack3.Snack3DataConvertor; -import cn.zhxu.okhttps.ConvertProvider; -import cn.zhxu.okhttps.MsgConvertor; - -public class Snack3MsgConvertor extends Snack3DataConvertor implements MsgConvertor, ConvertProvider { - - @Override - public String mediaType() { - return "application/json"; - } - - @Override - public MsgConvertor getConvertor() { - return new Snack3MsgConvertor(); - } - -} - - - - - - - - - - - - - - diff --git a/okhttps-snack3/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider b/okhttps-snack3/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider deleted file mode 100644 index a546ae29..00000000 --- a/okhttps-snack3/src/main/resources/META-INF/services/cn.zhxu.okhttps.ConvertProvider +++ /dev/null @@ -1 +0,0 @@ -cn.zhxu.okhttps.snack3.Snack3MsgConvertor \ No newline at end of file diff --git a/okhttps-snack3/src/test/java/cn/zhxu/okhttps/snack3/TestCase.java b/okhttps-snack3/src/test/java/cn/zhxu/okhttps/snack3/TestCase.java deleted file mode 100644 index 9ebb192f..00000000 --- a/okhttps-snack3/src/test/java/cn/zhxu/okhttps/snack3/TestCase.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.zhxu.okhttps.snack3; - -import cn.zhxu.okhttps.MsgConvertor; -import cn.zhxu.okhttps.test.JsonTestCases; -import org.junit.Test; - - -public class TestCase { - - @Test - public void doTest() throws Exception { - MsgConvertor msgConvertor = new Snack3MsgConvertor(); - new JsonTestCases(msgConvertor).run(); - } - -} diff --git a/okhttps-stomp/README.md b/okhttps-stomp/README.md index ccc3ce2c..319b6edd 100644 --- a/okhttps-stomp/README.md +++ b/okhttps-stomp/README.md @@ -9,16 +9,16 @@ ```xml - cn.zhxu + com.ejlchina okhttps-stomp - 3.5.3 + 3.4.5 ``` ##### Gradle ```groovy -implementation 'cn.zhxu:okhttps-stomp:3.5.3' +implementation 'com.ejlchina:okhttps-stomp:3.4.5' ``` -#### 更多请参阅 [https://ok.zhxu.cn/v2/stomp.html](https://ok.zhxu.cn/v2/stomp.html) +#### 更多请参阅 [http://okhttps.ejlchina.com/v2/stomp.html](http://okhttps.ejlchina.com/v2/stomp.html) diff --git a/okhttps-stomp/pom.xml b/okhttps-stomp/pom.xml index 3ccaa125..c8cdbe9f 100644 --- a/okhttps-stomp/pom.xml +++ b/okhttps-stomp/pom.xml @@ -6,19 +6,19 @@ jar - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 - cn.zhxu + com.ejlchina okhttps ${project.version} - cn.zhxu + com.ejlchina okhttps-test ${project.version} test diff --git a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Commands.java b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Commands.java similarity index 97% rename from okhttps-stomp/src/main/java/cn/zhxu/stomp/Commands.java rename to okhttps-stomp/src/main/java/com/ejlchina/stomp/Commands.java index 9a59bb4c..6cfb0dde 100644 --- a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Commands.java +++ b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Commands.java @@ -1,4 +1,4 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; /** * 命令 diff --git a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Header.java b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Header.java similarity index 97% rename from okhttps-stomp/src/main/java/cn/zhxu/stomp/Header.java rename to okhttps-stomp/src/main/java/com/ejlchina/stomp/Header.java index e3441c96..994d9079 100644 --- a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Header.java +++ b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Header.java @@ -1,4 +1,4 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; public class Header { diff --git a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Message.java b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Message.java similarity index 97% rename from okhttps-stomp/src/main/java/cn/zhxu/stomp/Message.java rename to okhttps-stomp/src/main/java/com/ejlchina/stomp/Message.java index 6df8a05a..fb6e16e0 100644 --- a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Message.java +++ b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Message.java @@ -1,4 +1,4 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; import java.util.List; diff --git a/okhttps-stomp/src/main/java/cn/zhxu/stomp/MsgCodec.java b/okhttps-stomp/src/main/java/com/ejlchina/stomp/MsgCodec.java similarity index 70% rename from okhttps-stomp/src/main/java/cn/zhxu/stomp/MsgCodec.java rename to okhttps-stomp/src/main/java/com/ejlchina/stomp/MsgCodec.java index 1f83addd..a1faeaa3 100644 --- a/okhttps-stomp/src/main/java/cn/zhxu/stomp/MsgCodec.java +++ b/okhttps-stomp/src/main/java/com/ejlchina/stomp/MsgCodec.java @@ -1,6 +1,6 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; -import java.util.function.Consumer; +import com.ejlchina.okhttps.OnCallback; /** * Stomp 消息编解码器 @@ -20,6 +20,6 @@ public interface MsgCodec { * @param input 输入 * @param out 输出 */ - void decode(String input, Consumer out); + void decode(String input, OnCallback out); } diff --git a/okhttps-stomp/src/main/java/cn/zhxu/stomp/MsgCodecImpl.java b/okhttps-stomp/src/main/java/com/ejlchina/stomp/MsgCodecImpl.java similarity index 95% rename from okhttps-stomp/src/main/java/cn/zhxu/stomp/MsgCodecImpl.java rename to okhttps-stomp/src/main/java/com/ejlchina/stomp/MsgCodecImpl.java index bcdb6fa3..4c955a3b 100644 --- a/okhttps-stomp/src/main/java/cn/zhxu/stomp/MsgCodecImpl.java +++ b/okhttps-stomp/src/main/java/com/ejlchina/stomp/MsgCodecImpl.java @@ -1,8 +1,9 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; + +import com.ejlchina.okhttps.OnCallback; import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; /** * Stomp 消息编解码器 @@ -70,7 +71,7 @@ protected List
msgHeaders(Message input) { } @Override - public synchronized void decode(String input, Consumer out) { + public synchronized void decode(String input, OnCallback out) { if (input == null || input.isEmpty()) { return; } @@ -84,7 +85,7 @@ public synchronized void decode(String input, Consumer out) { * @param out 输出 * @param start 开始解析的问题 */ - protected void decode(Consumer out, int start) { + protected void decode(OnCallback out, int start) { cleanPendingStartData(start); // Body 结尾符下标 int bEndIdx = pending.indexOf(bodyEnd); @@ -113,7 +114,7 @@ protected void decode(Consumer out, int start) { // 解析 Body String payload = pending.substring(hEndIdx + headersEnd.length(), bEndIdx); // 输出解析结果 - out.accept(createMessage(command, headers, payload)); + out.on(createMessage(command, headers, payload)); // 重新解析 bodyEnd 之后的数据 decode(out, bEndIdx + bodyEnd.length()); } diff --git a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Stomp.java b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Stomp.java similarity index 87% rename from okhttps-stomp/src/main/java/cn/zhxu/stomp/Stomp.java rename to okhttps-stomp/src/main/java/com/ejlchina/stomp/Stomp.java index f8555564..f674fa72 100644 --- a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Stomp.java +++ b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Stomp.java @@ -1,11 +1,13 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; -import cn.zhxu.okhttps.Platform; -import cn.zhxu.okhttps.WHttpTask; -import cn.zhxu.okhttps.WebSocket; +import com.ejlchina.okhttps.OnCallback; +import com.ejlchina.okhttps.Platform; +import com.ejlchina.okhttps.WHttpTask; +import com.ejlchina.okhttps.WebSocket; + +import okio.ByteString; import java.util.*; -import java.util.function.Consumer; /** * 基于 OkHttps websockt 的 Stomp 客户端 @@ -28,10 +30,10 @@ public class Stomp { private final List subscribers; - private Consumer onConnected; - private Consumer onDisconnected; - private Consumer onException; - private Consumer onError; + private OnCallback onConnected; + private OnCallback onDisconnected; + private OnCallback onException; + private OnCallback onError; private final String disReceipt; @@ -117,9 +119,9 @@ private synchronized void doOnOpened(List
headers) { } private synchronized void doOnException(Throwable throwable) { - Consumer listener = onException; + OnCallback listener = onException; if (listener != null) { - listener.accept(throwable); + listener.on(throwable); } disconnecting = false; connecting = false; @@ -133,9 +135,9 @@ private synchronized void doOnClosed(WebSocket.Close close) { for (Subscriber subscriber : subscribers) { subscriber.resetStatus(); } - Consumer listener = onDisconnected; + OnCallback listener = onDisconnected; if (listener != null) { - listener.accept(close); + listener.on(close); } } @@ -212,7 +214,7 @@ public synchronized void disconnect(boolean immediate) { * @param onConnected 连接成功回调 * @return Stomp */ - public Stomp setOnConnected(Consumer onConnected) { + public Stomp setOnConnected(OnCallback onConnected) { this.onConnected = onConnected; return this; } @@ -222,7 +224,7 @@ public Stomp setOnConnected(Consumer onConnected) { * @param onDisconnected 断开连接回调 * @return Stomp */ - public Stomp setOnDisconnected(Consumer onDisconnected) { + public Stomp setOnDisconnected(OnCallback onDisconnected) { this.onDisconnected = onDisconnected; return this; } @@ -233,7 +235,7 @@ public Stomp setOnDisconnected(Consumer onDisconnected) { * @param onException 异常回调 * @return Stomp */ - public Stomp setOnException(Consumer onException) { + public Stomp setOnException(OnCallback onException) { this.onException = onException; return this; } @@ -243,7 +245,7 @@ public Stomp setOnException(Consumer onException) { * @param onError 错误回调 * @return Stomp */ - public Stomp setOnError(Consumer onError) { + public Stomp setOnError(OnCallback onError) { this.onError = onError; return this; } @@ -295,7 +297,7 @@ public void send(Message message) { * @param callback 消息回调 * @return Stomp */ - public Stomp topic(String destination, Consumer callback) { + public Stomp topic(String destination, OnCallback callback) { return topic(destination, null, callback); } @@ -306,7 +308,7 @@ public Stomp topic(String destination, Consumer callback) { * @param callback 消息回调 * @return Stomp */ - public Stomp topic(String destination, List
headers, Consumer callback) { + public Stomp topic(String destination, List
headers, OnCallback callback) { return subscribe(TOPIC + destination, headers, callback); } @@ -316,7 +318,7 @@ public Stomp topic(String destination, List
headers, Consumer c * @param callback 消息回调 * @return Stomp */ - public Stomp queue(String destination, Consumer callback) { + public Stomp queue(String destination, OnCallback callback) { return queue(destination, null, callback); } @@ -327,7 +329,7 @@ public Stomp queue(String destination, Consumer callback) { * @param callback 消息回调 * @return Stomp */ - public Stomp queue(String destination, List
headers, Consumer callback) { + public Stomp queue(String destination, List
headers, OnCallback callback) { return subscribe(QUEUE + destination, headers, callback); } @@ -338,14 +340,13 @@ public Stomp queue(String destination, List
headers, Consumer c * @param callback 消息回调 * @return Stomp */ - public synchronized Stomp subscribe(String destination, List
headers, Consumer callback) { + public synchronized Stomp subscribe(String destination, List
headers, OnCallback callback) { if (destination == null || destination.isEmpty()) { throw new IllegalArgumentException("destination can not be empty!"); } for (Subscriber s: subscribers) { if (s.destinationEqual(destination)) { - Platform.logError("The destination [" + destination + "] has already been subscribed!"); - return this; + throw new IllegalStateException("The destination [" + destination + "] has already been subscribed!"); } } Subscriber subscriber = new Subscriber(this, destination, callback, headers); @@ -367,7 +368,7 @@ public void ack(Message message) { headers.add(msgId); send(new Message(Commands.ACK, headers, null)); } else { - Platform.logError("subscription and message-id not found in " + message + ", so it can not be ack!"); + Platform.logError("subscription and message-id not found in " + message.toString() + ", so it can not be ack!"); } } @@ -407,11 +408,7 @@ private synchronized void receive(Message msg) { String command = msg.getCommand(); if (Commands.CONNECTED.equals(command)) { String hbHeader = msg.headerValue(Header.HEART_BEAT); - synchronized (this) { - connected = true; - connecting = false; - onConnectedFrameReceived(hbHeader); - } + onConnectedFrameReceived(hbHeader); } else if (Commands.MESSAGE.equals(command)) { String id = msg.headerValue(Header.SUBSCRIPTION); if (id != null) { @@ -427,9 +424,9 @@ private synchronized void receive(Message msg) { disconnect(true); } } else if (Commands.ERROR.equals(command)) { - Consumer listener = onError; + OnCallback listener = onError; if (listener != null) { - listener.accept(msg); + listener.on(msg); } connecting = false; } @@ -444,18 +441,21 @@ private void onConnectedFrameReceived(String hbHeader) { int pongSeconds = Integer.parseInt(heartbeats[0]) / 1000; if (pingSeconds > 0 || pongSeconds > 0) { if (task.pingSupplier() == null) { - task.pingSupplier(() -> "\n"); + task.pingSupplier(() -> ByteString.of((byte) 0x0A)); } task.heatbeat(Math.max(pingSeconds, pingSecs), Math.max(pongSeconds, pongSecs)); } } - Consumer listener = onConnected; - if (listener != null) { - listener.accept(this); + synchronized (this) { + for (Subscriber s: subscribers) { + s.subscribe(); + } + connected = true; + connecting = false; } - // 为兼容 Android 低版本,这里不使用 JDK8 的 List.forEach(..) 方法 - for (Subscriber subscriber: subscribers) { - subscriber.subscribe(); + OnCallback listener = onConnected; + if (listener != null) { + listener.on(this); } } diff --git a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Subscriber.java b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Subscriber.java similarity index 90% rename from okhttps-stomp/src/main/java/cn/zhxu/stomp/Subscriber.java rename to okhttps-stomp/src/main/java/com/ejlchina/stomp/Subscriber.java index 0378012a..30782f9b 100644 --- a/okhttps-stomp/src/main/java/cn/zhxu/stomp/Subscriber.java +++ b/okhttps-stomp/src/main/java/com/ejlchina/stomp/Subscriber.java @@ -1,10 +1,11 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; + +import com.ejlchina.okhttps.OnCallback; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.UUID; -import java.util.function.Consumer; public class Subscriber { @@ -12,11 +13,11 @@ public class Subscriber { private final Stomp stomp; private final String id; private final String destination; - private final Consumer callback; + private final OnCallback callback; private final List
headers; private boolean subscribed; - public Subscriber(Stomp stomp, String destination, Consumer callback, List
headers) { + public Subscriber(Stomp stomp, String destination, OnCallback callback, List
headers) { this.stomp = stomp; this.id = UUID.randomUUID().toString(); this.destination = destination; @@ -78,7 +79,7 @@ public boolean destinationEqual(String destination) { public boolean tryCallback(String id, Message msg) { if (this.id.equals(id)) { - callback.accept(msg); + callback.on(msg); return true; } return false; diff --git a/okhttps-stomp/src/main/java/module-info.java b/okhttps-stomp/src/main/java/module-info.java new file mode 100644 index 00000000..99671369 --- /dev/null +++ b/okhttps-stomp/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module okhttps.stomp { + + requires okhttps; + requires okio; + + exports com.ejlchina.stomp; + +} \ No newline at end of file diff --git a/okhttps-stomp/src/test/java/cn/zhxu/stomp/Test.java b/okhttps-stomp/src/test/java/cn/zhxu/stomp/Test.java deleted file mode 100644 index 0564b09e..00000000 --- a/okhttps-stomp/src/test/java/cn/zhxu/stomp/Test.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.zhxu.stomp; - -import cn.zhxu.okhttps.OkHttps; - -import java.util.ArrayList; -import java.util.List; - -public class Test { - - public static void main(String[] args) throws InterruptedException { - - List
headers = new ArrayList<>(); - headers.add(new Header("login", "xxx")); - headers.add(new Header("passcode", "xxx")); - headers.add(new Header("host", "test")); - - Stomp stomp = Stomp.over(OkHttps.webSocket("ws://172.31.0.202:15674/ws").heatbeat(10, 10)) - .setOnConnected(s -> { - System.out.println("OnConnected"); - }) - .connect(headers); - - stomp.topic("/aaa", msg -> { - System.out.println("收到消息:" + msg); - System.out.println("内容:" + msg.getPayload()); - }); - - Thread.sleep(1000000); - - } - -} diff --git a/okhttps-stomp/src/test/java/cn/zhxu/stomp/MsgCodecTestCases.java b/okhttps-stomp/src/test/java/com/ejlchina/stomp/MsgCodecTestCases.java similarity index 88% rename from okhttps-stomp/src/test/java/cn/zhxu/stomp/MsgCodecTestCases.java rename to okhttps-stomp/src/test/java/com/ejlchina/stomp/MsgCodecTestCases.java index 86eff6c8..71bb34c2 100644 --- a/okhttps-stomp/src/test/java/cn/zhxu/stomp/MsgCodecTestCases.java +++ b/okhttps-stomp/src/test/java/com/ejlchina/stomp/MsgCodecTestCases.java @@ -1,21 +1,25 @@ -package cn.zhxu.stomp; +package com.ejlchina.stomp; +import com.ejlchina.okhttps.OnCallback; +import com.ejlchina.okhttps.test.BaseTest; import org.junit.Assert; import org.junit.Test; +import com.ejlchina.okhttps.OkHttps; + import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; +import java.util.concurrent.CountDownLatch; public class MsgCodecTestCases { - static class DecodeCallback implements Consumer { + static class DecodeCallback implements OnCallback { private final List list = new ArrayList<>(); @Override - public void accept(Message data) { + public void on(Message data) { list.add(data); } diff --git a/okhttps-test/pom.xml b/okhttps-test/pom.xml index cddf23cb..d5f8a65e 100644 --- a/okhttps-test/pom.xml +++ b/okhttps-test/pom.xml @@ -6,14 +6,14 @@ jar - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 - cn.zhxu + com.ejlchina okhttps ${project.version} diff --git a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/BaseTestCases.java b/okhttps-test/src/main/java/cn/zhxu/okhttps/test/BaseTestCases.java deleted file mode 100644 index ad49040c..00000000 --- a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/BaseTestCases.java +++ /dev/null @@ -1,347 +0,0 @@ -package cn.zhxu.okhttps.test; - -import cn.zhxu.data.Array; -import cn.zhxu.data.Mapper; -import cn.zhxu.data.TypeRef; -import cn.zhxu.okhttps.HTTP; -import cn.zhxu.okhttps.MsgConvertor; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.Assert; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.lang.reflect.Type; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -public abstract class BaseTestCases { - - final MockWebServer server = new MockWebServer(); - - final HTTP http; - - final MsgConvertor msgConvertor; - - final User user1 = new User(1, "Jack"); - final User user2 = new User(1, "Tom"); - - public BaseTestCases(MsgConvertor msgConvertor) { - this.http = HTTP.builder() - .baseUrl("http://" + server.getHostName() + ":" + server.getPort()) - .addMsgConvertor(msgConvertor) - .addMsgConvertor(new MsgConvertor.FormConvertor(msgConvertor)) - .build(); - this.msgConvertor = msgConvertor; - } - - public void run() throws Exception { - test_01_toMapper(); - test_02_toArray(); - test_03_serializeBean(); - test_04_toBean(); - test_05_toResult(); - test_06_toList(); - test_07_httpOnResponse(); - test_08_httpOnResBody(); - test_09_httpOnResMapper(); - test_10_httpOnResArray(); - test_11_httpOnResBean(); - test_12_httpOnResList(); - test_13_httpOnResString(); - test_14_httpMultiCallback(); - test_15_httpMultiCallback(); - testHttpSync(); - } - - abstract String getUser1Str(); - - abstract String getUser1ResultStr(); - - abstract String getUserListStr(); - - void assertUser1(User user) { - Assert.assertEquals(1, user.getId()); - Assert.assertEquals("Jack", user.getName()); - } - - void assertUser2(User user) { - Assert.assertEquals(2, user.getId()); - Assert.assertEquals("Tom", user.getName()); - } - - void assertMapper(Mapper mapper, int id, String name) { - Assert.assertEquals(2, mapper.size()); - mapper.forEach((key, data) -> { - if ("id".equals(key)) { - Assert.assertEquals(id, data.toInt()); - } - if ("name".equals(key)) { - Assert.assertEquals(name, data.toString()); - } - }); - Set keys = mapper.keySet(); - Assert.assertEquals(2, keys.size()); - Assert.assertTrue(keys.contains("id")); - Assert.assertTrue(keys.contains("name")); - Assert.assertFalse(mapper.isEmpty()); - Assert.assertEquals(2, mapper.size()); - Assert.assertEquals(id, mapper.getInt("id")); - Assert.assertFalse(mapper.has("age")); - Assert.assertEquals(0, mapper.getInt("age")); - Assert.assertEquals(name, mapper.getString("name")); - } - - void assertMapper1(Mapper mapper) { - assertMapper(mapper, 1, "Jack"); - assertUser1(mapper.toBean(User.class)); - } - - void assertMapper2(Mapper mapper) { - assertMapper(mapper, 2, "Tom"); - assertUser2(mapper.toBean(User.class)); - } - - void assertList(List list) { - Assert.assertEquals(2, list.size()); - assertUser1(list.get(0)); - assertUser2(list.get(1)); - } - - void assertArray(Array array) { - Assert.assertEquals(2, array.size()); - array.forEach((index, data) -> { - if (index == 0) { - assertMapper1(data.toMapper()); - } - if (index == 1) { - assertMapper2(data.toMapper()); - } - }); - assertMapper1(array.getMapper(0)); - assertMapper2(array.getMapper(1)); - assertList(array.toList(User.class)); - } - - void assertUser1Result(Result result) { - Assert.assertEquals(200, result.getCode()); - Assert.assertEquals("ok", result.getMsg()); - assertUser1(result.getData()); - } - - void test_01_toMapper() { - InputStream in = new ByteArrayInputStream(getUser1Str().getBytes(StandardCharsets.UTF_8)); - assertMapper1(msgConvertor.toMapper(in, StandardCharsets.UTF_8)); - assertMapper1(msgConvertor.toMapper(getUser1Str())); - System.out.println("case 01 passed!"); - } - - void test_02_toArray() { - InputStream in = new ByteArrayInputStream(getUserListStr().getBytes(StandardCharsets.UTF_8)); - assertArray(msgConvertor.toArray(in, StandardCharsets.UTF_8)); - assertArray(msgConvertor.toArray(getUserListStr())); - System.out.println("case 02 passed!"); - } - - void test_03_serializeBean() { - byte[] data = msgConvertor.serialize(user1, StandardCharsets.UTF_8); - Assert.assertEquals(getUser1Str(), new String(data, StandardCharsets.UTF_8)); - Assert.assertEquals(getUser1Str(), msgConvertor.serialize(user1)); - System.out.println("case 03 passed!"); - } - - void test_04_toBean() { - String json = getUser1Str(); - InputStream in = new ByteArrayInputStream(json.getBytes()); - assertUser1(msgConvertor.toBean(User.class, in, StandardCharsets.UTF_8)); - assertUser1(msgConvertor.toBean(User.class, json)); - System.out.println("case 04 passed!"); - } - - void test_05_toResult() { - String json = getUser1ResultStr(); - InputStream in = new ByteArrayInputStream(json.getBytes()); - Type type = new TypeRef>() {}.getType(); - assertUser1Result(msgConvertor.toBean(type, in, StandardCharsets.UTF_8)); - assertUser1Result(msgConvertor.toBean(type, json)); - System.out.println("case 05 passed!"); - } - - void test_06_toList() { - String json = getUserListStr(); - InputStream in = new ByteArrayInputStream(json.getBytes()); - assertList(msgConvertor.toList(User.class, in, StandardCharsets.UTF_8)); - assertList(msgConvertor.toList(User.class, json)); - System.out.println("case 06 passed!"); - } - - void test_07_httpOnResponse() throws InterruptedException { - server.enqueue(new MockResponse().setBody(getUser1Str())); - CountDownLatch latch = new CountDownLatch(1); - http.async("/") - .setOnResponse(res -> { - assertUser1(res.getBody().toBean(User.class)); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 07 passed!"); - } - - void test_08_httpOnResBody() throws InterruptedException { - server.enqueue(new MockResponse().setBody(getUser1Str())); - CountDownLatch latch = new CountDownLatch(1); - http.async("/") - .setOnResBody(body -> { - assertUser1(body.toBean(User.class)); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 08 passed!"); - } - - void test_09_httpOnResMapper() throws InterruptedException { - server.enqueue(new MockResponse().setBody(getUser1Str())); - CountDownLatch latch = new CountDownLatch(1); - http.async("/") - .setOnResMapper(mapper -> { - assertMapper1(mapper); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 09 passed!"); - } - - void test_10_httpOnResArray() throws InterruptedException { - server.enqueue(new MockResponse().setBody(getUserListStr())); - CountDownLatch latch = new CountDownLatch(1); - http.async("/") - .setOnResArray(array -> { - assertArray(array); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 10 passed!"); - } - - void test_11_httpOnResBean() throws InterruptedException { - server.enqueue(new MockResponse().setBody(getUser1Str())); - CountDownLatch latch = new CountDownLatch(1); - http.async("/") - .setOnResBean(User.class, user -> { - assertUser1(user); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1000, TimeUnit.SECONDS)); - System.out.println("case 11 passed!"); - } - - void test_12_httpOnResList() throws InterruptedException { - server.enqueue(new MockResponse().setBody(getUserListStr())); - CountDownLatch latch = new CountDownLatch(1); - http.async("/") - .setOnResList(User.class, list -> { - assertList(list); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 12 passed!"); - } - - void test_13_httpOnResString() throws InterruptedException { - String body = getUser1Str(); - server.enqueue(new MockResponse().setBody(body)); - CountDownLatch latch = new CountDownLatch(1); - http.async("/") - .setOnResString(str -> { - Assert.assertEquals(body, str); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 13 passed!"); - } - - void test_14_httpMultiCallback() throws InterruptedException { - String user1Str = getUser1Str(); - server.enqueue(new MockResponse().setBody(user1Str)); - CountDownLatch latch = new CountDownLatch(5); - http.async("/") - .setOnResponse(res -> { - assertUser1(res.getBody().toBean(User.class)); - latch.countDown(); - }) - .setOnResBody(body -> { - assertMapper1(body.toMapper()); - latch.countDown(); - }) - .setOnResMapper(mapper -> { - assertMapper1(mapper); - latch.countDown(); - }) - .setOnResBean(User.class, user -> { - assertUser1(user); - latch.countDown(); - }) - .setOnResString(str -> { - Assert.assertEquals(user1Str, str); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 14 passed!"); - } - - - void test_15_httpMultiCallback() throws InterruptedException { - String userListStr = getUserListStr(); - server.enqueue(new MockResponse().setBody(userListStr)); - CountDownLatch latch = new CountDownLatch(5); - http.async("/") - .setOnResponse(res -> { - assertList(res.getBody().toList(User.class)); - latch.countDown(); - }) - .setOnResBody(body -> { - assertArray(body.toArray()); - latch.countDown(); - }) - .setOnResList(User.class ,list -> { - assertList(list); - latch.countDown(); - }) - .setOnResArray(array -> { - assertArray(array); - latch.countDown(); - }) - .setOnResString(str -> { - Assert.assertEquals(userListStr, str); - latch.countDown(); - }) - .setOnException(Throwable::printStackTrace) - .get(); - Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); - System.out.println("case 15 passed!"); - } - - void testHttpSync() { - - } - -} diff --git a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/BaseTest.java b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/BaseTest.java similarity index 96% rename from okhttps-test/src/main/java/cn/zhxu/okhttps/test/BaseTest.java rename to okhttps-test/src/main/java/com/ejlchina/okhttps/test/BaseTest.java index 9b218884..158b0f3a 100644 --- a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/BaseTest.java +++ b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/BaseTest.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.test; +package com.ejlchina.okhttps.test; import java.text.SimpleDateFormat; import java.util.Date; diff --git a/okhttps-test/src/main/java/com/ejlchina/okhttps/test/BaseTestCases.java b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/BaseTestCases.java new file mode 100644 index 00000000..6381065a --- /dev/null +++ b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/BaseTestCases.java @@ -0,0 +1,130 @@ +package com.ejlchina.okhttps.test; + +import com.ejlchina.data.Array; +import com.ejlchina.data.Mapper; +import com.ejlchina.data.TypeRef; +import com.ejlchina.okhttps.MsgConvertor; +import org.junit.Assert; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Set; + +public abstract class BaseTestCases { + + MsgConvertor msgConvertor; + + public BaseTestCases(MsgConvertor msgConvertor) { + this.msgConvertor = msgConvertor; + } + + public void run() throws Exception { + testToMapper(); + testToArray(); + testSerializeBean(); + testToBean(); + testToResult(); + testToList(); + } + + abstract String getUserObjectStr(); + + abstract String getResultUserObjectStr(); + + abstract String getUserListStr(); + + void testToMapper() { + String json = getUserObjectStr(); + InputStream in = new ByteArrayInputStream(json.getBytes()); + Mapper mapper = msgConvertor.toMapper(in, StandardCharsets.UTF_8); + + mapper.forEach((key, data) -> { + if ("id".equals(key)) { + Assert.assertEquals(1, data.toInt()); + } + if ("name".equals(key)) { + Assert.assertEquals("Jack", data.toString()); + } + }); + + Set keys = mapper.keySet(); + Assert.assertEquals(2, keys.size()); + Assert.assertTrue(keys.contains("id")); + Assert.assertTrue(keys.contains("name")); + Assert.assertFalse(mapper.isEmpty()); + Assert.assertEquals(2, mapper.size()); + Assert.assertEquals(1, mapper.getInt("id")); + Assert.assertFalse(mapper.has("age")); + Assert.assertEquals(0, mapper.getInt("age")); + Assert.assertEquals("Jack", mapper.getString("name")); + System.out.println("case 1 passed!"); + } + + void testToArray() { + String json = getUserListStr(); + InputStream in = new ByteArrayInputStream(json.getBytes()); + + Array array = msgConvertor.toArray(in, StandardCharsets.UTF_8); + + array.forEach((index, data) -> { + System.out.println("index = " + index); + System.out.println("data = " + data.toMapper()); + }); + + Assert.assertFalse(array.isEmpty()); + Assert.assertEquals(2, array.size()); + Mapper json1 = array.getMapper(0); + Mapper json2 = array.getMapper(1); + Assert.assertEquals(1, json1.getInt("id")); + Assert.assertEquals("Jack", json1.getString("name")); + Assert.assertEquals(2, json2.getInt("id")); + Assert.assertEquals("Tom", json2.getString("name")); + + System.out.println("case 2 passed!"); + } + + void testSerializeBean() { + byte[] data = msgConvertor.serialize(new User(1, "Jack"), StandardCharsets.UTF_8); + String json = new String(data, StandardCharsets.UTF_8); + Assert.assertEquals(getUserObjectStr(), json); + System.out.println("case 3 passed!"); + } + + void testToBean() { + String json = getUserObjectStr(); + InputStream in = new ByteArrayInputStream(json.getBytes()); + User user = msgConvertor.toBean(User.class, in, StandardCharsets.UTF_8); + Assert.assertEquals(1, user.getId()); + Assert.assertEquals("Jack", user.getName()); + System.out.println("case 6 passed!"); + } + + void testToResult() { + String json = getResultUserObjectStr(); + InputStream in = new ByteArrayInputStream(json.getBytes()); + Result result = msgConvertor.toBean(new TypeRef>(){}.getType(), in, StandardCharsets.UTF_8); + Assert.assertEquals(200, result.getCode()); + Assert.assertEquals("ok", result.getMsg()); + User user = result.getData(); + Assert.assertEquals(1, user.getId()); + Assert.assertEquals("Jack", user.getName()); + System.out.println("case 7 passed!"); + } + + void testToList() { + String json = getUserListStr(); + InputStream in = new ByteArrayInputStream(json.getBytes()); + List users = msgConvertor.toList(User.class, in, StandardCharsets.UTF_8); + Assert.assertEquals(2, users.size()); + User u1 = users.get(0); + User u2 = users.get(1); + Assert.assertEquals(1, u1.getId()); + Assert.assertEquals("Jack", u1.getName()); + Assert.assertEquals(2, u2.getId()); + Assert.assertEquals("Tom", u2.getName()); + System.out.println("case 8 passed!"); + } + +} diff --git a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/DateBean.java b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/DateBean.java similarity index 93% rename from okhttps-test/src/main/java/cn/zhxu/okhttps/test/DateBean.java rename to okhttps-test/src/main/java/com/ejlchina/okhttps/test/DateBean.java index 9030919d..34cfdb53 100644 --- a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/DateBean.java +++ b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/DateBean.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.test; +package com.ejlchina.okhttps.test; import java.util.Date; diff --git a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/JsonTestCases.java b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/JsonTestCases.java similarity index 86% rename from okhttps-test/src/main/java/cn/zhxu/okhttps/test/JsonTestCases.java rename to okhttps-test/src/main/java/com/ejlchina/okhttps/test/JsonTestCases.java index 72019c51..28c90a0f 100644 --- a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/JsonTestCases.java +++ b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/JsonTestCases.java @@ -1,6 +1,6 @@ -package cn.zhxu.okhttps.test; +package com.ejlchina.okhttps.test; -import cn.zhxu.okhttps.MsgConvertor; +import com.ejlchina.okhttps.MsgConvertor; import org.junit.Assert; import java.nio.charset.StandardCharsets; @@ -19,12 +19,12 @@ public void run() throws Exception { } @Override - String getUser1Str() { + String getUserObjectStr() { return "{\"id\":1,\"name\":\"Jack\"}"; } @Override - String getUser1ResultStr() { + String getResultUserObjectStr() { return "{\"code\": 200, \"data\": {\"id\":1,\"name\":\"Jack\"}, \"msg\": \"ok\"}"; } diff --git a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/Result.java b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/Result.java similarity index 93% rename from okhttps-test/src/main/java/cn/zhxu/okhttps/test/Result.java rename to okhttps-test/src/main/java/com/ejlchina/okhttps/test/Result.java index 42232d56..d0a3b47d 100644 --- a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/Result.java +++ b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/Result.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.test; +package com.ejlchina.okhttps.test; import javax.xml.bind.annotation.XmlRootElement; diff --git a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/User.java b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/User.java similarity index 97% rename from okhttps-test/src/main/java/cn/zhxu/okhttps/test/User.java rename to okhttps-test/src/main/java/com/ejlchina/okhttps/test/User.java index e76583f1..c886339d 100644 --- a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/User.java +++ b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/User.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.test; +package com.ejlchina.okhttps.test; import javax.xml.bind.annotation.XmlRootElement; diff --git a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/XmlTestCases.java b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/XmlTestCases.java similarity index 64% rename from okhttps-test/src/main/java/cn/zhxu/okhttps/test/XmlTestCases.java rename to okhttps-test/src/main/java/com/ejlchina/okhttps/test/XmlTestCases.java index 399a311d..830203bf 100644 --- a/okhttps-test/src/main/java/cn/zhxu/okhttps/test/XmlTestCases.java +++ b/okhttps-test/src/main/java/com/ejlchina/okhttps/test/XmlTestCases.java @@ -1,6 +1,6 @@ -package cn.zhxu.okhttps.test; +package com.ejlchina.okhttps.test; -import cn.zhxu.okhttps.MsgConvertor; +import com.ejlchina.okhttps.MsgConvertor; public class XmlTestCases extends BaseTestCases { @@ -10,12 +10,12 @@ public XmlTestCases(MsgConvertor msgConvertor) { } @Override - String getUser1Str() { + String getUserObjectStr() { return "1Jack"; } @Override - String getUser1ResultStr() { + String getResultUserObjectStr() { return "\n" + "\t200\n" + "\tok\n" + @@ -27,7 +27,7 @@ String getUser1ResultStr() { @Override String getUserListStr() { - return "1Jack2Tom"; + return "1Jack2Tom"; } } diff --git a/okhttps-xml/README.md b/okhttps-xml/README.md new file mode 100644 index 00000000..00fbfb1f --- /dev/null +++ b/okhttps-xml/README.md @@ -0,0 +1,24 @@ +# OkHttps Xml + +#### 介绍 + +基于 OkHttps 与 Xml 集成扩展(仅支持 Java 8) + + +##### Maven + +```xml + + com.ejlchina + okhttps-xml + 3.4.5 + +``` + +##### Gradle + +```groovy +implementation 'com.ejlchina:okhttps-xml:3.4.5' +``` + +#### 更多请参阅 [http://okhttps.ejlchina.com/](http://okhttps.ejlchina.com/) diff --git a/okhttps-snack3/pom.xml b/okhttps-xml/pom.xml similarity index 70% rename from okhttps-snack3/pom.xml rename to okhttps-xml/pom.xml index 364fdeae..17fec0dc 100644 --- a/okhttps-snack3/pom.xml +++ b/okhttps-xml/pom.xml @@ -1,29 +1,29 @@ 4.0.0 - okhttps-snack3 - OkHttps Snack3 + okhttps-xml + OkHttps Xml jar - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 - cn.zhxu + com.ejlchina okhttps ${project.version} - cn.zhxu - data-snack3 + com.ejlchina + data-xml ${data.version} - cn.zhxu + com.ejlchina okhttps-test ${project.version} test @@ -31,6 +31,6 @@ - okhttps-snack3 + okhttps-xml \ No newline at end of file diff --git a/okhttps-xml/src/main/java/com/ejlchina/okhttps/xml/XmlMsgConvertor.java b/okhttps-xml/src/main/java/com/ejlchina/okhttps/xml/XmlMsgConvertor.java new file mode 100644 index 00000000..475cdd5e --- /dev/null +++ b/okhttps-xml/src/main/java/com/ejlchina/okhttps/xml/XmlMsgConvertor.java @@ -0,0 +1,28 @@ +package com.ejlchina.okhttps.xml; + +import com.ejlchina.data.Deserializer; +import com.ejlchina.data.xml.XmlDataConvertor; +import com.ejlchina.okhttps.ConvertProvider; +import com.ejlchina.okhttps.MsgConvertor; + +import javax.xml.parsers.DocumentBuilderFactory; + +public class XmlMsgConvertor extends XmlDataConvertor implements MsgConvertor, ConvertProvider { + + public XmlMsgConvertor() { } + + public XmlMsgConvertor(Deserializer deserializer, DocumentBuilderFactory dbFactory) { + super(deserializer, dbFactory); + } + + @Override + public String mediaType() { + return "application/xml; charset={charset}"; + } + + @Override + public MsgConvertor getConvertor() { + return new XmlMsgConvertor(); + } + +} diff --git a/okhttps-xml/src/main/java/module-info.java b/okhttps-xml/src/main/java/module-info.java new file mode 100644 index 00000000..6f22800f --- /dev/null +++ b/okhttps-xml/src/main/java/module-info.java @@ -0,0 +1,13 @@ +module okhttps.xml { + + requires okhttps; + requires data.core; + requires data.xml; + requires java.xml; + + provides com.ejlchina.okhttps.ConvertProvider with + com.ejlchina.okhttps.xml.XmlMsgConvertor; + + exports com.ejlchina.okhttps.xml; + +} \ No newline at end of file diff --git a/okhttps-xml/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider b/okhttps-xml/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider new file mode 100644 index 00000000..311e6839 --- /dev/null +++ b/okhttps-xml/src/main/resources/META-INF/services/com.ejlchina.okhttps.ConvertProvider @@ -0,0 +1 @@ +com.ejlchina.okhttps.xml.XmlMsgConvertor \ No newline at end of file diff --git a/okhttps-xml/src/test/java/com/ejlchina/okhttps/TestCases.java b/okhttps-xml/src/test/java/com/ejlchina/okhttps/TestCases.java new file mode 100644 index 00000000..117ea624 --- /dev/null +++ b/okhttps-xml/src/test/java/com/ejlchina/okhttps/TestCases.java @@ -0,0 +1,41 @@ +package com.ejlchina.okhttps; + +import com.ejlchina.data.Mapper; +import com.ejlchina.okhttps.test.XmlTestCases; +import com.ejlchina.okhttps.xml.XmlMsgConvertor; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.junit.Test; + +public class TestCases { + + protected MockWebServer server = new MockWebServer(); + + protected String mockUrl = "http://" + server.getHostName() + ":" + server.getPort(); + + + + @Test + public void doTest() throws Exception { + MsgConvertor msgConvertor = new XmlMsgConvertor(); + new XmlTestCases(msgConvertor).run(); + } + + @Test + public void test() { + HTTP http = HTTP.builder() + .addMsgConvertor(new XmlMsgConvertor()) + .build(); + + String xmlstr = "物联网(数据)月流量包定向30元1GB(201604)985810387181048576202105310000002038物联网(数据)月流量包定向30元1GB(201604)20210501000000KB10处理成功!10000001902021053156633564161410319993420"; + + server.enqueue(new MockResponse().setBody(xmlstr)); + + Mapper mapper = http.sync(mockUrl).get().getBody().toMapper(); + + System.out.println(mapper); + System.out.println(mapper.getMapper("web:CurrAcuRsp").getMapper("CumulRspList").getString("ACCU_NAME")); + } + +} + diff --git a/okhttps/README.md b/okhttps/README.md index 4950d947..ab5f8b20 100644 --- a/okhttps/README.md +++ b/okhttps/README.md @@ -9,16 +9,16 @@ ```xml - cn.zhxu + com.ejlchina okhttps - 3.5.3 + 3.4.5 ``` ##### Gradle ```groovy -implementation 'cn.zhxu:okhttps:3.5.3' +implementation 'com.ejlchina:okhttps:3.4.5' ``` -#### 更多请参阅 [https://ok.zhxu.cn/](https://ok.zhxu.cn/) +#### 更多请参阅 [http://okhttps.ejlchina.com/](http://okhttps.ejlchina.com/) diff --git a/okhttps/pom.xml b/okhttps/pom.xml index be91b92b..d5aedb43 100644 --- a/okhttps/pom.xml +++ b/okhttps/pom.xml @@ -6,14 +6,14 @@ jar - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 - cn.zhxu + com.ejlchina data-core ${data.version} diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/BodyPara.java b/okhttps/src/main/java/cn/zhxu/okhttps/BodyPara.java deleted file mode 100644 index ca88bd81..00000000 --- a/okhttps/src/main/java/cn/zhxu/okhttps/BodyPara.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.zhxu.okhttps; - -/** - * 请求体表单参数 - * @since v4.1.0 - */ -public class BodyPara { - - private final String type; - private final Object value; - - public BodyPara(String type, Object value) { - this.type = type; - this.value = value; - } - - public String getType() { - return type; - } - - public Object getValue() { - return value; - } - -} diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/Process.java b/okhttps/src/main/java/cn/zhxu/okhttps/Process.java deleted file mode 100644 index 65c8b73a..00000000 --- a/okhttps/src/main/java/cn/zhxu/okhttps/Process.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.zhxu.okhttps; - -/** - * 进度(上传或下载) - */ -public interface Process { - - int DEFAULT_STEP_BYTES = 8192; - - /** - * 当请求体大小未知(流式上传)时,该方法始终返回 -1 - * 当请求体大小为 0 时,该方法始终返回 1 - * @return 完成比例 - */ - double getRate(); - - /** - * 当请求体大小未知(流式上传)时,该方法返回 -1 - * @return 总字节数 - */ - long getTotalBytes(); - - /** - * @return 已完成字节数 - */ - long getDoneBytes(); - - /** - * 只有当 当请求体大小已知 的情况下,该方法才可能返回 true - * @return 任务是否完成 - */ - boolean isDone(); - -} diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/AHttpTask.java b/okhttps/src/main/java/com/ejlchina/okhttps/AHttpTask.java similarity index 77% rename from okhttps/src/main/java/cn/zhxu/okhttps/AHttpTask.java rename to okhttps/src/main/java/com/ejlchina/okhttps/AHttpTask.java index e038cc30..a29cf360 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/AHttpTask.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/AHttpTask.java @@ -1,21 +1,21 @@ -package cn.zhxu.okhttps; - -import cn.zhxu.data.Array; -import cn.zhxu.data.Mapper; -import cn.zhxu.data.TypeRef; -import cn.zhxu.okhttps.HttpResult.State; -import cn.zhxu.okhttps.internal.AbstractHttpClient; -import cn.zhxu.okhttps.internal.CopyInterceptor; -import cn.zhxu.okhttps.internal.RealHttpResult; +package com.ejlchina.okhttps; + +import com.ejlchina.data.Array; +import com.ejlchina.data.Mapper; +import com.ejlchina.data.TypeRef; +import com.ejlchina.okhttps.HttpResult.State; +import com.ejlchina.okhttps.internal.*; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.List; import java.util.concurrent.CountDownLatch; -import java.util.function.Consumer; + /** * 异步 Http 请求任务 @@ -26,20 +26,20 @@ public class AHttpTask extends HttpTask { - private Consumer onResponse; - private Consumer onException; - private Consumer onComplete; + private OnCallback onResponse; + private OnCallback onException; + private OnCallback onComplete; private boolean responseOnIO; private boolean exceptionOnIO; private boolean completeOnIO; - private Consumer onResBody; - private Consumer onResMapper; - private Consumer onResArray; - private Consumer onResString; - private Consumer onResBean; - private Consumer onResList; + private OnCallback onResBody; + private OnCallback onResMapper; + private OnCallback onResArray; + private OnCallback onResString; + private OnCallback onResBean; + private OnCallback onResList; private boolean resBodyOnIO; private boolean resMapperOnIO; @@ -66,7 +66,7 @@ public boolean isAsyncHttp() { * @param onException 请求异常回调 * @return HttpTask 实例 */ - public AHttpTask setOnException(Consumer onException) { + public AHttpTask setOnException(OnCallback onException) { this.onException = onException; exceptionOnIO = nextOnIO; nextOnIO = false; @@ -78,7 +78,7 @@ public AHttpTask setOnException(Consumer onException) { * @param onComplete 请求完成回调 * @return HttpTask 实例 */ - public AHttpTask setOnComplete(Consumer onComplete) { + public AHttpTask setOnComplete(OnCallback onComplete) { this.onComplete = onComplete; completeOnIO = nextOnIO; nextOnIO = false; @@ -90,7 +90,7 @@ public AHttpTask setOnComplete(Consumer onComplete) { * @param onResponse 请求响应回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResponse(Consumer onResponse) { + public synchronized AHttpTask setOnResponse(OnCallback onResponse) { this.onResponse = onResponse; responseOnIO = nextOnIO; nextOnIO = false; @@ -102,7 +102,7 @@ public synchronized AHttpTask setOnResponse(Consumer onResponse) { * @param onResBody 响应报文体回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResBody(Consumer onResBody) { + public synchronized AHttpTask setOnResBody(OnCallback onResBody) { this.onResBody = onResBody; resBodyOnIO = nextOnIO; nextOnIO = false; @@ -116,7 +116,7 @@ public synchronized AHttpTask setOnResBody(Consumer onResBody) * @param onResBean 响应 Bean 回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResBean(Class type, Consumer onResBean) { + public synchronized AHttpTask setOnResBean(Class type, OnCallback onResBean) { initBeanType(type); this.onResBean = onResBean; resBeanOnIO = nextOnIO; @@ -131,7 +131,7 @@ public synchronized AHttpTask setOnResBean(Class type, Consumer onResB * @param onResBean 响应 Bean 回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResBean(TypeRef type, Consumer onResBean) { + public synchronized AHttpTask setOnResBean(TypeRef type, OnCallback onResBean) { initBeanType(type.getType()); this.onResBean = onResBean; resBeanOnIO = nextOnIO; @@ -146,7 +146,7 @@ public synchronized AHttpTask setOnResBean(TypeRef type, Consumer onRe * @param onResList 请求响应回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResList(Class type, Consumer> onResList) { + public synchronized AHttpTask setOnResList(Class type, OnCallback> onResList) { if (type == null) { throw new IllegalArgumentException(" list type can not be null!"); } @@ -164,7 +164,7 @@ public synchronized AHttpTask setOnResList(Class type, Consumer> * @param onResMapper 请求响应回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResMapper(Consumer onResMapper) { + public synchronized AHttpTask setOnResMapper(OnCallback onResMapper) { this.onResMapper = onResMapper; resMapperOnIO = nextOnIO; nextOnIO = false; @@ -176,7 +176,7 @@ public synchronized AHttpTask setOnResMapper(Consumer onResMapper) { * @param onResArray 请求响应回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResArray(Consumer onResArray) { + public synchronized AHttpTask setOnResArray(OnCallback onResArray) { this.onResArray = onResArray; resArrayOnIO = nextOnIO; nextOnIO = false; @@ -188,7 +188,7 @@ public synchronized AHttpTask setOnResArray(Consumer onResArray) { * @param onResString 请求响应回调 * @return HttpTask 实例 */ - public synchronized AHttpTask setOnResString(Consumer onResString) { + public synchronized AHttpTask setOnResString(OnCallback onResString) { this.onResString = onResString; resStringOnIO = nextOnIO; nextOnIO = false; @@ -430,16 +430,15 @@ interface ResponseCallback { void on(Runnable runnable, boolean onIo); } - @SuppressWarnings("unchecked") - private synchronized Consumer complexOnResponse(OkHttpCall call) { + private synchronized OnCallback complexOnResponse(OkHttpCall call) { return res -> { - Consumer onResp = onResponse; - Consumer onBody = onResBody; - Consumer onMapper = onResMapper; - Consumer onArray = onResArray; - Consumer onBean = (Consumer) onResBean; - Consumer onList = (Consumer) onResList; - Consumer onString = onResString; + OnCallback onResp = onResponse; + OnCallback onBody = onResBody; + OnCallback onMapper = onResMapper; + OnCallback onArray = onResArray; + OnCallback onBean = onResBean; + OnCallback onList = onResList; + OnCallback onString = onResString; int count = 0; if (onResp != null) @@ -479,34 +478,61 @@ public void run() { }, onIo); if (onResp != null) { - callback.on(() -> onResp.accept(res), responseOnIO); + callback.on(() -> onResp.on(res), responseOnIO); } if (onBody != null) { - callback.on(() -> onBody.accept(body), resBodyOnIO); + callback.on(() -> onBody.on(body), resBodyOnIO); } if (onMapper != null) { Mapper mapper = body.toMapper(); - callback.on(() -> onMapper.accept(mapper), resMapperOnIO); + callback.on(() -> onMapper.on(mapper), resMapperOnIO); } if (onArray != null) { Array array = body.toArray(); - callback.on(() -> onArray.accept(array), resArrayOnIO); + callback.on(() -> onArray.on(array), resArrayOnIO); } if (onBean != null) { Object bean = body.toBean(beanType); - callback.on(() -> onBean.accept(bean), resBeanOnIO); + callback.on(() -> { + try { + callbackMethod(onBean.getClass(), bean.getClass()).invoke(onBean, bean); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new OkHttpsException("回调方法调用失败!", e); + } + }, resBeanOnIO); } if (onList != null) { List list = body.toList(listType); - callback.on(() -> onList.accept(list), resListOnIO); + callback.on(() -> { + try { + callbackMethod(onList.getClass(), list.getClass()).invoke(onList, list); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new OkHttpsException("回调方法调用失败!", e); + } + }, resListOnIO); } if (onString != null) { String string = body.toString(); - callback.on(() -> onString.accept(string), resStringOnIO); + callback.on(() -> onString.on(string), resStringOnIO); } }; } + static final String OnCallbackMethod = OnCallback.class.getDeclaredMethods()[0].getName(); + + private Method callbackMethod(Class clazz, Class paraType) { + Method[] methods = clazz.getDeclaredMethods(); + for (Method method : methods) { + Class[] paraTypes = method.getParameterTypes(); + if (method.getName().equals(OnCallbackMethod) && paraTypes.length == 1 + && paraTypes[0].isAssignableFrom(paraType)) { + method.setAccessible(true); + return method; + } + } + throw new IllegalStateException("没有可调用的方法"); + } + private void initBeanType(Type type) { if (type == null) { throw new IllegalArgumentException(" bean type can not be null!"); diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/Cancelable.java b/okhttps/src/main/java/com/ejlchina/okhttps/Cancelable.java similarity index 80% rename from okhttps/src/main/java/cn/zhxu/okhttps/Cancelable.java rename to okhttps/src/main/java/com/ejlchina/okhttps/Cancelable.java index e6b3db84..0c81a7ac 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/Cancelable.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/Cancelable.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; public interface Cancelable { diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/Config.java b/okhttps/src/main/java/com/ejlchina/okhttps/Config.java similarity index 67% rename from okhttps/src/main/java/cn/zhxu/okhttps/Config.java rename to okhttps/src/main/java/com/ejlchina/okhttps/Config.java index c2eeb36d..71a803c7 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/Config.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/Config.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; import java.util.ServiceLoader; @@ -7,10 +7,6 @@ */ public interface Config { - /** - * 配置 {@link OkHttps } 内部的 {@link HTTP } 实例 - * @param builder HTTP.Builder - */ void with(HTTP.Builder builder); static void config(HTTP.Builder builder) { diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/ConvertProvider.java b/okhttps/src/main/java/com/ejlchina/okhttps/ConvertProvider.java similarity index 94% rename from okhttps/src/main/java/cn/zhxu/okhttps/ConvertProvider.java rename to okhttps/src/main/java/com/ejlchina/okhttps/ConvertProvider.java index 0ce5d1ad..aa1600b9 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/ConvertProvider.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/ConvertProvider.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; import java.util.ServiceLoader; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/DownListener.java b/okhttps/src/main/java/com/ejlchina/okhttps/DownListener.java similarity index 89% rename from okhttps/src/main/java/cn/zhxu/okhttps/DownListener.java rename to okhttps/src/main/java/com/ejlchina/okhttps/DownListener.java index a4f4735b..53cbebed 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/DownListener.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/DownListener.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; /** * 下载监听接口 diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/Download.java b/okhttps/src/main/java/com/ejlchina/okhttps/Download.java similarity index 91% rename from okhttps/src/main/java/cn/zhxu/okhttps/Download.java rename to okhttps/src/main/java/com/ejlchina/okhttps/Download.java index fe622132..54026f2b 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/Download.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/Download.java @@ -1,7 +1,6 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; import java.io.*; -import java.util.function.Consumer; /** * 文件下载 @@ -14,9 +13,9 @@ public class Download { private final TaskExecutor taskExecutor; private final Ctrl ctrl; - private Consumer onSuccess; - private Consumer onFailure; - private Consumer onComplete; + private OnCallback onSuccess; + private OnCallback onFailure; + private OnCallback onComplete; private long doneBytes; private int buffSize = 0; private long seekBytes = 0; @@ -84,7 +83,7 @@ public Download nextOnIO() { * @param onSuccess 成功回调函数 * @return Download */ - public Download setOnSuccess(Consumer onSuccess) { + public Download setOnSuccess(OnCallback onSuccess) { this.onSuccess = onSuccess; sOnIO = nextOnIO; nextOnIO = false; @@ -96,7 +95,7 @@ public Download setOnSuccess(Consumer onSuccess) { * @param onFailure 失败回调函数 * @return Download */ - public Download setOnFailure(Consumer onFailure) { + public Download setOnFailure(OnCallback onFailure) { this.onFailure = onFailure; fOnIO = nextOnIO; nextOnIO = false; @@ -109,7 +108,7 @@ public Download setOnFailure(Consumer onFailure) { * @param onComplete 结束回调函数 * @return Download */ - public Download setOnComplete(Consumer onComplete) { + public Download setOnComplete(OnCallback onComplete) { this.onComplete = onComplete; cOnIO = nextOnIO; nextOnIO = false; @@ -332,23 +331,23 @@ private void doDownload(RandomAccessFile raFile) { } private void fireOnComplete() { - Consumer onComplete = this.onComplete; + OnCallback onComplete = this.onComplete; if (onComplete != null) { - taskExecutor.execute(() -> onComplete.accept(status), cOnIO); + taskExecutor.execute(() -> onComplete.on(status), cOnIO); } } private void fireOnSuccess() { - Consumer onSuccess = this.onSuccess; + OnCallback onSuccess = this.onSuccess; if (onSuccess != null) { - taskExecutor.execute(() -> onSuccess.accept(file), sOnIO); + taskExecutor.execute(() -> onSuccess.on(file), sOnIO); } } private void fireOnFailure(IOException e) { - Consumer onFailure = this.onFailure; + OnCallback onFailure = this.onFailure; if (onFailure != null) { - taskExecutor.execute(() -> onFailure.accept(new Failure(e)), fOnIO); + taskExecutor.execute(() -> onFailure.on(new Failure(e)), fOnIO); } else { throw new OkHttpsException("Download failed: ", e); } diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/DownloadHelper.java b/okhttps/src/main/java/com/ejlchina/okhttps/DownloadHelper.java similarity index 65% rename from okhttps/src/main/java/cn/zhxu/okhttps/DownloadHelper.java rename to okhttps/src/main/java/com/ejlchina/okhttps/DownloadHelper.java index 37dfac6d..94e582fc 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/DownloadHelper.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/DownloadHelper.java @@ -1,4 +1,6 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; + +import okhttp3.MediaType; import java.io.File; import java.io.UnsupportedEncodingException; @@ -14,22 +16,13 @@ public class DownloadHelper { private Map extMappings = new HashMap<>(); - public DownloadHelper() { - extMappings.put("text/plain", "txt"); - extMappings.put("audio/mpeg", "mp3"); extMappings.put("video/mpeg4", "mp4"); - extMappings.put("video/quicktime", "mov"); - extMappings.put("application/x-genesis-rom", "md"); - extMappings.put("application/x-xls", "xls"); - extMappings.put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx"); + extMappings.put("text/plain", "txt"); + extMappings.put("application/x-xls", "text/xls"); extMappings.put("application/vnd.android.package-archive", "apk"); extMappings.put("application/msword", "doc"); - extMappings.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx"); - extMappings.put("application/x-java-archive", "jar"); - extMappings.put("application/x-zip-compressed", "zip"); - extMappings.put("application/x-compressed-tar", "tar.gz"); - extMappings.put("application/x-rar", "rar"); + extMappings.put("x-zip-compressed", "zip"); } /** @@ -43,45 +36,33 @@ public String resolveFileName(HttpResult result) { if (contentDisposition == null || contentDisposition.length() < 1) { String urlPath = result.getTask().getUrl(); String urlName = urlPath.substring(urlPath.lastIndexOf("/") + 1); - return toFileName(urlName, result).replaceAll("[\"\\\\]", ""); + return toFileName(urlName, result); } try { String filename = URLDecoder.decode(contentDisposition.substring( contentDisposition.indexOf("filename=") + 9), StandardCharsets.UTF_8.name()); // 有些文件名会被包含在""里面,所以要去掉,不然无法读取文件后缀 - // 同时去掉 / 与 \ 符,避免发生目录穿越问题:https://github.com/troyzhxu/okhttps/issues/89 - return filename.replaceAll("[\"/\\\\]", ""); + return filename.replaceAll("\"", ""); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } - public String toFileName(String name, HttpResult result) { - int dotIdx = name.lastIndexOf('.'); - if (dotIdx > -1 && dotIdx < name.length() - 1) { + protected String toFileName(String name, HttpResult result) { + int dotIndex = name.lastIndexOf('.'); + if (dotIndex > -1 && dotIndex < name.length() - 1) { return name; } + MediaType type = result.getBody().getType(); // 获取文件扩展名 - String ext = getExt(result.getHeader("Content-Type")); - if (ext != null) { - if (dotIdx == -1) { - return name + "." + ext; - } - return name + ext; - } - return name; - } - - - public String getExt(String contentType) { - String ext = extMappings.get(contentType); + String ext = extMappings.get(type.toString()); if (ext == null) { - int i = contentType.indexOf('/'); - if (i > 0 && i < contentType.length() - 1) { - return contentType.substring(i + 1); - } + ext = type.subtype(); + } + if (dotIndex == -1) { + return name + "." + ext; } - return ext; + return name + ext; } /** diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/FilePara.java b/okhttps/src/main/java/com/ejlchina/okhttps/FilePara.java similarity index 96% rename from okhttps/src/main/java/cn/zhxu/okhttps/FilePara.java rename to okhttps/src/main/java/com/ejlchina/okhttps/FilePara.java index 6c8443eb..73070743 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/FilePara.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/FilePara.java @@ -1,6 +1,6 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; -import cn.zhxu.okhttps.internal.StreamRequestBody; +import com.ejlchina.okhttps.internal.StreamRequestBody; import okhttp3.MediaType; import okhttp3.RequestBody; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/HTTP.java b/okhttps/src/main/java/com/ejlchina/okhttps/HTTP.java similarity index 83% rename from okhttps/src/main/java/cn/zhxu/okhttps/HTTP.java rename to okhttps/src/main/java/com/ejlchina/okhttps/HTTP.java index 910d87f0..33240724 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/HTTP.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/HTTP.java @@ -1,13 +1,12 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; -import cn.zhxu.okhttps.okhttp.OkHttpBuilderImpl; -import okhttp3.WebSocket; +import com.ejlchina.okhttps.okhttp.OkHttpBuilderImpl; import okhttp3.*; +import okhttp3.WebSocket; import java.io.IOException; import java.nio.charset.Charset; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.Executor; /** @@ -88,28 +87,10 @@ public interface HTTP { /** * HTTP 构建器 - * 自 v3.5.0 起可通过系统环境变量 切换该方法返回的 构建器实现类 * @return HTTP 构建器 */ static Builder builder() { - String className = System.getProperty(Builder.class.getName()); - if (Platform.isNotBlank(className)) { - try { - Class dClass = Class.forName(className); - if (Builder.class.isAssignableFrom(dClass)) { - return (Builder) dClass.getDeclaredConstructor().newInstance(); - } else { - throw new OkHttpsException("The implementation class [" + className + "] you specified is not a subclass of " + Builder.class.getName()); - } - } catch (ClassNotFoundException e) { - throw new OkHttpsException("The implementation class [" + className + "] you specified can not be found", e); - } catch (NoSuchMethodException e) { - throw new OkHttpsException("There is none default constructor in [" + className + "] you specified", e); - } catch (ReflectiveOperationException e) { - throw new OkHttpsException("[" + className + "] can not be instanced", e); - } - } - return new OkHttpBuilderImpl(); // 默认构建器 + return new OkHttpBuilderImpl(); } /** @@ -166,13 +147,6 @@ interface Builder { Map getMediaTypes(); - /** - * 清空 ContentType - * @return Builder - * @since v3.5.0 - */ - HTTP.Builder clearContentTypes(); - /** * 配置支持的报文体类型 * @param contentTypes 报文体类型列表 @@ -315,7 +289,7 @@ interface Builder { String bodyType(); /** - * @since v3.4.2 + * @since v3.5.0 * 设置下载文件名解析器 * @param resolver 解析器 * @return Builder diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/HttpCall.java b/okhttps/src/main/java/com/ejlchina/okhttps/HttpCall.java similarity index 94% rename from okhttps/src/main/java/cn/zhxu/okhttps/HttpCall.java rename to okhttps/src/main/java/com/ejlchina/okhttps/HttpCall.java index 00c15fa8..4697510f 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/HttpCall.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/HttpCall.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; public interface HttpCall extends Cancelable { diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/HttpResult.java b/okhttps/src/main/java/com/ejlchina/okhttps/HttpResult.java similarity index 90% rename from okhttps/src/main/java/cn/zhxu/okhttps/HttpResult.java rename to okhttps/src/main/java/com/ejlchina/okhttps/HttpResult.java index 8294c861..fd46b590 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/HttpResult.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/HttpResult.java @@ -1,15 +1,14 @@ -package cn.zhxu.okhttps; - -import cn.zhxu.data.ListMap; -import cn.zhxu.okhttps.internal.RealHttpResult; -import okhttp3.Headers; -import okhttp3.MediaType; -import okhttp3.Response; +package com.ejlchina.okhttps; import java.io.File; import java.io.IOException; import java.util.List; -import java.util.function.Consumer; + +import com.ejlchina.okhttps.internal.RealHttpResult; + +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.Response; /** @@ -92,14 +91,11 @@ enum State { interface Body extends Toable { /** - * will be removed in next version * @return 媒体类型 */ - @Deprecated MediaType getType(); /** - * 依赖于 Content-Length 响应头 * @return 报文体字节长度 */ long getLength(); @@ -115,7 +111,7 @@ interface Body extends Toable { * @param onProcess 进度回调函数 * @return Body */ - Body setOnProcess(Consumer onProcess); + Body setOnProcess(OnCallback onProcess); /** * 设置进度回调的步进字节,默认 8K(8192) @@ -197,25 +193,15 @@ interface Body extends Toable { int getStatus(); /** - * WebSocket 返回 101 也返回 true (since v3.5.1) * @return 是否响应成功,状态码在 [200..300) 之间 */ boolean isSuccessful(); /** - * will be removed in next version * @return 响应头 - * @see #allHeaders() */ - @Deprecated Headers getHeaders(); - /** - * @return 所有响应头 - * @since v3.5.0 - */ - ListMap allHeaders(); - /** * @param name 头名称 * @return 响应头 diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/HttpTask.java b/okhttps/src/main/java/com/ejlchina/okhttps/HttpTask.java similarity index 76% rename from okhttps/src/main/java/cn/zhxu/okhttps/HttpTask.java rename to okhttps/src/main/java/com/ejlchina/okhttps/HttpTask.java index d7381c22..63957aa1 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/HttpTask.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/HttpTask.java @@ -1,10 +1,8 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; -import cn.zhxu.data.ArrayListMap; -import cn.zhxu.data.ListMap; -import cn.zhxu.okhttps.HttpResult.State; -import cn.zhxu.okhttps.internal.*; -import cn.zhxu.okhttps.internal.AbstractHttpClient.TagTask; +import com.ejlchina.okhttps.HttpResult.State; +import com.ejlchina.okhttps.internal.*; +import com.ejlchina.okhttps.internal.AbstractHttpClient.TagTask; import okhttp3.*; import okhttp3.internal.http.HttpMethod; @@ -18,10 +16,10 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; /** * Created by 周旭(Troy.Zhou) on 2020/3/11. @@ -29,9 +27,8 @@ @SuppressWarnings("unchecked") public abstract class HttpTask> implements Cancelable { + private static final String PATH_PARAM_REGEX = "[A-Za-z0-9_\\-/]*\\{[A-Za-z0-9_\\-]+\\}[A-Za-z0-9_\\-/]*"; private static final String DOT = "."; - private static final String MULTIPART = "multipart/"; - private static final String FORM = "x-www-form-urlencoded"; protected final AbstractHttpClient httpClient; protected boolean nothrow; @@ -39,17 +36,15 @@ public abstract class HttpTask> implements Cancelable { private final String urlPath; private String tag; - - private ListMap headers; - private ListMap pathParams; - private ListMap urlParams; - private ListMap bodyParams; - private ListMap files; - + private Map headers; + private Map pathParams; + private Map urlParams; + private Map bodyParams; + private Map files; private Object requestBody; - private String bodyType; // 都是小写形式 + private String bodyType; private String boundary; // MultipartBody 的 边界符 - private Consumer onProcess; + private OnCallback onProcess; private boolean processOnIO; private long stepBytes = 0; private double stepRate = -1; @@ -133,7 +128,7 @@ public boolean isTagged(String tag) { * 获取请求任务的头信息 * @return 头信息 */ - public ListMap getHeaders() { + public Map getHeaders() { return headers; } @@ -141,7 +136,7 @@ public ListMap getHeaders() { * @since 2.4.0 * @return 路径参数 */ - public ListMap getPathParas() { + public Map getPathParas() { return pathParams; } @@ -149,7 +144,7 @@ public ListMap getPathParas() { * @since 2.4.0 * @return URL参数(查询参数) */ - public ListMap getUrlParas() { + public Map getUrlParas() { return urlParams; } @@ -157,7 +152,7 @@ public ListMap getUrlParas() { * @since 2.4.0 * @return 报文体参数 */ - public ListMap getBodyParas() { + public Map getBodyParas() { return bodyParams; } @@ -165,7 +160,7 @@ public ListMap getBodyParas() { * @since 2.4.0 * @return 文件参数 */ - public ListMap getFileParas() { + public Map getFileParas() { return files; } @@ -309,7 +304,7 @@ public C bearerAuth(String token) { public C addHeader(String name, String value) { if (name != null && value != null) { if (headers == null) { - headers = new ArrayListMap<>(); + headers = new HashMap<>(); } headers.put(name, value); } @@ -324,7 +319,7 @@ public C addHeader(String name, String value) { public C addHeader(Map headers) { if (headers != null) { if (this.headers == null) { - this.headers = new ArrayListMap<>(); + this.headers = new HashMap<>(); } this.headers.putAll(headers); } @@ -357,7 +352,7 @@ public C setRange(long rangeStart, long rangeEnd) { * @param onProcess 进度回调函数 * @return HttpTask 实例 */ - public C setOnProcess(Consumer onProcess) { + public C setOnProcess(OnCallback onProcess) { this.onProcess = onProcess; processOnIO = nextOnIO; nextOnIO = false; @@ -395,7 +390,7 @@ public C stepRate(double stepRate) { public C addPathPara(String name, Object value) { if (name != null && value != null) { if (pathParams == null) { - pathParams = new ArrayListMap<>(); + pathParams = new HashMap<>(); } pathParams.put(name, value.toString()); } @@ -409,7 +404,7 @@ public C addPathPara(String name, Object value) { **/ public C addPathPara(Map params) { if (pathParams == null) { - pathParams = new ArrayListMap<>(); + pathParams = new HashMap<>(); } if (params != null) { pathParams.putAll(params); @@ -426,7 +421,7 @@ public C addPathPara(Map params) { public C addUrlPara(String name, Object value) { if (name != null && value != null) { if (urlParams == null) { - urlParams = new ArrayListMap<>(); + urlParams = new HashMap<>(); } urlParams.put(name, value.toString()); } @@ -440,7 +435,7 @@ public C addUrlPara(String name, Object value) { **/ public C addUrlPara(Map params) { if (urlParams == null) { - urlParams = new ArrayListMap<>(); + urlParams = new HashMap<>(); } if (params != null) { urlParams.putAll(params); @@ -457,35 +452,13 @@ public C addUrlPara(Map params) { public C addBodyPara(String name, Object value) { if (name != null && value != null) { if (bodyParams == null) { - bodyParams = new ArrayListMap<>(); + bodyParams = new HashMap<>(); } bodyParams.put(name, value); } return (C) this; } - /** - * Body参数:放在 Body 里的参数(该方法只适合表单提交方式) - * @param name 参数名 - * @param type 媒体类型: 如 txt、json、xml 等,参考 {@link HTTP.Builder#getMediaTypes() } - * @param value 参数值 - * @return HttpTask 实例 - * @since v4.1.0 - **/ - public C addBodyPara(String name, String type, Object value) { - if (name != null && value != null) { - if (bodyParams == null) { - bodyParams = new ArrayListMap<>(); - } - if (type == null) { - bodyParams.put(name, value); - } else { - bodyParams.put(name, new BodyPara(type, value)); - } - } - return (C) this; - } - /** * Body参数:放在Body里的参数 * @param params 参数集合 @@ -493,7 +466,7 @@ public C addBodyPara(String name, String type, Object value) { **/ public C addBodyPara(Map params) { if (bodyParams == null) { - bodyParams = new ArrayListMap<>(); + bodyParams = new HashMap<>(); } if (params != null) { bodyParams.putAll(params); @@ -505,9 +478,9 @@ public C addBodyPara(Map params) { * 设置 请求报文体 * @param body 请求报文体,可以是: *
-     *  byte[] - 字节数组(直接作为报文体) 
- * String - 字符串(比如:JSON 字符串、键值对字符串,也是直接作为报文体)
- * POJO - 普通 Java 数据对象(由 {@link MsgConvertor } 来序列化)
+ * byte[] - 字节数组(直接作为报文体)
+ * String - 字符串(比如:JSON 字符串、键值对字符串,也是直接作为报文体)
+ * POJO - 普通 Java 数据对象(由 {@link MsgConvertor } 来序列化)
* InputStream - 输入流(v3.5.0 开始支持) *
* @return HttpTask 实例 @@ -530,7 +503,7 @@ public C addFilePara(String name, String filePath) { /** * 添加文件参数(以 multipart/form-data 形式上传) * @param name 参数名 - * @param type 文件类型/扩展名: 如 txt、png、jpg、doc 等,参考 {@link HTTP.Builder#getMediaTypes() } + * @param type 文件类型/扩展名: 如 txt、png、jpg、doc 等,参考 @{ HTTP$Builder#mediaTypes } * @param filePath 文件路径 * @return HttpTask 实例 */ @@ -563,7 +536,7 @@ public C addFilePara(String name, File file) { public C addFilePara(String name, String type, File file) { if (name != null && file != null && file.exists()) { if (files == null) { - files = new ArrayListMap<>(); + files = new HashMap<>(); } files.put(name, new FilePara(type, file.getName(), file)); } @@ -581,26 +554,6 @@ public C addFilePara(String name, String type, byte[] content) { return addFilePara(name, type, name + DOT + type, content); } - /** - * 添加文件参数(以 multipart/form-data 形式上传) - * @param name 参数名 - * @param content 文件内容 - * @param fileName 文件名: 如 xxx.txt、xxx.png、xxx.doc 等 - * @return HttpTask 实例 - * @since v3.5.1 - */ - public C addFilePara(String name, byte[] content, String fileName) { - if (fileName != null) { - int dotIdx = fileName.indexOf(DOT); - if (dotIdx >= 0 && dotIdx < fileName.length() - 1) { - String type = fileName.substring(dotIdx + 1); - return addFilePara(name, type, fileName, content); - } - return addFilePara(name, null, fileName, content); - } - return (C) this; - } - /** * 添加文件参数(以 multipart/form-data 形式上传) * @param name 参数名 @@ -612,7 +565,7 @@ public C addFilePara(String name, byte[] content, String fileName) { public C addFilePara(String name, String type, String fileName, byte[] content) { if (name != null && content != null) { if (files == null) { - files = new ArrayListMap<>(); + files = new HashMap<>(); } files.put(name, new FilePara(type, fileName, content)); } @@ -631,26 +584,6 @@ public C addFilePara(String name, String type, InputStream stream) { return addFilePara(name, type, name + DOT + type, stream); } - /** - * 添加文件参数(以 multipart/form-data 形式上传) - * @param name 参数名 - * @param stream 文件输入流 - * @param fileName 文件名: 如 xxx.txt、xxx.png、xxx.doc 等 - * @return HttpTask 实例 - * @since v3.5.1 - */ - public C addFilePara(String name, InputStream stream, String fileName) { - if (fileName != null) { - int dotIdx = fileName.indexOf(DOT); - if (dotIdx >= 0 && dotIdx < fileName.length() - 1) { - String type = fileName.substring(dotIdx + 1); - return addFilePara(name, type, fileName, stream); - } - return addFilePara(name, null, fileName, stream); - } - return (C) this; - } - /** * 添加文件参数(以 multipart/form-data 形式上传) * @param name 参数名 @@ -663,7 +596,7 @@ public C addFilePara(String name, InputStream stream, String fileName) { public C addFilePara(String name, String type, String fileName, InputStream stream) { if (name != null && stream != null) { if (files == null) { - files = new ArrayListMap<>(); + files = new HashMap<>(); } files.put(name, new FilePara(type, fileName, stream)); } @@ -681,7 +614,6 @@ public String boundary() { /** * 设置 MultipartBody 的边界符 * @since v3.4.2 - * @param boundary 边界符 * @return this */ public C boundary(String boundary) { @@ -766,10 +698,12 @@ private long contentLength(RequestBody reqBody) { private void buildHeaders(Request.Builder builder) { if (headers != null) { - headers.forEach((name, value) -> { - if (value == null) return; - builder.addHeader(name, value); - }); + for (String name : headers.keySet()) { + String value = headers.get(name); + if (value != null) { + builder.addHeader(name, value); + } + } } } @@ -788,35 +722,27 @@ protected State toState(IOException e) { } private RequestBody buildRequestBody() { - if (bodyParams != null && (OkHttps.FORM_DATA.equals(bodyType) || bodyType.startsWith(MULTIPART)) + if (bodyParams != null && (OkHttps.FORM_DATA.equalsIgnoreCase(bodyType) || bodyType.startsWith("multipart")) || files != null) { MultipartBody.Builder builder = multipartBodyBuilder(); if (bodyParams != null) { - bodyParams.forEach((key, value) -> { + Platform.forEach(bodyParams, (key, value) -> { if (value == null) return; - MediaType contentType = null; - String bodyValue; - if (value instanceof BodyPara) { - BodyPara para = (BodyPara) value; - contentType = httpClient.mediaType(para.getType()); - bodyValue = para.getValue().toString(); - } else { - bodyValue = value.toString(); - } - byte[] content = bodyValue.getBytes(charset); - RequestBody body = RequestBody.create(contentType, content); + byte[] content = value.toString().getBytes(charset); + RequestBody body = RequestBody.create(null, content); builder.addPart(MultipartBody.Part.createFormData(key, null, body)); }); } if (files != null) { - files.forEach((name, file) -> { + for (String name : files.keySet()) { + FilePara file = files.get(name); MediaType type = httpClient.mediaType(file.getType()); builder.addFormDataPart( name, file.getFileName(), file.toRequestBody(type) ); - }); + } } return builder.build(); } @@ -826,9 +752,9 @@ private RequestBody buildRequestBody() { if (bodyParams == null) { return emptyRequestBody(); } - if (OkHttps.FORM.equals(bodyType) || bodyType.endsWith(FORM)) { + if (OkHttps.FORM.equalsIgnoreCase(bodyType)) { FormBody.Builder builder = new FormBody.Builder(charset); - bodyParams.forEach((key, value) -> { + Platform.forEach(bodyParams, (key, value) -> { if (value == null) return; builder.add(key, value.toString()); }); @@ -844,7 +770,7 @@ private MultipartBody.Builder multipartBodyBuilder() { } else { builder = new MultipartBody.Builder(); } - if (bodyType.startsWith(MULTIPART)) { + if (bodyType.startsWith("multipart")) { try { builder.setType(MediaType.get(bodyType)); } catch (IllegalArgumentException ignore) { } @@ -878,67 +804,72 @@ private RequestBody toRequestBody(Object bodyObj) { } private String buildUrlPath() { - if (Platform.isBlank(urlPath)) { + String url = urlPath; + if (url == null || url.trim().isEmpty()) { throw new OkHttpsException("url 不能为空!"); } - StringBuilder sb = new StringBuilder(urlPath); if (pathParams != null) { - pathParams.forEach((name, value) -> { + for (String name : pathParams.keySet()) { String target = "{" + name + "}"; - int start = sb.indexOf(target); - if (start >= 0) { - String newValue = value != null ? value.toString() : ""; - sb.replace(start, start + target.length(), newValue); + if (url.contains(target)) { + Object value = pathParams.get(name); + url = url.replace(target, value != null ? value.toString() : ""); } else { - throw new OkHttpsException("PathPara [ " + name + " ] 不存在于 url [ " + urlPath + " ]"); + throw new OkHttpsException("pathPara [ " + name + " ] 不存在于 url [ " + urlPath + " ]"); } - }); + } + } + if (url.matches(PATH_PARAM_REGEX)) { + throw new OkHttpsException("url 里有 pathPara 没有设置,你必须先调用 addPathPara 为其设置!"); } if (urlParams != null) { - if (sb.indexOf("?") >= 0) { // contains("?") - int lastIndex = sb.length() - 1; - if (sb.lastIndexOf("?") < lastIndex) { // !endsWith("?") - if (sb.lastIndexOf("=") < sb.lastIndexOf("?") + 2) { - throw new OkHttpsException("url 格式错误,'?' 后没有发现 '='"); - } - if (sb.lastIndexOf("&") < lastIndex) { // !endsWith("&") - sb.append('&'); - } + url = buildUrl(url.trim()); + } + return url; + } + + private String buildUrl(String url) { + StringBuilder sb = new StringBuilder(url); + if (url.contains("?")) { + if (!url.endsWith("?")) { + if (url.lastIndexOf("=") < url.lastIndexOf("?") + 2) { + throw new OkHttpsException("url 格式错误,'?' 后没有发现 '='"); + } + if (!url.endsWith("&")) { + sb.append('&'); } - } else { - sb.append('?'); } - urlParams.forEach((name, value) -> { - if (value == null) return; - sb.append(name).append('=').append(value).append('&'); - }); - sb.delete(sb.length() - 1, sb.length()); + } else { + sb.append('?'); + } + for (String name : urlParams.keySet()) { + sb.append(name).append('=').append(urlParams.get(name)).append('&'); } + sb.delete(sb.length() - 1, sb.length()); return sb.toString(); } /** * 参数冲突校验 - * @param bodyCantUsed 报文体是否不可用 */ protected void assertNotConflict(boolean bodyCantUsed) { if (bodyCantUsed) { if (requestBody != null) { - throw new OkHttpsException("GET | HEAD request can not call setBodyPara(..) method!"); + throw new OkHttpsException("GET | HEAD 请求 不能调用 setBodyPara 方法!"); } if (isNotEmpty(bodyParams)) { - throw new OkHttpsException("GET | HEAD request can not call addBodyPara(..) method!"); + throw new OkHttpsException("GET | HEAD 请求 不能调用 addBodyPara 方法!"); } if (isNotEmpty(files)) { - throw new OkHttpsException("GET | HEAD request can not call addFilePara(..) method!"); + throw new OkHttpsException("GET | HEAD 请求 不能调用 addFilePara 方法!"); } } if (requestBody != null) { if (isNotEmpty(bodyParams)) { - throw new OkHttpsException("can not call addBodyPara(..) and setBodyPara(..) at the same time!"); + throw new OkHttpsException("方法 addBodyPara 与 setBodyPara 不能同时使用!"); } if (isNotEmpty(files)) { - throw new OkHttpsException("can not call addFilePara(..) and setBodyPara(..) at the same time!"); + throw new OkHttpsException("方法 addFilePara 与 setBodyPara 不能同时使用!"); } } } @@ -956,7 +887,7 @@ protected boolean timeoutAwait(CountDownLatch latch) { return !latch.await(httpClient.preprocTimeoutMillis(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - throw new OkHttpsException("execute timeout: " + urlPath, e); + throw new OkHttpsException("执行超时: " + urlPath, e); } } @@ -964,7 +895,7 @@ protected HttpResult timeoutResult() { if (nothrow) { return new RealHttpResult(this, State.TIMEOUT); } - throw new OkHttpsException(State.TIMEOUT, "execute timeout: " + urlPath); + throw new OkHttpsException(State.TIMEOUT, "执行超时: " + urlPath); } public Charset charset(Response response) { diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/HttpUtils.java b/okhttps/src/main/java/com/ejlchina/okhttps/HttpUtils.java similarity index 98% rename from okhttps/src/main/java/cn/zhxu/okhttps/HttpUtils.java rename to okhttps/src/main/java/com/ejlchina/okhttps/HttpUtils.java index 00c2c4f0..a2404a3d 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/HttpUtils.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/HttpUtils.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; import okhttp3.Call; import okhttp3.Request; @@ -20,6 +20,7 @@ public class HttpUtils { * 配置HttpUtils持有的HTTP实例(不调用此方法前默认使用一个没有没有经过任何配置的HTTP懒实例) * @param http HTTP实例 */ + @Deprecated public static void of(HTTP http) { if (http != null) { HttpUtils.http = http; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/MsgConvertor.java b/okhttps/src/main/java/com/ejlchina/okhttps/MsgConvertor.java similarity index 89% rename from okhttps/src/main/java/cn/zhxu/okhttps/MsgConvertor.java rename to okhttps/src/main/java/com/ejlchina/okhttps/MsgConvertor.java index 090660f7..7f167e35 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/MsgConvertor.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/MsgConvertor.java @@ -1,9 +1,9 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; -import cn.zhxu.data.Array; -import cn.zhxu.data.DataConvertor; -import cn.zhxu.data.DataSet; -import cn.zhxu.data.Mapper; +import com.ejlchina.data.Array; +import com.ejlchina.data.DataConvertor; +import com.ejlchina.data.DataSet; +import com.ejlchina.data.Mapper; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -47,7 +47,7 @@ public FormConvertor(DataConvertor convertor, boolean urlEncoded) { @Override public String mediaType() { - return "application/x-www-form-urlencoded"; + return "application/x-www-form-urlencoded; charset={charset}"; } @Override @@ -61,7 +61,7 @@ public Array toArray(InputStream in, Charset charset) { } @Override - public byte[] serialize(Object object, Charset charset, boolean pretty) { + public byte[] serialize(Object object, Charset charset) { byte[] result = convertor.serialize(object, charset); Mapper mapper = convertor.toMapper(new ByteArrayInputStream(result), charset); StringBuilder sb = new StringBuilder(); diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/OkHttps.java b/okhttps/src/main/java/com/ejlchina/okhttps/OkHttps.java similarity index 84% rename from okhttps/src/main/java/cn/zhxu/okhttps/OkHttps.java rename to okhttps/src/main/java/com/ejlchina/okhttps/OkHttps.java index e592c917..56aca586 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/OkHttps.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/OkHttps.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; import okhttp3.Call; import okhttp3.Request; @@ -20,23 +20,19 @@ public final class OkHttps { public static final String PROTOBUF = "protobuf"; public static final String MSGPACK = "msgpack"; - private static HTTP instance; + private static HTTP http; private OkHttps() {} - public static HTTP getHttp() { - if (instance != null) { - return instance; - } - synchronized (OkHttps.class) { - if (instance == null) { - HTTP.Builder builder = HTTP.builder(); - ConvertProvider.inject(builder); - Config.config(builder); - instance = builder.build(); - } - return instance; + public static synchronized HTTP getHttp() { + if (http != null) { + return http; } + HTTP.Builder builder = HTTP.builder(); + ConvertProvider.inject(builder); + Config.config(builder); + http = builder.build(); + return http; } /** diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/OkHttpsException.java b/okhttps/src/main/java/com/ejlchina/okhttps/OkHttpsException.java similarity index 96% rename from okhttps/src/main/java/cn/zhxu/okhttps/OkHttpsException.java rename to okhttps/src/main/java/com/ejlchina/okhttps/OkHttpsException.java index 67993955..3817aa51 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/OkHttpsException.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/OkHttpsException.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; /** * Created by 周旭(Troy.Zhou) on 2016/8/30. diff --git a/okhttps/src/main/java/com/ejlchina/okhttps/OnCallback.java b/okhttps/src/main/java/com/ejlchina/okhttps/OnCallback.java new file mode 100644 index 00000000..bfeeaa3e --- /dev/null +++ b/okhttps/src/main/java/com/ejlchina/okhttps/OnCallback.java @@ -0,0 +1,11 @@ +package com.ejlchina.okhttps; + +/** + * 数据回调接口 + * Created by 15735 on 2017/1/3. + */ +public interface OnCallback { + + void on(T data); + +} diff --git a/okhttps/src/main/java/com/ejlchina/okhttps/PingSupplier.java b/okhttps/src/main/java/com/ejlchina/okhttps/PingSupplier.java new file mode 100644 index 00000000..88ec9c1b --- /dev/null +++ b/okhttps/src/main/java/com/ejlchina/okhttps/PingSupplier.java @@ -0,0 +1,15 @@ +package com.ejlchina.okhttps; + +import okio.ByteString; + +/** + * 心跳数据提供者 + */ +public interface PingSupplier { + + /** + * @return 心跳数据 + */ + ByteString getPing(); + +} diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/Platform.java b/okhttps/src/main/java/com/ejlchina/okhttps/Platform.java similarity index 75% rename from okhttps/src/main/java/cn/zhxu/okhttps/Platform.java rename to okhttps/src/main/java/com/ejlchina/okhttps/Platform.java index 1766bb0e..82293ed2 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/Platform.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/Platform.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -90,44 +90,4 @@ public static void forEach(Map map, BiConsumer task, AHttpTask.OkHttpCall call, Consumer onResponse, HttpResult result, boolean onIo) { + public void executeOnResponse(HttpTask task, AHttpTask.OkHttpCall call, OnCallback onResponse, HttpResult result, boolean onIo) { Runnable runnable = () -> { - if (!call.isCanceled()) onResponse.accept(result); + if (!call.isCanceled()) onResponse.on(result); }; if (responseListener != null) { if (responseListener.listen(task, result) && onResponse != null) { @@ -79,10 +78,10 @@ public void executeOnResponse(HttpTask task, AHttpTask.OkHttpCall call, Consu } } - public boolean executeOnException(HttpTask task, AHttpTask.OkHttpCall call, Consumer onException, IOException error, boolean onIo) { + public boolean executeOnException(HttpTask task, AHttpTask.OkHttpCall call, OnCallback onException, IOException error, boolean onIo) { Runnable runnable = () -> { if (!call.isCanceled()) { - onException.accept(error); + onException.on(error); } call.finish(); }; @@ -101,13 +100,13 @@ public boolean executeOnException(HttpTask task, AHttpTask.OkHttpCall call, C return true; } - public void executeOnComplete(HttpTask task, Consumer onComplete, State state, boolean onIo) { + public void executeOnComplete(HttpTask task, OnCallback onComplete, State state, boolean onIo) { if (completeListener != null) { if (completeListener.listen(task, state) && onComplete != null) { - execute(() -> onComplete.accept(state), onIo); + execute(() -> onComplete.on(state), onIo); } } else if (onComplete != null) { - execute(() -> onComplete.accept(state), onIo); + execute(() -> onComplete.on(state), onIo); } } diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/TaskListener.java b/okhttps/src/main/java/com/ejlchina/okhttps/TaskListener.java similarity index 91% rename from okhttps/src/main/java/cn/zhxu/okhttps/TaskListener.java rename to okhttps/src/main/java/com/ejlchina/okhttps/TaskListener.java index 96e11a84..54f734d1 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/TaskListener.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/TaskListener.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; /** * 任务监听接口 diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/Toable.java b/okhttps/src/main/java/com/ejlchina/okhttps/Toable.java similarity index 89% rename from okhttps/src/main/java/cn/zhxu/okhttps/Toable.java rename to okhttps/src/main/java/com/ejlchina/okhttps/Toable.java index 4b5f562d..06c62016 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/Toable.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/Toable.java @@ -1,8 +1,8 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; -import cn.zhxu.data.Array; -import cn.zhxu.data.Mapper; -import cn.zhxu.data.TypeRef; +import com.ejlchina.data.Array; +import com.ejlchina.data.Mapper; +import com.ejlchina.data.TypeRef; import okio.ByteString; import java.io.InputStream; @@ -23,10 +23,8 @@ public interface Toable { byte[] toBytes(); /** - * will be removed in next version * @return ByteString */ - @Deprecated ByteString toByteString(); /** diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/WHttpTask.java b/okhttps/src/main/java/com/ejlchina/okhttps/WHttpTask.java similarity index 88% rename from okhttps/src/main/java/cn/zhxu/okhttps/WHttpTask.java rename to okhttps/src/main/java/com/ejlchina/okhttps/WHttpTask.java index 3c24331a..9e4a63bc 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/WHttpTask.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/WHttpTask.java @@ -1,11 +1,11 @@ -package cn.zhxu.okhttps; - -import cn.zhxu.okhttps.WebSocket.Close; -import cn.zhxu.okhttps.WebSocket.Listener; -import cn.zhxu.okhttps.WebSocket.Message; -import cn.zhxu.okhttps.internal.AbstractHttpClient; -import cn.zhxu.okhttps.internal.RealHttpResult; -import cn.zhxu.okhttps.internal.WebSocketMsg; +package com.ejlchina.okhttps; + +import com.ejlchina.okhttps.WebSocket.Close; +import com.ejlchina.okhttps.WebSocket.Listener; +import com.ejlchina.okhttps.WebSocket.Message; +import com.ejlchina.okhttps.internal.AbstractHttpClient; +import com.ejlchina.okhttps.internal.RealHttpResult; +import com.ejlchina.okhttps.internal.WebSocketMsg; import okhttp3.Request; import okhttp3.Response; import okhttp3.WebSocketListener; @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; public class WHttpTask extends HttpTask { @@ -41,7 +40,7 @@ public class WHttpTask extends HttpTask { private long lastPongSecs = 0; // 心跳数据提供者 - private Supplier pingSupplier; + private PingSupplier pingSupplier; private WebSocketImpl webSocket; @@ -72,14 +71,14 @@ public boolean isWebsocket() { * * 由于 OkHttp 底层并未暴露 websocket 协议里 opcode 的接口,所以该心跳的 opcode 始终是 2,并不是 websocket 协议里定义的 9 * 所以如果服务器要求客户端心跳的 opcode 必须是 9 的话,请使用 OkHttp 的原生心跳: - * https://ok.zhxu.cn/v3/websocket.html#%E5%85%A8%E5%B1%80%E5%BF%83%E8%B7%B3%E9%85%8D%E7%BD%AE + * [http://okhttps.ejlchina.com/v2/websocket.html#%E5%85%A8%E5%B1%80%E5%BF%83%E8%B7%B3%E9%85%8D%E7%BD%AE] * - * 另若需要 可使用 {@link #pingSupplier(Supplier)} 方法指定心跳发送的具体内容 + * 另若需要 可使用 {@link #pingSupplier(PingSupplier)} 方法指定心跳发送的具体内容 * * @since v2.3.0 * @param pingSeconds 客户端心跳间隔秒数(0 表示不需要心跳) * @param pongSeconds 服务器心跳间隔秒数(0 表示不需要心跳) - * @return WHttpTask + * @return WebSocketTask */ public WHttpTask heatbeat(int pingSeconds, int pongSeconds) { if (pingSeconds < 0 || pongSeconds < 0) { @@ -94,7 +93,7 @@ public WHttpTask heatbeat(int pingSeconds, int pongSeconds) { * 用于兼容某些强制客户端必须以固定的时间间隔发送心跳的服务器 * @since v2.5.0 * @param flexiblePing Ping 的间隔是否灵活可变(默认为 true, 为 false 时客户端 Ping 的间隔固定,普通的消息不做为 Ping) - * @return WHttpTask + * @return WebSocketTask */ public WHttpTask flexiblePing(boolean flexiblePing) { this.flexiblePing = flexiblePing; @@ -103,14 +102,14 @@ public WHttpTask flexiblePing(boolean flexiblePing) { /** * @param pingSupplier 心跳数据提供者 - * @return WHttpTask + * @return WebSocketTask */ - public WHttpTask pingSupplier(Supplier pingSupplier) { + public WHttpTask pingSupplier(PingSupplier pingSupplier) { this.pingSupplier = pingSupplier; return this; } - public Supplier pingSupplier() { + public PingSupplier pingSupplier() { return pingSupplier; } @@ -202,6 +201,7 @@ public void onMessage(okhttp3.WebSocket webSocket, String text) { } if (pongSeconds > 0) { lastPongSecs = nowSeconds(); + Platform.logInfo("PONG <<< " + text); } } @@ -214,29 +214,30 @@ public void onMessage(okhttp3.WebSocket webSocket, ByteString bytes) { } if (pongSeconds > 0) { lastPongSecs = nowSeconds(); + Platform.logInfo("PONG <<< " + bytes.utf8()); } } @Override - public void onClosing(okhttp3.WebSocket ws, int code, String reason) { + public void onClosing(okhttp3.WebSocket webSocket, int code, String reason) { this.webSocket.setStatus(WebSocket.STATUS_DISCONNECTED); Listener listener = onClosing; if (listener != null) { execute(() -> listener.on(this.webSocket, new Close(code, reason)), closingOnIO); } httpClient.executor().requireScheduler().schedule(() -> { - doOnClose(HttpResult.State.RESPONSED, code, reason); + doOnClose(webSocket, HttpResult.State.RESPONSED, code, reason); }, maxClosingSecs, TimeUnit.SECONDS); } @Override - public void onClosed(okhttp3.WebSocket ws, int code, String reason) { - doOnClose(HttpResult.State.RESPONSED, code, reason); + public void onClosed(okhttp3.WebSocket webSocket, int code, String reason) { + doOnClose(webSocket, HttpResult.State.RESPONSED, code, reason); } - private void doOnClose(HttpResult.State state, int code, String reason) { + private void doOnClose(okhttp3.WebSocket webSocket, HttpResult.State state, int code, String reason) { synchronized(WHttpTask.this) { - if (WHttpTask.this.webSocket == null || this.webSocket != WHttpTask.this.webSocket) { + if (WHttpTask.this.webSocket == null || this.webSocket.webSocket != webSocket) { return; // 回调已经执行过 } WHttpTask.this.webSocket = null; @@ -275,9 +276,9 @@ private Close updateStatus(HttpResult.State state, int code, String reason) { } @Override - public void onFailure(okhttp3.WebSocket ws, Throwable t, Response response) { + public void onFailure(okhttp3.WebSocket webSocket, Throwable t, Response response) { IOException e = t instanceof IOException ? (IOException) t : new IOException(t.getMessage(), t); - doOnClose(toState(e), 0, t.getMessage()); + doOnClose(webSocket, toState(e), 0, t.getMessage()); TaskListener listener = httpClient.executor().getExceptionListener(); Listener exceptionListener = onException; if (listener != null) { @@ -315,7 +316,8 @@ private void schedulePing() { } WebSocket ws = webSocket; if (nowSeconds() - lastPingSecs >= pingSeconds && ws != null) { - ws.send(pingSupplier != null ? pingSupplier.get() : ByteString.EMPTY); + ByteString ping = pingSupplier != null ? pingSupplier.getPing() : ByteString.EMPTY; + ws.send(ping); lastPingSecs = nowSeconds(); } schedulePing(); @@ -351,7 +353,7 @@ private void schedulePong() { * @return 当前时间戳(秒) */ private long nowSeconds() { - return System.currentTimeMillis() / 1000; + return System.nanoTime() / 1000_000_000; } class WebSocketImpl implements WebSocket { @@ -469,7 +471,7 @@ boolean send(okhttp3.WebSocket webSocket, Object msg) { /** * 连接打开监听 * @param onOpen 监听器 - * @return WHttpTask + * @return WebSocketTask */ public WHttpTask setOnOpen(Listener onOpen) { this.onOpen = onOpen; @@ -481,7 +483,7 @@ public WHttpTask setOnOpen(Listener onOpen) { /** * 连接异常监听 * @param onException 监听器 - * @return WHttpTask + * @return WebSocketTask */ public WHttpTask setOnException(Listener onException) { this.onException = onException; @@ -493,7 +495,7 @@ public WHttpTask setOnException(Listener onException) { /** * 消息监听 * @param onMessage 监听器 - * @return WHttpTask + * @return WebSocketTask */ public WHttpTask setOnMessage(Listener onMessage) { this.onMessage = onMessage; @@ -505,7 +507,7 @@ public WHttpTask setOnMessage(Listener onMessage) { /** * 正在关闭监听 * @param onClosing 监听器 - * @return WHttpTask + * @return WebSocketTask */ public WHttpTask setOnClosing(Listener onClosing) { this.onClosing = onClosing; @@ -517,7 +519,7 @@ public WHttpTask setOnClosing(Listener onClosing) { /** * 已关闭监听(当连接被取消或发生异常时,也会走该回调) * @param onClosed 监听器 - * @return WHttpTask + * @return WebSocketTask */ public WHttpTask setOnClosed(Listener onClosed) { this.onClosed = onClosed; @@ -529,7 +531,6 @@ public WHttpTask setOnClosed(Listener onClosed) { /** * 设置在 OnClosing 回调执行完毕后,OnClosed 回调执行的最晚延迟时间 * @param maxClosingSecs 最大 Closing 时长(单位:秒,默认:10秒) - * @return WHttpTask */ public WHttpTask setMaxClosingSecs(int maxClosingSecs) { this.maxClosingSecs = maxClosingSecs; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/WebSocket.java b/okhttps/src/main/java/com/ejlchina/okhttps/WebSocket.java similarity index 99% rename from okhttps/src/main/java/cn/zhxu/okhttps/WebSocket.java rename to okhttps/src/main/java/com/ejlchina/okhttps/WebSocket.java index 4fdc577e..0313aed6 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/WebSocket.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/WebSocket.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.okhttps; public interface WebSocket extends Cancelable { diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/AbstractBody.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/AbstractBody.java similarity index 90% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/AbstractBody.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/AbstractBody.java index 0d28e917..7b493c36 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/AbstractBody.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/AbstractBody.java @@ -1,16 +1,15 @@ -package cn.zhxu.okhttps.internal; - -import cn.zhxu.data.Array; -import cn.zhxu.data.Mapper; -import cn.zhxu.data.TypeRef; -import cn.zhxu.okhttps.TaskExecutor; -import cn.zhxu.okhttps.Toable; +package com.ejlchina.okhttps.internal; import java.io.InputStream; import java.lang.reflect.Type; import java.nio.charset.Charset; import java.util.List; +import com.ejlchina.data.Array; +import com.ejlchina.data.Mapper; +import com.ejlchina.data.TypeRef; +import com.ejlchina.okhttps.*; + public abstract class AbstractBody implements Toable { protected TaskExecutor taskExecutor; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/AbstractHttpClient.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/AbstractHttpClient.java similarity index 94% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/AbstractHttpClient.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/AbstractHttpClient.java index 01f80471..53c12bc3 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/AbstractHttpClient.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/AbstractHttpClient.java @@ -1,13 +1,10 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; -import cn.zhxu.okhttps.*; -import okhttp3.MediaType; +import com.ejlchina.okhttps.*; +import okhttp3.*; import java.nio.charset.Charset; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.Executor; public abstract class AbstractHttpClient implements HTTP { @@ -141,12 +138,12 @@ public class TagTask { this.tag = tag; this.canceler = canceler; this.task = task; - this.createAt = System.currentTimeMillis(); + this.createAt = System.nanoTime(); } boolean isExpired() { // 生存时间大于10倍的总超时限值 - return System.currentTimeMillis() - createAt > preprocTimeoutMillis(); + return System.nanoTime() - createAt > 1_000_000L * preprocTimeoutMillis(); } public void setTag(String tag) { @@ -161,15 +158,12 @@ public MediaType mediaType(String type) { return MediaType.parse(mediaType); } if (type != null) { - if (type.indexOf('/') < 0) { - type = "application/" + type; - } MediaType mType = MediaType.parse(type); if (mType != null) { return mType; } } - return MediaType.parse("application/unknown"); + return MediaType.parse("application/octet-stream"); } @Override diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/CopyInterceptor.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/CopyInterceptor.java similarity index 97% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/CopyInterceptor.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/CopyInterceptor.java index deb3483e..3e488484 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/CopyInterceptor.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/CopyInterceptor.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; import okhttp3.Interceptor; import okhttp3.Request; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/FixedRequestBody.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/FixedRequestBody.java similarity index 96% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/FixedRequestBody.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/FixedRequestBody.java index 89eb7d34..1e34411e 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/FixedRequestBody.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/FixedRequestBody.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; import okhttp3.MediaType; import okhttp3.RequestBody; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/ProcessInputStream.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/ProcessInputStream.java similarity index 82% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/ProcessInputStream.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/ProcessInputStream.java index ec828e5b..b9b8272f 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/ProcessInputStream.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/ProcessInputStream.java @@ -1,24 +1,24 @@ -package cn.zhxu.okhttps.internal; - -import cn.zhxu.okhttps.Process; +package com.ejlchina.okhttps.internal; import java.io.IOException; import java.io.InputStream; import java.util.concurrent.Executor; -import java.util.function.Consumer; + +import com.ejlchina.okhttps.OnCallback; +import com.ejlchina.okhttps.Process; public class ProcessInputStream extends InputStream { private final InputStream input; - private final Consumer onProcess; + private final OnCallback onProcess; private final Executor callbackExecutor; private final long stepBytes; private final RealProcess process; private boolean doneCalled = false; private long step; - public ProcessInputStream(InputStream input, Consumer onProcess, long totalBytes, long stepBytes, - long doneBytes, Executor callbackExecutor) { + public ProcessInputStream(InputStream input, OnCallback onProcess, long totalBytes, long stepBytes, + long doneBytes, Executor callbackExecutor) { this.input = input; this.onProcess = onProcess; this.stepBytes = stepBytes; @@ -71,7 +71,7 @@ private void updateProcess(long count) { step = (process.getDoneBytes() - 1) / stepBytes + 1; // 因为 process 一直被更新,所有此处应克隆一个新的对象用于回调 Process p = process.newProcess(); - callbackExecutor.execute(() -> onProcess.accept(p)); + callbackExecutor.execute(() -> onProcess.on(p)); } @Override diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/ProcessRequestBody.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/ProcessRequestBody.java similarity index 81% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/ProcessRequestBody.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/ProcessRequestBody.java index c7533d4b..8c8a0d59 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/ProcessRequestBody.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/ProcessRequestBody.java @@ -1,22 +1,22 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; -import cn.zhxu.okhttps.Process; +import com.ejlchina.okhttps.OnCallback; +import com.ejlchina.okhttps.Process; import okhttp3.RequestBody; import okio.*; import java.io.IOException; import java.util.concurrent.Executor; -import java.util.function.Consumer; public class ProcessRequestBody extends FixedRequestBody { - private final Consumer onProcess; + private final OnCallback onProcess; private final Executor callbackExecutor; private final RealProcess process; private final long stepBytes; - public ProcessRequestBody(RequestBody requestBody, Consumer onProcess, Executor callbackExecutor, - long contentLength, long stepBytes) { + public ProcessRequestBody(RequestBody requestBody, OnCallback onProcess, Executor callbackExecutor, + long contentLength, long stepBytes) { super(requestBody); this.onProcess = onProcess; this.callbackExecutor = callbackExecutor; @@ -59,7 +59,7 @@ private void updateProcess(long count) { step = (process.getDoneBytes() - 1) / stepBytes + 1; // 因为 process 一直被更新,所有此处应克隆一个新的对象用于回调 Process p = process.newProcess(); - callbackExecutor.execute(() -> onProcess.accept(p)); + callbackExecutor.execute(() -> onProcess.on(p)); } } diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/RealHttpResult.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/RealHttpResult.java similarity index 82% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/RealHttpResult.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/RealHttpResult.java index a0f86671..33196e23 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/RealHttpResult.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/RealHttpResult.java @@ -1,10 +1,8 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; -import cn.zhxu.data.ArrayListMap; -import cn.zhxu.data.ListMap; -import cn.zhxu.okhttps.HttpTask; -import cn.zhxu.okhttps.TaskExecutor; -import cn.zhxu.okhttps.HttpResult; +import com.ejlchina.okhttps.HttpResult; +import com.ejlchina.okhttps.HttpTask; +import com.ejlchina.okhttps.TaskExecutor; import okhttp3.Headers; import okhttp3.Response; @@ -68,10 +66,6 @@ public int getStatus() { @Override public boolean isSuccessful() { if (response != null) { - if (httpTask != null && httpTask.isWebsocket() - && response.code() == 101) { - return true; - } return response.isSuccessful(); } return false; @@ -84,19 +78,7 @@ public Headers getHeaders() { } return null; } - - @Override - public ListMap allHeaders() { - ListMap map = new ArrayListMap<>(); - if (response != null) { - Headers hs = response.headers(); - for (int i = 0, size = hs.size(); i < size; i++) { - map.put(hs.name(i), hs.value(i)); - } - } - return map; - } - + @Override public List getHeaders(String name) { if (response != null) { diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/RealProcess.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/RealProcess.java similarity index 71% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/RealProcess.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/RealProcess.java index c9a925ed..f04605b3 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/RealProcess.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/RealProcess.java @@ -1,10 +1,10 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; -import cn.zhxu.okhttps.Process; +import com.ejlchina.okhttps.Process; public class RealProcess implements Process { - // 总字节数(流式上传时该字段为 -1) + // 总字节数 private final long totalBytes; // 已经完成字节数 private long doneBytes; @@ -20,12 +20,6 @@ public Process newProcess() { @Override public double getRate() { - if (totalBytes == 0) { - return 1; - } - if (totalBytes < 0) { - return -1; - } return (double) doneBytes / totalBytes; } @@ -41,7 +35,7 @@ public long getDoneBytes() { @Override public boolean isDone() { - return doneBytes >= totalBytes && totalBytes >= 0; + return doneBytes >= totalBytes; } public void addDoneBytes(long delt) { @@ -49,12 +43,11 @@ public void addDoneBytes(long delt) { } public boolean isUndoneAndUnreached(long bytes) { - return doneBytes < bytes && (totalBytes < 0 || doneBytes < totalBytes); + return doneBytes < bytes && doneBytes < totalBytes; } @Override public String toString() { return "Process[" + doneBytes + " / " + totalBytes + " | " + getRate() + ']'; } - } diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/ResultBody.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/ResultBody.java similarity index 92% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/ResultBody.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/ResultBody.java index 65c09095..8814aa2b 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/ResultBody.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/ResultBody.java @@ -1,23 +1,26 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; -import cn.zhxu.okhttps.Process; -import cn.zhxu.okhttps.*; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; + +import com.ejlchina.okhttps.*; +import com.ejlchina.okhttps.HttpResult.Body; + +import com.ejlchina.okhttps.Process; import okhttp3.MediaType; import okhttp3.Response; import okhttp3.ResponseBody; import okio.Buffer; import okio.ByteString; -import java.io.*; -import java.net.HttpURLConnection; -import java.util.function.Consumer; - -public class ResultBody extends AbstractBody implements HttpResult.Body { +public class ResultBody extends AbstractBody implements Body { private final HttpResult result; private final Response response; private boolean onIO = false; - private Consumer onProcess; + private OnCallback onProcess; private long stepBytes = 0; private double stepRate = -1; private boolean rangeIgnored = false; @@ -50,13 +53,13 @@ public long getLength() { } @Override - public HttpResult.Body nextOnIO() { + public Body nextOnIO() { onIO = true; return this; } @Override - public HttpResult.Body setOnProcess(Consumer onProcess) { + public Body setOnProcess(OnCallback onProcess) { if (taskExecutor == null) { response.close(); throw new IllegalStateException("没有 taskExecutor,不可设置下载进度回调!"); @@ -70,19 +73,19 @@ public HttpResult.Body setOnProcess(Consumer onProcess) { } @Override - public HttpResult.Body stepBytes(long stepBytes) { + public Body stepBytes(long stepBytes) { this.stepBytes = stepBytes; return this; } @Override - public HttpResult.Body stepRate(double stepRate) { + public Body stepRate(double stepRate) { this.stepRate = stepRate; return this; } @Override - public HttpResult.Body setRangeIgnored() { + public Body setRangeIgnored() { this.rangeIgnored =true; return this; } @@ -231,7 +234,7 @@ public Download toFolder(File dir) { } @Override - public HttpResult.Body cache() { + public Body cache() { if (onProcess != null) { response.close(); throw new IllegalStateException("设置了下载进度回调,不可再开启缓存!"); @@ -241,7 +244,7 @@ public HttpResult.Body cache() { } @Override - public HttpResult.Body close() { + public Body close() { response.close(); data = null; return this; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/SerialPreprocessor.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/SerialPreprocessor.java similarity index 93% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/SerialPreprocessor.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/SerialPreprocessor.java index 388a4cb8..f46bac27 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/SerialPreprocessor.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/SerialPreprocessor.java @@ -1,6 +1,6 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; -import cn.zhxu.okhttps.Preprocessor; +import com.ejlchina.okhttps.Preprocessor; import java.util.LinkedList; import java.util.Queue; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/StreamRequestBody.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/StreamRequestBody.java similarity index 82% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/StreamRequestBody.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/StreamRequestBody.java index 2e17e12b..9a0f3fd5 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/StreamRequestBody.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/StreamRequestBody.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; import okhttp3.MediaType; import okhttp3.RequestBody; @@ -30,11 +30,7 @@ public MediaType contentType() { @Override public void writeTo(BufferedSink sink) throws IOException { - try { - sink.writeAll(Okio.source(inputStream)); - } finally { - inputStream.close(); - } + sink.writeAll(Okio.source(inputStream)); } @Override diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/internal/WebSocketMsg.java b/okhttps/src/main/java/com/ejlchina/okhttps/internal/WebSocketMsg.java similarity index 89% rename from okhttps/src/main/java/cn/zhxu/okhttps/internal/WebSocketMsg.java rename to okhttps/src/main/java/com/ejlchina/okhttps/internal/WebSocketMsg.java index 5b7fc09c..73a669f7 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/internal/WebSocketMsg.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/internal/WebSocketMsg.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps.internal; +package com.ejlchina.okhttps.internal; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -8,13 +8,13 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import cn.zhxu.okhttps.TaskExecutor; -import cn.zhxu.okhttps.WebSocket; +import com.ejlchina.okhttps.TaskExecutor; +import com.ejlchina.okhttps.WebSocket.Message; import okio.ByteString; -public class WebSocketMsg extends AbstractBody implements WebSocket.Message { +public class WebSocketMsg extends AbstractBody implements Message { private String text; private ByteString bytes; diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/okhttp/OkHttpBuilderImpl.java b/okhttps/src/main/java/com/ejlchina/okhttps/okhttp/OkHttpBuilderImpl.java similarity index 91% rename from okhttps/src/main/java/cn/zhxu/okhttps/okhttp/OkHttpBuilderImpl.java rename to okhttps/src/main/java/com/ejlchina/okhttps/okhttp/OkHttpBuilderImpl.java index 4d691ec7..245012e5 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/okhttp/OkHttpBuilderImpl.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/okhttp/OkHttpBuilderImpl.java @@ -1,8 +1,7 @@ -package cn.zhxu.okhttps.okhttp; +package com.ejlchina.okhttps.okhttp; -import cn.zhxu.okhttps.*; -import cn.zhxu.okhttps.internal.CopyInterceptor; -import cn.zhxu.okhttps.internal.SerialPreprocessor; +import com.ejlchina.okhttps.*; +import com.ejlchina.okhttps.internal.*; import okhttp3.Interceptor; import okhttp3.OkHttpClient; @@ -51,26 +50,24 @@ public class OkHttpBuilderImpl implements HTTP.Builder { public OkHttpBuilderImpl() { mediaTypes = new HashMap<>(); + mediaTypes.put("*", "application/octet-stream"); mediaTypes.put("png", "image/png"); mediaTypes.put("jpg", "image/jpeg"); mediaTypes.put("jpeg", "image/jpeg"); mediaTypes.put("wav", "audio/wav"); mediaTypes.put("mp3", "audio/mp3"); - mediaTypes.put("mp4", "video/mp4"); + mediaTypes.put("mp4", "video/mpeg4"); mediaTypes.put("txt", "text/plain"); mediaTypes.put("xls", "application/x-xls"); - mediaTypes.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); mediaTypes.put("xml", "text/xml"); mediaTypes.put("apk", "application/vnd.android.package-archive"); mediaTypes.put("doc", "application/msword"); - mediaTypes.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + mediaTypes.put("pdf", "application/pdf"); mediaTypes.put("html", "text/html"); - mediaTypes.put("rar", "application/x-rar"); - mediaTypes.put("jar", "application/x-java-archive"); contentTypes = new ArrayList<>(); - contentTypes.add("application/x-www-form-urlencoded"); - contentTypes.add("application/json"); - contentTypes.add("application/xml"); + contentTypes.add("application/x-www-form-urlencoded; charset={charset}"); + contentTypes.add("application/json; charset={charset}"); + contentTypes.add("application/xml; charset={charset}"); contentTypes.add("application/protobuf"); contentTypes.add("application/msgpack"); preprocessors = new ArrayList<>(); @@ -132,11 +129,6 @@ public HTTP.Builder mediaTypes(String key, String value) { return this; } - public HTTP.Builder clearContentTypes() { - contentTypes.clear(); - return this; - } - public HTTP.Builder contentTypes(List contentTypes) { if (contentTypes != null) { this.contentTypes.addAll(contentTypes); diff --git a/okhttps/src/main/java/cn/zhxu/okhttps/okhttp/OkHttpClientWrapper.java b/okhttps/src/main/java/com/ejlchina/okhttps/okhttp/OkHttpClientWrapper.java similarity index 84% rename from okhttps/src/main/java/cn/zhxu/okhttps/okhttp/OkHttpClientWrapper.java rename to okhttps/src/main/java/com/ejlchina/okhttps/okhttp/OkHttpClientWrapper.java index 14489c93..f71424de 100644 --- a/okhttps/src/main/java/cn/zhxu/okhttps/okhttp/OkHttpClientWrapper.java +++ b/okhttps/src/main/java/com/ejlchina/okhttps/okhttp/OkHttpClientWrapper.java @@ -1,7 +1,6 @@ -package cn.zhxu.okhttps.okhttp; +package com.ejlchina.okhttps.okhttp; -import cn.zhxu.okhttps.HTTP; -import cn.zhxu.okhttps.internal.AbstractHttpClient; +import com.ejlchina.okhttps.internal.AbstractHttpClient; import okhttp3.*; import java.util.concurrent.Executor; @@ -18,7 +17,7 @@ public OkHttpClientWrapper(OkHttpBuilderImpl builder) { } @Override - public Executor ioExecutor(HTTP.Builder builder) { + public Executor ioExecutor(Builder builder) { OkHttpBuilderImpl builderImpl = (OkHttpBuilderImpl) builder; return builderImpl.okClient().dispatcher().executorService(); } @@ -48,7 +47,7 @@ public int totalTimeoutMillis() { } @Override - public HTTP.Builder newBuilder() { + public Builder newBuilder() { return new OkHttpBuilderImpl(this); } diff --git a/okhttps/src/main/java/module-info.java b/okhttps/src/main/java/module-info.java new file mode 100644 index 00000000..aed05901 --- /dev/null +++ b/okhttps/src/main/java/module-info.java @@ -0,0 +1,14 @@ +module okhttps { + + requires okhttp3; + requires data.core; + requires okio; + + exports com.ejlchina.okhttps; + exports com.ejlchina.okhttps.internal; + exports com.ejlchina.okhttps.okhttp; + + uses com.ejlchina.okhttps.ConvertProvider; + uses com.ejlchina.okhttps.Config; + +} \ No newline at end of file diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/ListMapTests.java b/okhttps/src/test/java/cn/zhxu/okhttps/ListMapTests.java deleted file mode 100644 index f880ded6..00000000 --- a/okhttps/src/test/java/cn/zhxu/okhttps/ListMapTests.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.zhxu.okhttps; - -import cn.zhxu.data.ArrayListMap; -import cn.zhxu.data.LinkedListMap; -import cn.zhxu.data.ListMap; -import org.junit.Test; - -public class ListMapTests { - - @Test - public void map() { - long t0 = System.currentTimeMillis(); - for (int i = 0; i < 10000; i++) { - ListMap map = new ArrayListMap<>(); - map.put("name", "jack"); - map.put("school", "High School"); - map.put("age", 20); - map.put("sex", "Male"); - map.put("height", 170); - map.put("type", 2); - map.put("timestamp", "1234567890"); - map.put("name", "jack"); - map.put("school", "High School"); - map.put("age", 20); - map.put("sex", "Male"); - map.put("height", 170); - map.put("type", 2); - map.put("timestamp", "1234567890"); - map.forEach((key, value) -> { }); - } - long t1 = System.currentTimeMillis(); - for (int i = 0; i < 10000; i++) { - ListMap map = new LinkedListMap<>(); - map.put("name", "jack"); - map.put("school", "High School"); - map.put("age", 20); - map.put("sex", "Male"); - map.put("height", 170); - map.put("type", 2); - map.put("timestamp", "1234567890"); - map.put("name", "jack"); - map.put("school", "High School"); - map.put("age", 20); - map.put("sex", "Male"); - map.put("height", 170); - map.put("type", 2); - map.put("timestamp", "1234567890"); - map.forEach((key, value) -> { }); - } - long t2 = System.currentTimeMillis(); - System.out.println(t1 - t0); - System.out.println(t2 - t1); - } - -} diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/BaseTest.java b/okhttps/src/test/java/com/ejlchina/test/BaseTest.java similarity index 94% rename from okhttps/src/test/java/cn/zhxu/okhttps/BaseTest.java rename to okhttps/src/test/java/com/ejlchina/test/BaseTest.java index 72da672c..54a8b826 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/BaseTest.java +++ b/okhttps/src/test/java/com/ejlchina/test/BaseTest.java @@ -1,6 +1,6 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; -import cn.zhxu.okhttps.HTTP; +import com.ejlchina.okhttps.HTTP; import okhttp3.mockwebserver.MockWebServer; import java.text.SimpleDateFormat; diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/BodyParaTests.java b/okhttps/src/test/java/com/ejlchina/test/BodyParaTests.java similarity index 97% rename from okhttps/src/test/java/cn/zhxu/okhttps/BodyParaTests.java rename to okhttps/src/test/java/com/ejlchina/test/BodyParaTests.java index 5ec732df..1a43b6f1 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/BodyParaTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/BodyParaTests.java @@ -1,4 +1,4 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.RecordedRequest; @@ -7,6 +7,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.net.URLEncoder; public class BodyParaTests extends BaseTest { diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/CacheTests.java b/okhttps/src/test/java/com/ejlchina/test/CacheTests.java similarity index 90% rename from okhttps/src/test/java/cn/zhxu/okhttps/CacheTests.java rename to okhttps/src/test/java/com/ejlchina/test/CacheTests.java index 307119ca..53f1e09a 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/CacheTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/CacheTests.java @@ -1,5 +1,6 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.HttpResult; import okhttp3.mockwebserver.MockResponse; import org.junit.Assert; import org.junit.Test; diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/CancelTests.java b/okhttps/src/test/java/com/ejlchina/test/CancelTests.java similarity index 93% rename from okhttps/src/test/java/cn/zhxu/okhttps/CancelTests.java rename to okhttps/src/test/java/com/ejlchina/test/CancelTests.java index fe6b602a..085a01f4 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/CancelTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/CancelTests.java @@ -1,7 +1,8 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; -import cn.zhxu.okhttps.HttpResult.State; -import cn.zhxu.okhttps.internal.AbstractHttpClient; +import com.ejlchina.okhttps.HttpResult; +import com.ejlchina.okhttps.HttpResult.State; +import com.ejlchina.okhttps.internal.AbstractHttpClient; import org.junit.Test; import java.io.IOException; diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/DownloadTests.java b/okhttps/src/test/java/com/ejlchina/test/DownloadTests.java similarity index 97% rename from okhttps/src/test/java/cn/zhxu/okhttps/DownloadTests.java rename to okhttps/src/test/java/com/ejlchina/test/DownloadTests.java index e5cf2ef4..dd2fe80d 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/DownloadTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/DownloadTests.java @@ -1,5 +1,7 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.Process; +import com.ejlchina.okhttps.*; import okhttp3.OkHttpClient; import org.junit.Test; @@ -163,7 +165,7 @@ public void testDownload() { }) .build(); - String url = "https://gitee.com/troyzhxu/okhttps/blob/master/README.md"; + String url = "https://gitee.com/ejlchina-zhxu/okhttps/blob/master/README.md"; // String url = "http://47.100.7.202/ejl-test.zip"; long t0 = now(); diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/ExceptionTests.java b/okhttps/src/test/java/com/ejlchina/test/ExceptionTests.java similarity index 94% rename from okhttps/src/test/java/cn/zhxu/okhttps/ExceptionTests.java rename to okhttps/src/test/java/com/ejlchina/test/ExceptionTests.java index ae1245d4..29985246 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/ExceptionTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/ExceptionTests.java @@ -1,5 +1,8 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.HTTP; +import com.ejlchina.okhttps.HttpResult; +import com.ejlchina.okhttps.OkHttpsException; import okhttp3.OkHttpClient; import org.junit.Test; diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/ExecutorTests.java b/okhttps/src/test/java/com/ejlchina/test/ExecutorTests.java similarity index 87% rename from okhttps/src/test/java/cn/zhxu/okhttps/ExecutorTests.java rename to okhttps/src/test/java/com/ejlchina/test/ExecutorTests.java index a598128c..ccbed45f 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/ExecutorTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/ExecutorTests.java @@ -1,5 +1,8 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.HTTP; +import com.ejlchina.okhttps.HttpResult; +import com.ejlchina.okhttps.Process; import org.junit.Test; public class ExecutorTests extends BaseTest { diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/ListenerTests.java b/okhttps/src/test/java/com/ejlchina/test/ListenerTests.java similarity index 96% rename from okhttps/src/test/java/cn/zhxu/okhttps/ListenerTests.java rename to okhttps/src/test/java/com/ejlchina/test/ListenerTests.java index 2d38a050..1f69e126 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/ListenerTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/ListenerTests.java @@ -1,5 +1,7 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.Process; +import com.ejlchina.okhttps.*; import org.junit.Test; import java.io.File; diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/PreprocessorTests.java b/okhttps/src/test/java/com/ejlchina/test/PreprocessorTests.java similarity index 93% rename from okhttps/src/test/java/cn/zhxu/okhttps/PreprocessorTests.java rename to okhttps/src/test/java/com/ejlchina/test/PreprocessorTests.java index bd490cf1..f20fe559 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/PreprocessorTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/PreprocessorTests.java @@ -1,5 +1,7 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.HTTP; +import com.ejlchina.okhttps.Preprocessor; import org.junit.Test; public class PreprocessorTests extends BaseTest { diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/SimpleTests.java b/okhttps/src/test/java/com/ejlchina/test/SimpleTests.java similarity index 86% rename from okhttps/src/test/java/cn/zhxu/okhttps/SimpleTests.java rename to okhttps/src/test/java/com/ejlchina/test/SimpleTests.java index 956e086d..c4fa7d3f 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/SimpleTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/SimpleTests.java @@ -1,5 +1,6 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.OkHttps; import okhttp3.mockwebserver.MockResponse; import org.junit.Assert; import org.junit.Test; @@ -14,20 +15,6 @@ public void testSyncPost() throws InterruptedException { Assert.assertEquals(server.takeRequest().getHeader("Content-Type"), "application/x-www-form-urlencoded; charset=UTF-8"); } - @Test - public void test() { - HttpResult res = HTTP.builder() - .build() - .sync("http://www.baidu.com") - .bodyType("application/x-www-form-urlencoded") - .addBodyPara("name", "Jack") - .addBodyPara("age", 11) - .post() - .close(); - System.out.println(res); - } - - /** * 同步请求示例 * 同步请求直接得到结果,无需设置回调 diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/TagTests.java b/okhttps/src/test/java/com/ejlchina/test/TagTests.java similarity index 87% rename from okhttps/src/test/java/cn/zhxu/okhttps/TagTests.java rename to okhttps/src/test/java/com/ejlchina/test/TagTests.java index 2ab0f0e8..8e8665f1 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/TagTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/TagTests.java @@ -1,6 +1,8 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; -import cn.zhxu.okhttps.internal.AbstractHttpClient; +import com.ejlchina.okhttps.HTTP; +import com.ejlchina.okhttps.HttpResult; +import com.ejlchina.okhttps.internal.AbstractHttpClient; import okhttp3.OkHttpClient; import org.junit.Test; diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/UploadTests.java b/okhttps/src/test/java/com/ejlchina/test/UploadTests.java similarity index 96% rename from okhttps/src/test/java/cn/zhxu/okhttps/UploadTests.java rename to okhttps/src/test/java/com/ejlchina/test/UploadTests.java index 83506cd8..10bcd28f 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/UploadTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/UploadTests.java @@ -1,5 +1,6 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; +import com.ejlchina.okhttps.Process; import okhttp3.mockwebserver.MockResponse; import org.junit.Assert; import org.junit.Test; diff --git a/okhttps/src/test/java/cn/zhxu/okhttps/WebSocketTests.java b/okhttps/src/test/java/com/ejlchina/test/WebSocketTests.java similarity index 89% rename from okhttps/src/test/java/cn/zhxu/okhttps/WebSocketTests.java rename to okhttps/src/test/java/com/ejlchina/test/WebSocketTests.java index 47a52963..3f1b0c44 100644 --- a/okhttps/src/test/java/cn/zhxu/okhttps/WebSocketTests.java +++ b/okhttps/src/test/java/com/ejlchina/test/WebSocketTests.java @@ -1,9 +1,9 @@ -package cn.zhxu.okhttps; +package com.ejlchina.test; -import cn.zhxu.okhttps.HTTP; -import cn.zhxu.okhttps.HttpResult; -import cn.zhxu.okhttps.WebSocket; -import cn.zhxu.okhttps.WebSocket.Message; +import com.ejlchina.okhttps.HTTP; +import com.ejlchina.okhttps.HttpResult; +import com.ejlchina.okhttps.WebSocket; +import com.ejlchina.okhttps.WebSocket.Message; import org.junit.Test; public class WebSocketTests { diff --git a/pom.xml b/pom.xml index 27ee625c..6d6673e3 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - cn.zhxu + com.ejlchina okhttps-parent - 4.1.0 + 3.4.5 OkHttps pom @@ -13,20 +13,16 @@ okhttps-stomp okhttps-gson okhttps-jackson - okhttps-jackson-xml - okhttps-jackson-yaml okhttps-fastjson - okhttps-fastjson2 - okhttps-fastjson2-jsonb - okhttps-snack3 + okhttps-xml okhttps-test 1.8 - 1.6.2 + 1.2.0 3.14.9 - 1.17.6 + 1.17.5 4.13.2 UTF-8 https://oss.sonatype.org/content/repositories/snapshots/ @@ -49,10 +45,10 @@ - scm:git://gitee.com/troyzhxu/okhttps.git - scm:http://gitee.com/troyzhxu/okhttps - https://gitee.com/troyzhxu/okhttps - v${project.version} + scm:git://gitee.com/ejlchina-zhxu/okhttps.git + scm:http://gitee.com/ejlchina-zhxu/okhttps + https://gitee.com/ejlchina-zhxu/okhttps + v3.4.5 @@ -63,15 +59,31 @@ test - + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + ${sonatypeOssDistMgmtSnapshotsUrl} - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ @@ -97,9 +109,9 @@ default-compile - 1.8 + 11 - + 11 @@ -170,13 +182,13 @@ - https://gitee.com/troyzhxu/okhttps + https://gitee.com/ejlchina-zhxu/okhttps 比 Retrofit 更好用的网络框架! OkHttp3 轻量封装 ,开箱即用、Java领域前后端处理 Http问题的新选择。 - zhouxu - https://zhxu.cn/ + 江苏一键联信息科技有限公司 + http://www.ejlchina.com/ - https://gitee.com/troyzhxu/okhttps/issues + https://gitee.com/ejlchina-zhxu/okhttps/issues \ No newline at end of file