Browse Source

REPORT-76079【迭代】【起始页】交互问题

处理一下 util 里面的鲁棒性
feature/x
Harrison 2 years ago
parent
commit
7f6bda5ee8
  1. 12
      designer-base/src/main/java/com/fr/startup/ui/StartupPageUtil.java
  2. 21
      designer-base/src/test/java/com/fr/startup/ui/StartupPageUtilTest.java

12
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;

21
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);
}
}
Loading…
Cancel
Save