wujimin closed pull request #651: [SCB-498] Configuration Center ip address 
need to config default port
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/651
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java
 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java
index 3fbee2767..b7bac4d74 100644
--- 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java
+++ 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java
@@ -145,12 +145,25 @@ public static IpPort parseIpPortFromURI(String 
uriAddress) {
     try {
       URI uri = new URI(uriAddress);
       String authority = uri.getAuthority();
-      return parseIpPort(authority);
+      return parseIpPort(uri.getScheme(), authority);
     } catch (URISyntaxException e) {
       return null;
     }
   }
 
+  private static IpPort parseIpPort(String scheme, String authority) {
+    if (authority == null)
+      return null;
+    int idx = authority.indexOf(':');
+    if (idx != -1)
+      return parseIpPort(authority);
+    if (scheme.equals("http"))
+      return new IpPort(authority, 80);
+    if (scheme.equals("https"))
+      return new IpPort(authority, 443);
+    return null;
+  }
+
   /**
    * 对于配置为0.0.0.0的地址,let it go
    * schema, e.g. http
diff --git 
a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
 
b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
index ce6cc081e..85eebe27a 100644
--- 
a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
+++ 
b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
@@ -46,9 +46,13 @@ public void testNetutils() {
     Assert.assertEquals(8080, 
NetUtils.parseIpPort("127.0.0.1:8080").getPort());
     Assert.assertEquals(null, NetUtils.parseIpPort(null));
     Assert.assertEquals(null, NetUtils.parseIpPort("127.0.0.18080"));
-    Assert.assertEquals(NetUtils.parseIpPortFromURI(null), null);
-    Assert.assertEquals(NetUtils.parseIpPortFromURI("ss"), null);
-    
Assert.assertEquals(NetUtils.parseIpPortFromURI("rest://127.0.0.1:8080").getHostOrIp(),
 "127.0.0.1");
+    Assert.assertEquals(null, NetUtils.parseIpPortFromURI(null));
+    Assert.assertEquals(null, NetUtils.parseIpPortFromURI("ss"));
+    Assert.assertEquals("127.0.0.1", 
NetUtils.parseIpPortFromURI("rest://127.0.0.1:8080").getHostOrIp());
+    Assert.assertEquals(8080, 
NetUtils.parseIpPortFromURI("http://127.0.0.1:8080";).getPort());
+    Assert.assertEquals(80, 
NetUtils.parseIpPortFromURI("http://127.0.0.1";).getPort());
+    Assert.assertEquals(8080, 
NetUtils.parseIpPortFromURI("https://127.0.0.1:8080";).getPort());
+    Assert.assertEquals(443, 
NetUtils.parseIpPortFromURI("https://127.0.0.1";).getPort());
   }
 
   @Test


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to