From f9282484474334583f5b3b97e7f4a5412bfc94cc Mon Sep 17 00:00:00 2001 From: ZZ Date: Fri, 17 Dec 2021 11:36:37 +0800 Subject: [PATCH] log4j dep exclusion --- evcs-modules/pom.xml | 6 ++++++ pom.xml | 6 ++++++ .../com/xhpc/common/core/utils/HttpUtils.java | 21 ++++++++++--------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/evcs-modules/pom.xml b/evcs-modules/pom.xml index e4654c73..6b6fa81a 100644 --- a/evcs-modules/pom.xml +++ b/evcs-modules/pom.xml @@ -181,6 +181,12 @@ org.springframework.cloud spring-cloud-starter-bootstrap + + + org.apache.logging.log4j + log4j-to-slf4j + + diff --git a/pom.xml b/pom.xml index 2928e683..5d09fffc 100644 --- a/pom.xml +++ b/pom.xml @@ -261,6 +261,12 @@ org.springframework.cloud spring-cloud-starter-bootstrap + + + org.apache.logging.log4j + log4j-to-slf4j + + diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java index 08fdb1dd..ace04bc9 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java @@ -26,8 +26,8 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.message.BasicNameValuePair; import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.util.EntityUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -36,6 +36,7 @@ import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.util.*; /** @@ -50,18 +51,17 @@ public class HttpUtils { */ private static PoolingHttpClientConnectionManager poolConnManager = null; - private static Logger logger = LogManager.getLogger(HttpUtils.class); - private static CloseableHttpClient httpClient = null; /** * 请求器的配置 */ private static RequestConfig requestConfig; + static final Logger logger = LoggerFactory.getLogger(HttpUtils.class); static { try { - System.out.println("httpClient~~~开始"); + logger.info("httpClient init..."); SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); @@ -84,7 +84,7 @@ public class HttpUtils { connectTimeout).build(); // 初始化httpClient httpClient = getConnection(); - System.out.println("初始化HttpClient~~~结束"); + System.out.println("HttpClient inited."); } catch (Exception e) { e.printStackTrace(); } @@ -448,15 +448,16 @@ public class HttpUtils { } connection.connect(); //OutputStream out = new DataOutputStream(connection.getOutputStream()); - PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); - out.print(formSB.toString()); + PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8)); + out.print(formSB); out.flush(); //获得响应状态 int resultCode = connection.getResponseCode(); if (HttpURLConnection.HTTP_OK == resultCode) { formSB = new StringBuffer(); String readLine; - BufferedReader responseReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); + BufferedReader responseReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), + StandardCharsets.UTF_8)); while ((readLine = responseReader.readLine()) != null) { formSB.append(readLine).append("\n"); } @@ -506,7 +507,7 @@ public class HttpUtils { } // 定义 BufferedReader输入流来读取URL的响应 in = new BufferedReader(new InputStreamReader( - connection.getInputStream(), "utf-8")); + connection.getInputStream(), StandardCharsets.UTF_8)); String line; while ((line = in.readLine()) != null) { result += line;