From 08cb30cc2e950f5241850378330faa4a4f30e54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Wed, 3 Nov 2021 15:58:13 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-57521=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=97=B6websocket=E6=96=AD=E5=BC=80=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E7=9A=84=E6=8F=90=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/socketio/DesignerSocketIO.java | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java b/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java index a6edb04083..197265cccc 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java @@ -3,11 +3,14 @@ package com.fr.design.mainframe.socketio; import com.fr.config.RemoteConfigEvent; import com.fr.decision.webservice.utils.DecisionServiceConstants; import com.fr.design.DesignerEnvManager; +import com.fr.design.EnvChangeEntrance; +import com.fr.design.dialog.FineJOptionPane; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceInfoContext; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.loghandler.DesignerLogger; import com.fr.design.mainframe.share.ui.base.MouseClickListener; import com.fr.design.mainframe.toast.DesignerToastMsgUtil; @@ -21,10 +24,16 @@ import com.fr.log.FineLoggerFactory; import com.fr.report.RemoteDesignConstants; import com.fr.serialization.SerializerHelper; import com.fr.stable.ArrayUtils; +import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.third.apache.log4j.spi.LoggingEvent; +import com.fr.third.org.apache.http.client.config.RequestConfig; +import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse; +import com.fr.third.org.apache.http.client.methods.HttpGet; import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; import com.fr.third.org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; +import com.fr.third.org.apache.http.impl.client.HttpClients; import com.fr.third.org.apache.http.ssl.SSLContexts; import com.fr.web.WebSocketConfig; import com.fr.web.socketio.WebSocketProtocol; @@ -39,7 +48,9 @@ import io.socket.emitter.Emitter; import javax.net.ssl.SSLContext; import javax.swing.BorderFactory; +import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.UIManager; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; @@ -195,11 +206,12 @@ public class DesignerSocketIO { private static final Emitter.Listener failRetry = new Emitter.Listener() { @Override public void call(Object... args) { - showConnectionLostDialog(); + showSocketDisconnectToast(); printLog(args, PrintEventLogImpl.WARN, "failed args: {}"); status = Status.Disconnecting; socket.close(); count++; + System.out.println("失败重连第" + count + "次"); createSocket(); } }; @@ -245,7 +257,7 @@ public class DesignerSocketIO { */ printLog(objects, PrintEventLogImpl.ERROR, "disConnected args: {}"); if (status != Status.Disconnecting) { - showConnectionLostDialog(); + dealWithSocketDisconnect(); } status = Status.Disconnected; } finally { @@ -257,7 +269,15 @@ public class DesignerSocketIO { } }; - private static void showConnectionLostDialog() { + private static void dealWithSocketDisconnect() { + if (checkRPCConnect()) { + showSocketDisconnectToast(); + } else { + showRPCDisconnectDialog(); + } + } + + private static void showSocketDisconnectToast() { try { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override @@ -293,6 +313,36 @@ public class DesignerSocketIO { return jPanel; } + private static void showRPCDisconnectDialog() { + FineJOptionPane.showMessageDialog( + DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Remote_Disconnected"), + UIManager.getString("OptionPane.messageDialogTitle"), + JOptionPane.ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon")); + EnvChangeEntrance.getInstance().chooseEnv(); + } + + private static boolean checkRPCConnect() { + CloseableHttpClient httpclient = HttpClients.createDefault(); + WorkspaceConnectionInfo info = getConnectionInfo(); + HttpGet httpGet = new HttpGet(StableUtils.pathJoin(info.getUrl(), WorkspaceConstants.CONTROLLER_PREFIX, WorkspaceConstants.VT)); + RequestConfig requestConfig = RequestConfig + .custom() + .setConnectTimeout(5000) + .setConnectionRequestTimeout(5000) + .setSocketTimeout(5000) + .build(); + httpGet.setConfig(requestConfig); + try { + CloseableHttpResponse response = httpclient.execute(httpGet); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + return false; + } + return true; + } + //配置变更监听器 private static final Emitter.Listener modifyConfig = new Emitter.Listener() { @Override