From ca480243aefa82c8d08c74711cf7b20cc40122d6 Mon Sep 17 00:00:00 2001 From: octopusYan <935540320@qq.com> Date: Mon, 11 Apr 2022 17:24:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E9=9A=A7=E9=81=93=E7=9A=84=E9=87=8D=E7=BD=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/top/octopusyan/YanFrpApplication.java | 12 +++++++++--- .../http => config}/OkHttpClientConfig.java | 18 +++++++++++------- .../octopusyan/controller/MainController.java | 13 +++++++------ 3 files changed, 27 insertions(+), 16 deletions(-) rename src/main/java/top/octopusyan/{manager/http => config}/OkHttpClientConfig.java (91%) diff --git a/src/main/java/top/octopusyan/YanFrpApplication.java b/src/main/java/top/octopusyan/YanFrpApplication.java index cb438c5..51b7ea7 100644 --- a/src/main/java/top/octopusyan/YanFrpApplication.java +++ b/src/main/java/top/octopusyan/YanFrpApplication.java @@ -8,14 +8,15 @@ import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.stage.StageStyle; +import okhttp3.logging.HttpLoggingInterceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import top.octopusyan.config.OkHttpClientConfig; import top.octopusyan.controller.LoginController; import top.octopusyan.http.HttpConfig; import top.octopusyan.http.config.LogStrategy; import top.octopusyan.http.request.RequestHandler; import top.octopusyan.manager.FrpManager; -import top.octopusyan.manager.http.OkHttpClientConfig; import top.octopusyan.model.ApplicatonStore; import top.octopusyan.utils.AlertUtil; import top.octopusyan.utils.EncryptionUtil; @@ -46,12 +47,17 @@ public class YanFrpApplication extends Application { // 初始化frp客户端临时文件 FrpManager.initFrpc(); + // 网络请求日志 + OkHttpClientConfig.showLog = false; + // 网络请求设置 - HttpConfig.with(OkHttpClientConfig.httpClient()) + HttpConfig.with(OkHttpClientConfig.httpClient( + HttpLoggingInterceptor.Level.HEADERS + )) // 请求服务地址 .serverPath("https://frp.octopusyan.top") // 是否打印日志 - .setLogEnabled(false) + .setLogEnabled(true) // 设置日志打印策略 .setLogStrategy(new LogStrategy()) // 设置请求处理策略 diff --git a/src/main/java/top/octopusyan/manager/http/OkHttpClientConfig.java b/src/main/java/top/octopusyan/config/OkHttpClientConfig.java similarity index 91% rename from src/main/java/top/octopusyan/manager/http/OkHttpClientConfig.java rename to src/main/java/top/octopusyan/config/OkHttpClientConfig.java index e98f864..4f0a646 100644 --- a/src/main/java/top/octopusyan/manager/http/OkHttpClientConfig.java +++ b/src/main/java/top/octopusyan/config/OkHttpClientConfig.java @@ -1,4 +1,4 @@ -package top.octopusyan.manager.http; +package top.octopusyan.config; import kotlin.text.Charsets; import okhttp3.*; @@ -26,19 +26,23 @@ import java.util.concurrent.TimeUnit; * @create : 2022-4-2 15:27 */ public class OkHttpClientConfig { + public static boolean showLog = false; public static final String TAG = "OkHttpLogger"; private static final Logger log = LoggerFactory.getLogger(TAG); - public static final HashMap> cookieStore = new HashMap<>(); - public static OkHttpClient httpClient() { + /** + * 初始化okhttp client + * @param logLevel 日志等级 + */ + public static OkHttpClient httpClient(HttpLoggingInterceptor.Level logLevel) { HttpLoggingInterceptor logginInterceptor = new HttpLoggingInterceptor( new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { try { - log.info(message); + if(showLog) log.info(message); } catch (Exception e) { e.printStackTrace(); log.error(message); @@ -48,11 +52,11 @@ public class OkHttpClientConfig { ); // setlevel用来设置日志打印的级别,共包括了四个级别:NONE,BASIC,HEADER,BODY -// BASEIC:请求/响应行 -// HEADER:请求/响应行 + 头 +// BASIC:请求/响应行 +// HEADERS:请求/响应行 + 头 // BODY:请求/响应行 + 头 + 体 //包含header、body数据 - logginInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); + logginInterceptor.setLevel(logLevel); Dispatcher dispatcher = new Dispatcher(); dispatcher.setMaxRequests(16); diff --git a/src/main/java/top/octopusyan/controller/MainController.java b/src/main/java/top/octopusyan/controller/MainController.java index c641f1b..728b84f 100644 --- a/src/main/java/top/octopusyan/controller/MainController.java +++ b/src/main/java/top/octopusyan/controller/MainController.java @@ -326,10 +326,11 @@ public class MainController extends BaseController implements Initial // 重置 resetProxyBtn.setOnMouseClicked(event -> { ProxySetup proxySetup = userProxy.get(proxySetupModel.getId()); - proxySetup = userProxy.get(proxySetup.getId()); - proxySetup.setRuning(proxySetupModel.isRunning()); - proxySetupModel.set(proxySetup); - domainTextField.resetValidation(); + if(proxySetup != null){ + proxySetup.setRuning(proxySetupModel.isRunning()); + proxySetupModel.set(proxySetup); + domainTextField.resetValidation(); + } }); // 日志清理 @@ -565,12 +566,12 @@ public class MainController extends BaseController implements Initial private void start(ProxySetup setup) { // 添加成功,设置运行状态 - setup.setRuning(frpUtilMap.containsKey(setup.getId())); + setup.setRuning(frpUtilMap.containsKey(setup.getId().toString())); proxySetupModel.set(setup); // 初始化frputil FrpManager frpManager; - if ((frpManager = frpUtilMap.get(setup.getId())) == null) + if ((frpManager = frpUtilMap.get(setup.getId().toString())) == null) frpUtilMap.put(proxySetupModel.getId(), frpManager = FrpManager.init(proxySetupModel)); // 设置文本域对象