From 35c5bad3e424133fa7eef32c3105b008d5a43bb3 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 6 Aug 2018 10:40:50 +0800 Subject: [PATCH] Fixes #38: Enhance error handling when parsing bad dashboard addresses Signed-off-by: Eric Zhao --- .../heartbeat/SimpleHttpHeartbeatSender.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java index 1fce5612..2ac4ffe1 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java @@ -101,21 +101,29 @@ public class SimpleHttpHeartbeatSender implements HeartbeatSender { private List getDefaultConsoleIps() { List newAddrs = new ArrayList(); - String ipsStr = TransportConfig.getConsoleServer(); - if (StringUtil.isEmpty(ipsStr)) { - return newAddrs; - } - - for (String ipPortStr : ipsStr.split(",")) { - if (ipPortStr.trim().length() == 0) { - continue; + try { + String ipsStr = TransportConfig.getConsoleServer(); + if (StringUtil.isEmpty(ipsStr)) { + return newAddrs; } - String[] ipPort = ipPortStr.trim().split(":"); - int port = 80; - if (ipPort.length > 1) { - port = Integer.parseInt(ipPort[1].trim()); + + for (String ipPortStr : ipsStr.split(",")) { + if (ipPortStr.trim().length() == 0) { + continue; + } + if (ipPortStr.startsWith("http://")) { + ipPortStr = ipPortStr.trim().substring(7); + } + String[] ipPort = ipPortStr.trim().split(":"); + int port = 80; + if (ipPort.length > 1) { + port = Integer.parseInt(ipPort[1].trim()); + } + newAddrs.add(new InetSocketAddress(ipPort[0].trim(), port)); } - newAddrs.add(new InetSocketAddress(ipPort[0].trim(), port)); + } catch (Exception ex) { + RecordLog.info("[SimpleHeartbeatSender] Parse console list failed, current address list: " + newAddrs, ex); + ex.printStackTrace(); } return newAddrs; }