From 2b0fd627208ecf08242724d945517c27393cbb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=96=87=E8=AE=AE?= Date: Thu, 30 Apr 2020 14:24:46 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=87=86=E5=A4=87=E6=9E=84=E5=BB=BA2.0.4?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 54bc0ee..18d9386 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.fengwenyi JavaLib - 2.0.3.RELEASE + 2.0.4.BUILD jar JavaLib JAVA开发常用工具集 From dcfd283ac4077de33fb323912d9d7f65d3eb6d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=96=87=E8=AE=AE?= Date: Mon, 11 May 2020 00:37:00 +0800 Subject: [PATCH 2/7] =?UTF-8?q?Http=E8=AF=B7=E6=B1=82=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/HttpHeaderKeyConstant.java | 13 ++++ .../javalib/constant/MediaTypeConstant.java | 13 ++++ .../com/fengwenyi/javalib/util/HttpUtils.java | 70 ++++++++++++++++++- .../com/fengwenyi/javalib/HttpUtilsTests.java | 46 ++++++++++++ 4 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java create mode 100644 src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java create mode 100644 src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java diff --git a/src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java b/src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java new file mode 100644 index 0000000..c34404d --- /dev/null +++ b/src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java @@ -0,0 +1,13 @@ +package com.fengwenyi.javalib.constant; + +/** + * Http header key + * @author Erwin Feng + * @since 2020/5/11 12:11 上午 + */ +public class HttpHeaderKeyConstant { + + /** Content-Type */ + public static final String CONTENT_TYPE = "Content-Type"; + +} diff --git a/src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java b/src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java new file mode 100644 index 0000000..b15285d --- /dev/null +++ b/src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java @@ -0,0 +1,13 @@ +package com.fengwenyi.javalib.constant; + +/** + * Http Media Type + * @author Erwin Feng + * @since 2020/5/11 12:08 上午 + */ +public class MediaTypeConstant { + + /** application/json */ + public static final String APPLICATION_JSON_VALUE = "application/json"; + +} diff --git a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java b/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java index c38d42c..b84ed29 100644 --- a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java +++ b/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java @@ -1,6 +1,8 @@ package com.fengwenyi.javalib.util; import com.fengwenyi.javalib.constant.ContentType; +import com.fengwenyi.javalib.constant.HttpHeaderKeyConstant; +import com.fengwenyi.javalib.constant.MediaTypeConstant; import okhttp3.*; import java.io.IOException; @@ -67,12 +69,25 @@ public static String postJson(String url, String jsonStr) throws IOException { /** * get请求 * @param url URL - * @param paramMap 参数,用Map进行封装 + * @param map 参数,用Map进行封装 + * @return 服务器响应字符串 + * @throws IOException IO异常 + */ + public static String get(String url, Map map) throws IOException { + String param = ParamUtils.getUrlParamsByMap(map); + if (StringUtils.isNotEmpty(param)) + url = url + "?" + param; + return get(url); + } + + /** + * get请求 + * @param url URL + * @param param 参数 * @return 服务器响应字符串 * @throws IOException IO异常 */ - public static String get(String url, Map paramMap) throws IOException { - String param = ParamUtils.getUrlParamsByMap(paramMap); + public static String get(String url, String param) throws IOException { if (StringUtils.isNotEmpty(param)) url = url + "?" + param; return get(url); @@ -95,4 +110,53 @@ public static String get(String url) throws IOException { return response.body().string(); } + /** + * get请求 + * @param url URL + * @return 服务器响应字符串 + * @throws IOException IO异常 + */ + public static String getJson(String url) throws IOException { + OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); + Request request = new Request.Builder() + .url(url) + .addHeader(HttpHeaderKeyConstant.CONTENT_TYPE, MediaTypeConstant.APPLICATION_JSON_VALUE) + .get() + .build(); + Response response = okHttpClient.newCall(request).execute(); + assert response.body() != null; + return response.body().string(); + } + + /** + * get请求 + * @param url URL + * @param param 参数 + * @return 服务器响应字符串 + * @throws IOException IO异常 + */ + public static String getJson(String url, String param) throws IOException { + if (StringUtils.isNotEmpty(param)) + url = url + "?" + param; + return getJson(url); + } + + /** + * get请求 + * @param url URL + * @return 服务器响应字符串 + * @throws IOException IO异常 + */ + public static String getJson(String url, Map headers, String param) throws IOException { + OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); + Request request = new Request.Builder() + .url(url) + .addHeader(HttpHeaderKeyConstant.CONTENT_TYPE, MediaTypeConstant.APPLICATION_JSON_VALUE) + .get() + .build(); + Response response = okHttpClient.newCall(request).execute(); + assert response.body() != null; + return response.body().string(); + } + } diff --git a/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java b/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java new file mode 100644 index 0000000..69fcb2a --- /dev/null +++ b/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java @@ -0,0 +1,46 @@ +package com.fengwenyi.javalib; + +import com.fengwenyi.javalib.util.HttpUtils; +import org.junit.Test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Erwin Feng + * @since 2020/5/10 11:27 下午 + */ +public class HttpUtilsTests { + + @Test + public void testGet() throws IOException { + String url = "https://www.baidu.com"; + String response = HttpUtils.get(url); + System.out.println(response); + } + + @Test + public void testGetJson() throws IOException { + String url = "http://localhost:9191/api/test/result"; + String response = HttpUtils.getJson(url); + System.out.println(response); + } + + @Test + public void testGetParamMap() throws IOException { + String url = "https://www.baidu.com"; + Map map = new HashMap<>(); + String response = HttpUtils.get(url, map); + System.out.println(response); + } + + @Test + public void testGetParam() throws IOException { + String url = "https://www.baidu.com"; + String param = ""; + String response = HttpUtils.get(url, param); + System.out.println(response); + } + +} From 5d8c1227376a7451e8f26708c8fd2c852bcc9b40 Mon Sep 17 00:00:00 2001 From: Erwin Date: Thu, 21 May 2020 00:42:24 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- version/2.0.4.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 version/2.0.4.md diff --git a/version/2.0.4.md b/version/2.0.4.md new file mode 100644 index 0000000..f59a08f --- /dev/null +++ b/version/2.0.4.md @@ -0,0 +1,9 @@ +# 2.0.4 + +## 新增 + +## 优化 + +- HTTP请求工具类(HttpUtils)【2020.5.21(优化中)】 + +## 删除 \ No newline at end of file From ece512bee1e2a7eb7c7cd73735419ae394c7f31d Mon Sep 17 00:00:00 2001 From: Erwin Date: Thu, 21 May 2020 00:42:41 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BC=98=E5=8C=96HTTP=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fengwenyi/javalib/util/HttpUtils.java | 53 +++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java b/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java index b84ed29..8efb010 100644 --- a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java +++ b/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java @@ -142,18 +142,51 @@ public static String getJson(String url, String param) throws IOException { } /** - * get请求 - * @param url URL - * @return 服务器响应字符串 - * @throws IOException IO异常 + * 自定义get请求 + * @param url URL + * @param headers 自定义请求头 + * @param param 参数 + * @return 服务器响应字符串 + * @throws IOException IO异常 */ - public static String getJson(String url, Map headers, String param) throws IOException { + public static String get(String url, Map headers, String param) throws IOException { OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); - Request request = new Request.Builder() - .url(url) - .addHeader(HttpHeaderKeyConstant.CONTENT_TYPE, MediaTypeConstant.APPLICATION_JSON_VALUE) - .get() - .build(); + Request.Builder requestBuilder = new Request.Builder(); + for (Map.Entry entry : headers.entrySet()) { + String headerKey = entry.getKey(); + String headerValue = entry.getValue(); + requestBuilder.addHeader(headerKey, headerValue); + } + if (StringUtils.isNotEmpty(param)) + url = url + "?" + param; + requestBuilder.url(url).get(); + Request request = requestBuilder.build(); + Response response = okHttpClient.newCall(request).execute(); + assert response.body() != null; + return response.body().string(); + } + + /** + * 自定义post请求 + * @param url URL + * @param headers 自定义请求头 + * @param param 参数 + * @return 服务器响应字符串 + * @throws IOException IO异常 + */ + public static String post(String url, Map headers, String param) throws IOException { + OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); + Request.Builder requestBuilder = new Request.Builder(); + for (Map.Entry entry : headers.entrySet()) { + String headerKey = entry.getKey(); + String headerValue = entry.getValue(); + requestBuilder.addHeader(headerKey, headerValue); + } + if (StringUtils.isNotEmpty(param)) + url = url + "?" + param; + requestBuilder.url(url) + .post(s); + Request request = requestBuilder.build(); Response response = okHttpClient.newCall(request).execute(); assert response.body() != null; return response.body().string(); From 39ec1664c3b8c1a85b1d426489233405a062ab55 Mon Sep 17 00:00:00 2001 From: Erwin Date: Sat, 23 May 2020 19:48:43 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BC=98=E5=8C=96HTTP=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fengwenyi/javalib/util/HttpUtils.java | 60 +------------------ .../com/fengwenyi/javalib/HttpUtilsTests.java | 18 +++--- 2 files changed, 13 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java b/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java index 8efb010..ceb25f0 100644 --- a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java +++ b/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java @@ -17,8 +17,9 @@ *
  • json提交
  • *
  • header设置
  • * + *

    经过深思之后,决定这个工具类移除,我会以博文的形式记录使用OKHttp请求

    * @author Erwin Feng - * @since 2019-06-27 00:09 + * @since 2019-06-27 */ public class HttpUtils { @@ -110,37 +111,6 @@ public static String get(String url) throws IOException { return response.body().string(); } - /** - * get请求 - * @param url URL - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String getJson(String url) throws IOException { - OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); - Request request = new Request.Builder() - .url(url) - .addHeader(HttpHeaderKeyConstant.CONTENT_TYPE, MediaTypeConstant.APPLICATION_JSON_VALUE) - .get() - .build(); - Response response = okHttpClient.newCall(request).execute(); - assert response.body() != null; - return response.body().string(); - } - - /** - * get请求 - * @param url URL - * @param param 参数 - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String getJson(String url, String param) throws IOException { - if (StringUtils.isNotEmpty(param)) - url = url + "?" + param; - return getJson(url); - } - /** * 自定义get请求 * @param url URL @@ -166,30 +136,4 @@ public static String get(String url, Map headers, String param) return response.body().string(); } - /** - * 自定义post请求 - * @param url URL - * @param headers 自定义请求头 - * @param param 参数 - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String post(String url, Map headers, String param) throws IOException { - OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); - Request.Builder requestBuilder = new Request.Builder(); - for (Map.Entry entry : headers.entrySet()) { - String headerKey = entry.getKey(); - String headerValue = entry.getValue(); - requestBuilder.addHeader(headerKey, headerValue); - } - if (StringUtils.isNotEmpty(param)) - url = url + "?" + param; - requestBuilder.url(url) - .post(s); - Request request = requestBuilder.build(); - Response response = okHttpClient.newCall(request).execute(); - assert response.body() != null; - return response.body().string(); - } - } diff --git a/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java b/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java index 69fcb2a..2d43ac3 100644 --- a/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java +++ b/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java @@ -8,6 +8,17 @@ import java.util.Map; /** + * 测试HTTP请求工具类:HttpUtils + *

    测试项:

    + *
      + *
    • get请求
    • + *
    • post请求
    • + *
    • put请求
    • + *
    • patch请求
    • + *
    • delete请求
    • + *
    • json请求
    • + *
    • 自定义header请求
    • + *
    * @author Erwin Feng * @since 2020/5/10 11:27 下午 */ @@ -20,13 +31,6 @@ public void testGet() throws IOException { System.out.println(response); } - @Test - public void testGetJson() throws IOException { - String url = "http://localhost:9191/api/test/result"; - String response = HttpUtils.getJson(url); - System.out.println(response); - } - @Test public void testGetParamMap() throws IOException { String url = "https://www.baidu.com"; From 3a57d9bf0dacc471e71c5b6038e6313bfeb76509 Mon Sep 17 00:00:00 2001 From: Erwin Date: Thu, 28 May 2020 19:42:57 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E7=9A=84=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 2 +- pom.xml | 15 -- .../{Charset.java => CharsetConstant.java} | 2 +- .../javalib/constant/ContentType.java | 20 -- ...nType.java => EncryptionTypeConstant.java} | 2 +- .../constant/HttpHeaderKeyConstant.java | 2 +- .../{LogLevel.java => LogLevelConstant.java} | 2 +- .../javalib/constant/MediaTypeConstant.java | 3 + ...Method.java => RequestMethodConstant.java} | 2 +- .../constant/{URL.java => URLConstant.java} | 2 +- ...{UserAgent.java => UserAgentConstant.java} | 2 +- .../com/fengwenyi/javalib/util/BeanUtils.java | 14 - .../javalib/util/ExceptionUtils.java | 61 ----- .../com/fengwenyi/javalib/util/HttpUtils.java | 139 ---------- .../com/fengwenyi/javalib/util/IpUtils.java | 119 --------- .../com/fengwenyi/javalib/util/MD5Utils.java | 4 +- .../javalib/util/NumberToChnUtils.java | 249 ------------------ .../fengwenyi/javalib/util/ParamUtils.java | 4 +- .../fengwenyi/javalib/util/PatternUtils.java | 9 - .../com/fengwenyi/javalib/util/RSAUtils.java | 6 +- .../fengwenyi/javalib/util/RequestUtils.java | 5 + .../com/fengwenyi/javalib/util/SHAUtils.java | 4 +- .../com/fengwenyi/javalib/HttpUtilsTests.java | 50 ---- .../com/fengwenyi/javalib/IpUtilsTests.java | 37 --- version/2.0.4.md | 12 +- 25 files changed, 35 insertions(+), 732 deletions(-) rename src/main/java/com/fengwenyi/javalib/constant/{Charset.java => CharsetConstant.java} (85%) delete mode 100644 src/main/java/com/fengwenyi/javalib/constant/ContentType.java rename src/main/java/com/fengwenyi/javalib/constant/{EncryptionType.java => EncryptionTypeConstant.java} (87%) rename src/main/java/com/fengwenyi/javalib/constant/{LogLevel.java => LogLevelConstant.java} (97%) rename src/main/java/com/fengwenyi/javalib/constant/{RequestMethod.java => RequestMethodConstant.java} (91%) rename src/main/java/com/fengwenyi/javalib/constant/{URL.java => URLConstant.java} (89%) rename src/main/java/com/fengwenyi/javalib/constant/{UserAgent.java => UserAgentConstant.java} (99%) delete mode 100644 src/main/java/com/fengwenyi/javalib/util/BeanUtils.java delete mode 100644 src/main/java/com/fengwenyi/javalib/util/ExceptionUtils.java delete mode 100644 src/main/java/com/fengwenyi/javalib/util/HttpUtils.java delete mode 100644 src/main/java/com/fengwenyi/javalib/util/IpUtils.java delete mode 100644 src/main/java/com/fengwenyi/javalib/util/NumberToChnUtils.java delete mode 100644 src/main/java/com/fengwenyi/javalib/util/PatternUtils.java delete mode 100644 src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java delete mode 100644 src/test/java/com/fengwenyi/javalib/IpUtilsTests.java diff --git a/LICENSE b/LICENSE index fd7a4bb..f05b8b3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Erwin Feng +Copyright (c) 2020 Erwin Feng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pom.xml b/pom.xml index 18d9386..126edfc 100644 --- a/pom.xml +++ b/pom.xml @@ -55,13 +55,6 @@ provided - - - com.alibaba - fastjson - ${fastjson.version} - - com.fasterxml.jackson.core @@ -70,14 +63,6 @@ provided - - - com.squareup.okhttp3 - okhttp - ${okhttp.version} - - - net.coobird diff --git a/src/main/java/com/fengwenyi/javalib/constant/Charset.java b/src/main/java/com/fengwenyi/javalib/constant/CharsetConstant.java similarity index 85% rename from src/main/java/com/fengwenyi/javalib/constant/Charset.java rename to src/main/java/com/fengwenyi/javalib/constant/CharsetConstant.java index 663dc9a..26c3255 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/Charset.java +++ b/src/main/java/com/fengwenyi/javalib/constant/CharsetConstant.java @@ -5,7 +5,7 @@ * @author Wenyi Feng * @since 2018-10-28 */ -public class Charset { +public class CharsetConstant { /** * UTF-8 diff --git a/src/main/java/com/fengwenyi/javalib/constant/ContentType.java b/src/main/java/com/fengwenyi/javalib/constant/ContentType.java deleted file mode 100644 index 6fafe36..0000000 --- a/src/main/java/com/fengwenyi/javalib/constant/ContentType.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fengwenyi.javalib.constant; - -/** - * Content Type - * @author Wenyi Feng - * @since 2018-11-17 - */ -public class ContentType { - - /** - * 表单类型 - */ - public static final String FROM = "application/x-www-form-urlencoded; charset=UTF-8"; - - /** - * JSON格式 - */ - public static final String JSON = "application/json; charset=UTF-8"; - -} diff --git a/src/main/java/com/fengwenyi/javalib/constant/EncryptionType.java b/src/main/java/com/fengwenyi/javalib/constant/EncryptionTypeConstant.java similarity index 87% rename from src/main/java/com/fengwenyi/javalib/constant/EncryptionType.java rename to src/main/java/com/fengwenyi/javalib/constant/EncryptionTypeConstant.java index 62ff63c..8be898c 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/EncryptionType.java +++ b/src/main/java/com/fengwenyi/javalib/constant/EncryptionTypeConstant.java @@ -5,7 +5,7 @@ * @author Wenyi Feng * @since 2018-10-16 */ -public class EncryptionType { +public class EncryptionTypeConstant { /** * md5 diff --git a/src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java b/src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java index c34404d..5a204ab 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java +++ b/src/main/java/com/fengwenyi/javalib/constant/HttpHeaderKeyConstant.java @@ -8,6 +8,6 @@ public class HttpHeaderKeyConstant { /** Content-Type */ - public static final String CONTENT_TYPE = "Content-Type"; + public static final String KEY_CONTENT_TYPE = "Content-Type"; } diff --git a/src/main/java/com/fengwenyi/javalib/constant/LogLevel.java b/src/main/java/com/fengwenyi/javalib/constant/LogLevelConstant.java similarity index 97% rename from src/main/java/com/fengwenyi/javalib/constant/LogLevel.java rename to src/main/java/com/fengwenyi/javalib/constant/LogLevelConstant.java index 854c436..1163989 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/LogLevel.java +++ b/src/main/java/com/fengwenyi/javalib/constant/LogLevelConstant.java @@ -18,7 +18,7 @@ * @author Erwin Feng * @since 2019-03-14 10:58 */ -public class LogLevel { +public class LogLevelConstant { /** 各级包括自定义级别 */ public static final String ALL = "ALL"; diff --git a/src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java b/src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java index b15285d..1b22f6a 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java +++ b/src/main/java/com/fengwenyi/javalib/constant/MediaTypeConstant.java @@ -10,4 +10,7 @@ public class MediaTypeConstant { /** application/json */ public static final String APPLICATION_JSON_VALUE = "application/json"; + /** application/...form... */ + public static final String APPLICATION_FORM_VALUE = "application/x-www-form-urlencoded;"; + } diff --git a/src/main/java/com/fengwenyi/javalib/constant/RequestMethod.java b/src/main/java/com/fengwenyi/javalib/constant/RequestMethodConstant.java similarity index 91% rename from src/main/java/com/fengwenyi/javalib/constant/RequestMethod.java rename to src/main/java/com/fengwenyi/javalib/constant/RequestMethodConstant.java index 79e9d49..0eaf437 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/RequestMethod.java +++ b/src/main/java/com/fengwenyi/javalib/constant/RequestMethodConstant.java @@ -5,7 +5,7 @@ * @author Wenyi Feng * @since 2018-09-25 */ -public class RequestMethod { +public class RequestMethodConstant { /** * get diff --git a/src/main/java/com/fengwenyi/javalib/constant/URL.java b/src/main/java/com/fengwenyi/javalib/constant/URLConstant.java similarity index 89% rename from src/main/java/com/fengwenyi/javalib/constant/URL.java rename to src/main/java/com/fengwenyi/javalib/constant/URLConstant.java index 6be3b78..64912fc 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/URL.java +++ b/src/main/java/com/fengwenyi/javalib/constant/URLConstant.java @@ -4,7 +4,7 @@ * @author Wenyi Feng * @since 2018-10-28 */ -public class URL { +public class URLConstant { /** * 获取ip地址的信息的uri diff --git a/src/main/java/com/fengwenyi/javalib/constant/UserAgent.java b/src/main/java/com/fengwenyi/javalib/constant/UserAgentConstant.java similarity index 99% rename from src/main/java/com/fengwenyi/javalib/constant/UserAgent.java rename to src/main/java/com/fengwenyi/javalib/constant/UserAgentConstant.java index a6b4498..6e658dc 100644 --- a/src/main/java/com/fengwenyi/javalib/constant/UserAgent.java +++ b/src/main/java/com/fengwenyi/javalib/constant/UserAgentConstant.java @@ -4,7 +4,7 @@ * @author Wenyi Feng * @since 2018-11-17 */ -public class UserAgent { +public class UserAgentConstant { private static final String MAC_ = "Mozilla/5.0 (Macintosh; PPC Mac OS X) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"; diff --git a/src/main/java/com/fengwenyi/javalib/util/BeanUtils.java b/src/main/java/com/fengwenyi/javalib/util/BeanUtils.java deleted file mode 100644 index c0f004b..0000000 --- a/src/main/java/com/fengwenyi/javalib/util/BeanUtils.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.fengwenyi.javalib.util; - -/** - * Bean工具类 - * @author Wenyi Feng - * @since 2018-10-15 - */ -public class BeanUtils { - - // 拷贝bean相同名称类型的属性(不包含父类) - - // 拷贝bean相同名称类型的属性(包含父类) - -} diff --git a/src/main/java/com/fengwenyi/javalib/util/ExceptionUtils.java b/src/main/java/com/fengwenyi/javalib/util/ExceptionUtils.java deleted file mode 100644 index bdc95b6..0000000 --- a/src/main/java/com/fengwenyi/javalib/util/ExceptionUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.fengwenyi.javalib.util; - -/** - * 异常处理工具类 - *

    - * 看博客说 java 应该提供一个异常处理的东西,不同的人可以看到不同的错误级别,我也正在向这个方向靠拢 - *

    - * - * @author Wenyi Feng - * @since 2018-08-27 - */ -public class ExceptionUtils { - - /** - * 校验参数是否为空,如果不为空,将抛出异常 - * @param object 参数对象 - * @param message 异常说明信息 - * (@see org.springframework.util.Assert#isNull) - */ - public static void isNull(Object object, String message) { - if (object != null) - throw new IllegalArgumentException(message); // 非法参数异常 - } - - /** - * 校验参数是否不为空,如果为空,将抛出异常 - * @param object 参数对象 - * @param message 异常说明信息 - * (@see org.springframework.util.Assert#notNull) - */ - public static void notNull(Object object, String message) { - if (object == null) - throw new IllegalArgumentException(message); - /* - * 如果是字符串,我不希望你的字符串是一个空字符串,那样没有任何意义, - * 但是你仍然坚持要为空,那你可以添加一个空格(" ")试试 - * */ - if (object instanceof String) - if (StringUtils.isEmpty((String) object)) - throw new IllegalArgumentException(message); - } - - /** - * 校验参数是否为空,如果不为空,将抛出异常 - * @param object 参数对象 - * (@see org.springframework.util.Assert#isNull) - */ - public static void isNull(Object object) { - isNull(object, "Param must null."); - } - - /** - * 校验参数是否为空,如果不为空,将抛出异常 - * @param object 参数对象 - * (@see org.springframework.util.Assert#isNull) - */ - public static void notNull(Object object) { - notNull(object, "Param must not null."); - } - -} diff --git a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java b/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java deleted file mode 100644 index ceb25f0..0000000 --- a/src/main/java/com/fengwenyi/javalib/util/HttpUtils.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.fengwenyi.javalib.util; - -import com.fengwenyi.javalib.constant.ContentType; -import com.fengwenyi.javalib.constant.HttpHeaderKeyConstant; -import com.fengwenyi.javalib.constant.MediaTypeConstant; -import okhttp3.*; - -import java.io.IOException; -import java.util.Map; - -/** - * Http请求工具类 - *
      - *
    • get
    • - *
    • post
    • - *
    • form表单提交
    • - *
    • json提交
    • - *
    • header设置
    • - *
    - *

    经过深思之后,决定这个工具类移除,我会以博文的形式记录使用OKHttp请求

    - * @author Erwin Feng - * @since 2019-06-27 - */ -public class HttpUtils { - - /** - * post方式提交表单 - * @param url URL - * @param paramMap 参数,用Map进行封装 - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String postForm(String url, Map paramMap) throws IOException { - FormBody.Builder formBuilder = new FormBody.Builder(); - for (Map.Entry entry : paramMap.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - formBuilder.add(key, value); - } - FormBody formBody = formBuilder.build(); - OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); - Request request = new Request.Builder() - .url(url) - .post(formBody) - .build(); - Response response = okHttpClient.newCall(request).execute(); - assert response.body() != null; - return response.body().string(); - } - - /** - * post方式提交json字符串格式参数 - * @param url URL - * @param jsonStr 参数,json字符串 - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String postJson(String url, String jsonStr) throws IOException { - MediaType mediaType = MediaType.parse(ContentType.JSON); - OkHttpClient okHttpClient = new OkHttpClient(); - Request request = new Request.Builder() - .url(url) - .post(RequestBody.create(mediaType, jsonStr)) - .build(); - Response response = okHttpClient.newCall(request).execute(); - assert response.body() != null; - return response.body().string(); - } - - /** - * get请求 - * @param url URL - * @param map 参数,用Map进行封装 - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String get(String url, Map map) throws IOException { - String param = ParamUtils.getUrlParamsByMap(map); - if (StringUtils.isNotEmpty(param)) - url = url + "?" + param; - return get(url); - } - - /** - * get请求 - * @param url URL - * @param param 参数 - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String get(String url, String param) throws IOException { - if (StringUtils.isNotEmpty(param)) - url = url + "?" + param; - return get(url); - } - - /** - * get请求 - * @param url URL - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String get(String url) throws IOException { - OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); - Request request = new Request.Builder() - .url(url) - .get() - .build(); - Response response = okHttpClient.newCall(request).execute(); - assert response.body() != null; - return response.body().string(); - } - - /** - * 自定义get请求 - * @param url URL - * @param headers 自定义请求头 - * @param param 参数 - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - public static String get(String url, Map headers, String param) throws IOException { - OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); - Request.Builder requestBuilder = new Request.Builder(); - for (Map.Entry entry : headers.entrySet()) { - String headerKey = entry.getKey(); - String headerValue = entry.getValue(); - requestBuilder.addHeader(headerKey, headerValue); - } - if (StringUtils.isNotEmpty(param)) - url = url + "?" + param; - requestBuilder.url(url).get(); - Request request = requestBuilder.build(); - Response response = okHttpClient.newCall(request).execute(); - assert response.body() != null; - return response.body().string(); - } - -} diff --git a/src/main/java/com/fengwenyi/javalib/util/IpUtils.java b/src/main/java/com/fengwenyi/javalib/util/IpUtils.java deleted file mode 100644 index 292797f..0000000 --- a/src/main/java/com/fengwenyi/javalib/util/IpUtils.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.fengwenyi.javalib.util; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.fengwenyi.javalib.constant.URL; -import okhttp3.Call; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -import java.io.IOException; - -//import org.lionsoul.ip2region.*; - -/** - * @author Wenyi Feng - * @since 2018-10-28 - */ -public class IpUtils { - - /** - * 请求佯装KEY - */ - private static final String USER_AGENT_KEY = "User-Agent"; - - /** - * 请求佯装VALUE - */ - private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36 JavaLib"; - - - /** - * 通过ip获取位置 - * @param ip ip地址 - * @return (国家)(地区)(省份)(城市)(县级)(运营商) - * @throws IOException io异常 - */ - public static String getPosition(String ip) throws IOException { - JSONObject jsonObject = getIpInfo(ip); - if (jsonObject != null) { - String country = jsonObject.get("country").toString(); - String area = jsonObject.get("area").toString(); - String region = jsonObject.get("region").toString(); - String city = jsonObject.get("city").toString(); - String county = jsonObject.get("county").toString(); - String isp = jsonObject.get("isp").toString(); - return country + area + region + city + county + isp; - } - return null; - } - - /** - * 获取ip位置信息 - * @param ip ip地址 - * @return json数据 - * @throws IOException io异常 - */ - public static JSONObject getIpInfo(String ip) throws IOException { - String param = "?ip=" + ip; - String ipInfoStr = getIpInfoByIp(URL.IP_INFO_URI + param); - JSONObject jsonObject = JSON.parseObject(ipInfoStr); - Integer code = (Integer) jsonObject.get("code"); - if (code == 0) { - return jsonObject.getJSONObject("data"); - } - return null; - } - - /** - * 通过IP获取IP信息 - * @param url url - * @return 服务器响应字符串 - * @throws IOException IO异常 - */ - private static String getIpInfoByIp(String url) throws IOException { - OkHttpClient okHttpClient = new OkHttpClient(); - Request request = new Request.Builder() - .url(url) - .get() - .removeHeader(USER_AGENT_KEY) - .addHeader(USER_AGENT_KEY, USER_AGENT_VALUE) - .build(); - Call call = okHttpClient.newCall(request); - Response response = call.execute(); - return response.body() == null ? "" : response.body().string(); - } - - // 有问题 还在测试 - /*public static String getCityInfo(int algorithm, String ip) throws - DbMakerConfigException, - FileNotFoundException, - NoSuchMethodException, - InvocationTargetException, - IllegalAccessException { - String dbPath = IpUtils.class.getResource("ip2region.db").getPath(); // null - PrintUtils.info(dbPath); - File file = new File(dbPath); - DbConfig config = new DbConfig(); - DbSearcher searcher = new DbSearcher(config, file.getPath()); - Method method; - switch (algorithm) { - case DbSearcher.BTREE_ALGORITHM: - method = searcher.getClass().getMethod("btreeSearch", String.class); - break; - case DbSearcher.BINARY_ALGORITHM: - method = searcher.getClass().getMethod("binarySearch", String.class); - break; - default: - method = searcher.getClass().getMethod("memorySearch", String.class); - break; - } - if (!Util.isIpAddress(ip)) { - throw new IllegalArgumentException("Invalid ip address"); - } - DataBlock dataBlock = (DataBlock) method.invoke(searcher, ip); - return dataBlock.getRegion(); - }*/ - -} diff --git a/src/main/java/com/fengwenyi/javalib/util/MD5Utils.java b/src/main/java/com/fengwenyi/javalib/util/MD5Utils.java index 8c4df16..86ab390 100644 --- a/src/main/java/com/fengwenyi/javalib/util/MD5Utils.java +++ b/src/main/java/com/fengwenyi/javalib/util/MD5Utils.java @@ -1,7 +1,7 @@ package com.fengwenyi.javalib.util; -import com.fengwenyi.javalib.constant.EncryptionType; +import com.fengwenyi.javalib.constant.EncryptionTypeConstant; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -21,7 +21,7 @@ public class MD5Utils { */ public static String md5(String plainText) throws NoSuchAlgorithmException { // 创建一个md5算法对象 - MessageDigest md = MessageDigest.getInstance(EncryptionType.MD5); + MessageDigest md = MessageDigest.getInstance(EncryptionTypeConstant.MD5); byte[] messageByte = plainText.getBytes(); // 获得MD5字节数组,16*8=128位 byte[] md5Byte = md.digest(messageByte); diff --git a/src/main/java/com/fengwenyi/javalib/util/NumberToChnUtils.java b/src/main/java/com/fengwenyi/javalib/util/NumberToChnUtils.java deleted file mode 100644 index 926aa36..0000000 --- a/src/main/java/com/fengwenyi/javalib/util/NumberToChnUtils.java +++ /dev/null @@ -1,249 +0,0 @@ -package com.fengwenyi.javalib.util; - -/** - * @author Erwin Feng[xfsy_2015@163.com] - * @since 2019/12/12 12:34 - */ -public class NumberToChnUtils { - static String CHN_NUMBER[] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}; - static String CHN_UNIT[] = {"", "十", "百", "千"}; //权位 - static String CHN_UNIT_SECTION[] = {"", "万", "亿", "万亿"}; //节权位 - - /** - * 测试数据的数据类型 - */ - public static class Test_Data{ - int number; - String chnNum; - public Test_Data(int number,String chnNum){ - this.chnNum=chnNum; - this.number=number; - } - } - - /** - * 测试数据 - */ - static Test_Data testData[]={ - new Test_Data(0,"零"), - new Test_Data(1,"一"), - new Test_Data(2,"二"), - new Test_Data(3, "三"), - new Test_Data(4, "四"), - new Test_Data(5, "五"), - new Test_Data(6, "六"), - new Test_Data(7, "七"), - new Test_Data(8, "八"), - new Test_Data(9, "九"), - new Test_Data(10, "一十"), - new Test_Data(11, "一十一"), - new Test_Data(110, "一百一十"), - new Test_Data(111, "一百一十一"), - new Test_Data(100, "一百"), - new Test_Data(102, "一百零二"), - new Test_Data(1020, "一千零二十"), - new Test_Data(1001, "一千零一"), - new Test_Data(1015, "一千零一十五"), - new Test_Data(1000, "一千"), - new Test_Data(10000, "一万"), - new Test_Data(20010, "二万零一十"), - new Test_Data(20001, "二万零一"), - new Test_Data(100000, "一十万"), - new Test_Data(1000000, "一百万"), - new Test_Data(10000000, "一千万"), - new Test_Data(100000000, "一亿"), - new Test_Data(1000000000, "一十亿"), - new Test_Data(1000001000, "一十亿一千"), - new Test_Data(1000000100, "一十亿零一百"), - new Test_Data(200010, "二十万零一十"), - new Test_Data(2000105, "二百万零一百零五"), - new Test_Data(20001007, "二千万一千零七"), - new Test_Data(2000100190, "二十亿零一十万零一百九十"), - new Test_Data(1040010000, "一十亿四千零一万"), - new Test_Data(200012301, "二亿零一万二千三百零一"), - new Test_Data(2005010010, "二十亿零五百零一万零一十") -// new Test_Data(4009060200, "四十亿零九百零六万零二百"), -// new Test_Data(4294967295, "四十二亿九千四百九十六万七千二百九十五") - - - }; - - /** - * 阿拉伯数字转换为中文数字的核心算法实现。 - * @param num 为需要转换为中文数字的阿拉伯数字,是无符号的整形数 - * @return [忽略] - */ - public static String NumberToChn(int num) { - StringBuffer returnStr = new StringBuffer(); - Boolean needZero = false; - int pos=0; //节权位的位置 - if(num==0){ - //如果num为0,进行特殊处理。 - returnStr.insert(0,CHN_NUMBER[0]); - } - while (num > 0) { - int section = num % 10000; - if (needZero) { - returnStr.insert(0, CHN_NUMBER[0]); - } - String sectionToChn = SectionNumToChn(section); - //判断是否需要节权位 - sectionToChn += (section != 0) ? CHN_UNIT_SECTION[pos] : CHN_UNIT_SECTION[0]; - returnStr.insert(0, sectionToChn); - needZero = ((section < 1000 && section > 0) ? true : false); //判断section中的千位上是不是为零,若为零应该添加一个零。 - pos++; - num = num / 10000; - } - return returnStr.toString(); - } - - /** - * 将四位的section转换为中文数字 - * @param section [忽略] - * @return [忽略] - */ - public static String SectionNumToChn(int section) { - StringBuffer returnStr = new StringBuffer(); - int unitPos = 0; //节权位的位置编号,0-3依次为个十百千; - - Boolean zero = true; - while (section > 0) { - - int v = (section % 10); - if (v == 0) { - if ((section == 0) || !zero) { - zero = true; /*需要补0,zero的作用是确保对连续的多个0,只补一个中文零*/ - //chnStr.insert(0, chnNumChar[v]); - returnStr.insert(0, CHN_NUMBER[v]); - } - } else { - zero = false; //至少有一个数字不是0 - StringBuffer tempStr = new StringBuffer(CHN_NUMBER[v]);//数字v所对应的中文数字 - tempStr.append(CHN_UNIT[unitPos]); //数字v所对应的中文权位 - returnStr.insert(0, tempStr); - } - unitPos++; //移位 - section = section / 10; - } - return returnStr.toString(); - } - - /** - * 完成将阿拉伯数字转换为中文数字的测试 - */ - public static void TestNumToChn(){ - for(int i=0;i=0,代表该位置(pos),所对应的是数字不是权位。若小于0,则表示为权位 - if(num>=0){ - number=num; - pos++; - //pos是最好一位,直接将number加入到section中。 - if(pos>=str.length()){ - section+=number; - returnNumber+=section; - break; - } - }else{ - int chnNameValueIndex=ChnUnitToValue(str.substring(pos,pos+1)); - //chnNameValue[chnNameValueIndex].secUnit==true,表示该位置所对应的权位是节权位, - if(chnNameValue[chnNameValueIndex].secUnit){ - section=(section+number)*chnNameValue[chnNameValueIndex].value; - returnNumber+=section; - section=0; - }else{ - section+=number*chnNameValue[chnNameValueIndex].value; - } - pos++; - number=0; - if(pos>=str.length()){ - returnNumber+=section; - break; - } - } - } - return returnNumber; - } - - /** - * 完成对中文数字字符串转换成阿拉伯数字函数的测试 - */ - public static void TestChnStringToNumber(){ - for(int i=0;i data) throws Unsuppor sb.append(i.getKey()) .append("=") - .append(URLEncoder.encode(i.getValue(), Charset.UTF_8)) + .append(URLEncoder.encode(i.getValue(), CharsetConstant.UTF_8)) .append("&"); } diff --git a/src/main/java/com/fengwenyi/javalib/util/PatternUtils.java b/src/main/java/com/fengwenyi/javalib/util/PatternUtils.java deleted file mode 100644 index 90329fc..0000000 --- a/src/main/java/com/fengwenyi/javalib/util/PatternUtils.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.fengwenyi.javalib.util; - -/** - * 正则工具类 - * @author Wenyi Feng - * @since 2018-11-13 - */ -public class PatternUtils { -} diff --git a/src/main/java/com/fengwenyi/javalib/util/RSAUtils.java b/src/main/java/com/fengwenyi/javalib/util/RSAUtils.java index fa999d9..707f1d4 100644 --- a/src/main/java/com/fengwenyi/javalib/util/RSAUtils.java +++ b/src/main/java/com/fengwenyi/javalib/util/RSAUtils.java @@ -1,6 +1,6 @@ package com.fengwenyi.javalib.util; -import com.fengwenyi.javalib.constant.Charset; +import com.fengwenyi.javalib.constant.CharsetConstant; import com.fengwenyi.javalib.third.Base64; import javax.crypto.BadPaddingException; @@ -77,7 +77,7 @@ public static String privateKeyEncrypt(String key, String plainText) throws NoSu PrivateKey privateKey = commonGetPrivatekeyByText(key); Cipher cipher = Cipher.getInstance(RSA); cipher.init(Cipher.ENCRYPT_MODE, privateKey); - byte [] result = cipher.doFinal(plainText.getBytes(Charset.UTF_8)); + byte [] result = cipher.doFinal(plainText.getBytes(CharsetConstant.UTF_8)); return Base64.byteArrayToBase64(result); } @@ -125,7 +125,7 @@ public static String publicKeyEncrypt(String key, String plainText) throws NoSuc Cipher cipher = Cipher.getInstance(RSA); cipher.init(Cipher.ENCRYPT_MODE, publicKey); - byte [] result = cipher.doFinal(plainText.getBytes(Charset.UTF_8)); + byte [] result = cipher.doFinal(plainText.getBytes(CharsetConstant.UTF_8)); return Base64.byteArrayToBase64(result); } diff --git a/src/main/java/com/fengwenyi/javalib/util/RequestUtils.java b/src/main/java/com/fengwenyi/javalib/util/RequestUtils.java index bebf2d5..d676049 100644 --- a/src/main/java/com/fengwenyi/javalib/util/RequestUtils.java +++ b/src/main/java/com/fengwenyi/javalib/util/RequestUtils.java @@ -73,6 +73,11 @@ public static String getRequestIp(HttpServletRequest request) throws UnknownHost /** * 如果客户端通过 request 传递数据,那么就可以使用该方法获取数据 * 这种通常是通过 Post方式 + * + *

    + * 警告:使用该方法获取post的值,{@code HttpServletRequest} 就不可再用,该方法待优化。(2020.5.28) + *

    + * * @param request HttpServletRequest * @return 客户端上传的数据 * @throws IOException 因为是通过IO流读取数据, diff --git a/src/main/java/com/fengwenyi/javalib/util/SHAUtils.java b/src/main/java/com/fengwenyi/javalib/util/SHAUtils.java index f4c42d0..86375c8 100644 --- a/src/main/java/com/fengwenyi/javalib/util/SHAUtils.java +++ b/src/main/java/com/fengwenyi/javalib/util/SHAUtils.java @@ -1,6 +1,6 @@ package com.fengwenyi.javalib.util; -import com.fengwenyi.javalib.constant.EncryptionType; +import com.fengwenyi.javalib.constant.EncryptionTypeConstant; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -25,7 +25,7 @@ public static String SHA1(String plainText) throws NoSuchAlgorithmException { if (StringUtils.isNotEmpty(plainText)) { // SHA 加密开始 // 创建加密对象 并传入加密类型 - MessageDigest messageDigest = MessageDigest.getInstance(EncryptionType.SHA1); + MessageDigest messageDigest = MessageDigest.getInstance(EncryptionTypeConstant.SHA1); // 传入要加密的字符串 messageDigest.update(plainText.getBytes()); // 得到 byte 类型结果 diff --git a/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java b/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java deleted file mode 100644 index 2d43ac3..0000000 --- a/src/test/java/com/fengwenyi/javalib/HttpUtilsTests.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.fengwenyi.javalib; - -import com.fengwenyi.javalib.util.HttpUtils; -import org.junit.Test; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -/** - * 测试HTTP请求工具类:HttpUtils - *

    测试项:

    - *
      - *
    • get请求
    • - *
    • post请求
    • - *
    • put请求
    • - *
    • patch请求
    • - *
    • delete请求
    • - *
    • json请求
    • - *
    • 自定义header请求
    • - *
    - * @author Erwin Feng - * @since 2020/5/10 11:27 下午 - */ -public class HttpUtilsTests { - - @Test - public void testGet() throws IOException { - String url = "https://www.baidu.com"; - String response = HttpUtils.get(url); - System.out.println(response); - } - - @Test - public void testGetParamMap() throws IOException { - String url = "https://www.baidu.com"; - Map map = new HashMap<>(); - String response = HttpUtils.get(url, map); - System.out.println(response); - } - - @Test - public void testGetParam() throws IOException { - String url = "https://www.baidu.com"; - String param = ""; - String response = HttpUtils.get(url, param); - System.out.println(response); - } - -} diff --git a/src/test/java/com/fengwenyi/javalib/IpUtilsTests.java b/src/test/java/com/fengwenyi/javalib/IpUtilsTests.java deleted file mode 100644 index 3e9d923..0000000 --- a/src/test/java/com/fengwenyi/javalib/IpUtilsTests.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fengwenyi.javalib; - -import com.fengwenyi.javalib.util.IpUtils; -import com.fengwenyi.javalib.util.PrintUtils; -import org.junit.Test; -//import org.lionsoul.ip2region.DbMakerConfigException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.lang.reflect.InvocationTargetException; - -/** - * @author Erwin Feng - * @since 2019-07-05 09:51 - */ -public class IpUtilsTests { - - @Test - public void testGetCityByIp() { - try { -// net/iutil/javalib/util/ip2region.db -// java.net.URL url = IpUtils.class.getResource("ip2region.db"); - java.net.URL url = IpUtils.class.getResource("/net/iutil/javalib/util/FileUtils.java"); - PrintUtils.info(url); - - String fileName = this.getClass().getClassLoader().getResource("ip2region.db").getPath();//获取文件路径 - - PrintUtils.info(fileName); - -// String city = IpUtils.getCityInfo(0, "218.88.94.192"); -// PrintUtils.info(city); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/version/2.0.4.md b/version/2.0.4.md index f59a08f..45f5321 100644 --- a/version/2.0.4.md +++ b/version/2.0.4.md @@ -1,9 +1,17 @@ # 2.0.4 +> 注:本次更新主要是做精简,本版本不与之前的版本兼容。 + ## 新增 + ## 优化 -- HTTP请求工具类(HttpUtils)【2020.5.21(优化中)】 +- 常量类都以 `Constant` 结尾。【2020.5.28】 + + +## 删除 -## 删除 \ No newline at end of file +- 删除HTTP请求工具类(HttpUtils)【2020.5.28】 +- 删除异常工具类(ExceptionUtils)【2020.5.28】 +- 删除获取IP信息工具类(IpUtils)【2020.5.28】 \ No newline at end of file From 51bfad9ca69039dc0b8d7b78e4e36673c64ec6f0 Mon Sep 17 00:00:00 2001 From: Erwin Date: Sun, 31 May 2020 21:22:05 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=8F=91=E5=B8=832.0.4=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 126edfc..2fbd529 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.fengwenyi JavaLib - 2.0.4.BUILD + 2.0.4.RELEASE jar JavaLib JAVA开发常用工具集