diff --git a/designer-base/src/main/java/com/fr/startup/ui/StartupPageUtil.java b/designer-base/src/main/java/com/fr/startup/ui/StartupPageUtil.java index 2a71d0d5e5..fd79c9fe36 100644 --- a/designer-base/src/main/java/com/fr/startup/ui/StartupPageUtil.java +++ b/designer-base/src/main/java/com/fr/startup/ui/StartupPageUtil.java @@ -3,6 +3,7 @@ package com.fr.startup.ui; import com.fr.base.svg.SVGIcon; import com.fr.design.env.DesignerWorkspaceType; import com.fr.log.FineLoggerFactory; +import com.fr.stable.StringUtils; import javax.swing.Icon; import java.net.URL; @@ -12,6 +13,9 @@ import java.net.URL; **/ public class StartupPageUtil { + public static final int INVALID_PORT = -1; + public static final String COLON = ":"; + /** * 获取最近区域的 ICON * @@ -49,10 +53,16 @@ public class StartupPageUtil { public static String getRemoteAddress(String urlStr) { try { + if (StringUtils.isEmpty(urlStr)) { + return StringUtils.EMPTY; + } URL url = new URL(urlStr); String host = url.getHost(); int port = url.getPort(); - return host + ":" + port; + if (port == INVALID_PORT) { + return host; + } + return host + COLON + port; } catch (Exception e) { FineLoggerFactory.getLogger().debug(e.getMessage(), e); return urlStr; diff --git a/designer-base/src/test/java/com/fr/startup/ui/StartupPageUtilTest.java b/designer-base/src/test/java/com/fr/startup/ui/StartupPageUtilTest.java new file mode 100644 index 0000000000..fe69541e35 --- /dev/null +++ b/designer-base/src/test/java/com/fr/startup/ui/StartupPageUtilTest.java @@ -0,0 +1,21 @@ +package com.fr.startup.ui; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class StartupPageUtilTest { + + @Test + public void testGetRemoteAddress() throws Exception { + String remoteAddress = StartupPageUtil.getRemoteAddress("https://localhost:9090/webroot"); + Assert.assertEquals("localhost:9090", remoteAddress); + + String remoteAddress1 = StartupPageUtil.getRemoteAddress("https://localhost/webroot"); + Assert.assertEquals("localhost", remoteAddress1); + + String remoteAddress2 = StartupPageUtil.getRemoteAddress(null); + Assert.assertEquals("", remoteAddress2); + } +} \ No newline at end of file