Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Http工具类实现): 解决JDK大于等于11后无法引入其他第三方的httpClient的问题 #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/com/xkcoding/http/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public class HttpUtil {
private void selectHttpProxy() {
AbstractHttp defaultProxy = null;
ClassLoader classLoader = HttpUtil.class.getClassLoader();
// 基于 java 11 HttpClient
if (ClassUtil.isPresent("java.net.http.HttpClient", classLoader)) {
defaultProxy = getHttpProxy(com.xkcoding.http.support.java11.HttpClientImpl.class);
}
// 基于 okhttp3
if (null == defaultProxy && ClassUtil.isPresent("okhttp3.OkHttpClient", classLoader)) {
defaultProxy = getHttpProxy(com.xkcoding.http.support.okhttp3.OkHttp3Impl.class);
Expand All @@ -59,6 +55,10 @@ private void selectHttpProxy() {
if (null == defaultProxy && ClassUtil.isPresent("cn.hutool.http.HttpRequest", classLoader)) {
defaultProxy = getHttpProxy(com.xkcoding.http.support.hutool.HutoolImpl.class);
}
// 基于 java 11 HttpClient
if (null == defaultProxy && ClassUtil.isPresent("java.net.http.HttpClient", classLoader)) {
defaultProxy = getHttpProxy(com.xkcoding.http.support.java11.HttpClientImpl.class);
}

if (defaultProxy == null) {
throw new SimpleHttpException("Has no HttpImpl defined in environment!");
Expand Down